0

Say one has setup a BTRFS partition, and created several LXC containers on it.

How can, in hindsight, be determined what backing store type each container is using (so whether each uses a 'directory' backing store, a 'BTRFS' one, or even an 'AUFS' one, etc.)?

This can be important to in-turn know what thecontainer maintenance options are.

1

When a container is created, there is a configuration file that is also created. The configuration file defines certain settings within the container. For LXC containers this is stored, by default under

/var/lib/lxc/YourContainerName-foo/config (for privileged containers).

and

~/.local/share/lxc/YourContainerName-foo/config (for unprivileged containers).

The default backing store for lxc containers is a directory based file system named dir, this means that a particular file system is not defined. The 'none' option acts as an alias for dir. If dir is the defined backing store, then the container's root file system will be located at usr/local/var/lib/lxc/YourContainerName-foo/rootfs and ext4 will be used as the root filesystem.

The place to check the type of backing store in use for each container would be in the config file mentioned above under /var/lib/lxc/container/config.

Under the section "Container specific configuration", there is a line that defines the rootfs.backend.

eg. lxc.rootfs.backend = lvm

lxc.rootfs.backend = dir

lxc.rootfs.backend = btrfs

etc.

Another method that can be used but not as reliable, is to use the df -Th command in a shell prompt, from inside the lxc container. This will allow you to not only check the status of the disk's space but will also show the file system type. The output can be misleading when trying to determine the file system backing store because dir will use ext4 and LVM will use ext3. i.e. the df output would show as ext3, even though lvm is also used.

Hope this helps

  • I think this is exactly what I needed (and beyond)! Sadly in the specific version of LXC that I'm using (openWRT) this is not the case @Jason-C . I do have the config file itself, but it is lacking an lxc.rootfs.backend entry. df -TH (run from within the container) does show: /dev/sda btrfs 233G 13G 219G 6% / though! Could it be because I started out with a directory backed one that I cloned into a BTRFS backed one (using the -B parameter), or do you reckon this being an OpenWRT specific thing? – woosting Nov 7 '17 at 0:58
0

I'm now curious about your implementation and still unsure about your environment. But I am basing this comment around a few assumptions:

  1. You have access to a Linux shell prompt (CLI).
  2. You have downloaded/installed LXC and btrfs-tools.
  3. You have loaded the btrfs kernel module.

I would have thought that if you were to clone an lxc container, there would still be a root filesystem backend entry, as this is what defines the rootfs type. Saying that, from my experience with cloning full virtualisation environments, there always seems to be conflicting problems.

Also, have you created the actual btrfs filesystem or just defined it in the lxc-create command? It may not be showing because the actual block device may not be defined.

I'm not too sure what the overall issue may be, but it does sound like it is clone related. i.e. new container still pointing to the original containers dir block device for storage, or something like that. let me give some points that may help troubleshoot it.

The way I would create an LXC container with BTRFS backing store would be.

Install BTRFS (Sounds like you've done this):

apt-get -y install btrfs-tools

Load the kernel module (Sounds like you've done this):

modprobe btrfs

Make the btrfs filesystem (Sounds like you've done this):

mkfs -t btrfs /dev/sda

The filesystem on the block device would then be mounted.

mkdir /home/btrfs-mnt (or wherever the desired location is)

mount /dev/sda /home/btrfs-mnt

That would be the the steps that I would take to make a usable filesystem for the LXC containers.

If you are making a bunch of btrfs containers then:

file -s /dev/sda (shows that the type of file is a btrfs filesystem).

btrfs filesystem show (shows btrfs filesystems).

btrfs subvolume show /home/btrfs-mnt (identifies the btrfs root directory).

cat /proc/mounts | grep btrfs (shows mounted btrfs block devices).

btrfs filesystem df /home/btrfs-mnt (shows btrfs disk usage).

After the btrfs block device is created and LXC is installed, I can make a container. The path to the btrfs mount will be defined using the --lxcpath= option and the btrfs rootfs type is defined using the --bdev option. Because the path to the default lxc location is now different, a symbolic link is required to re-direct to the actual location.

Create the btrfs backed LXC container:

lxc-create --bdev btrfs --lxcpath=/home/btrfs-mnt --name mybtrfscontainerfoo --template ubuntu

create the symbolic link to the actual config file.

cd /var/lib/lxc/mybtrfscontainerfoo/

ln -s /home/btrfs-mnt/mybtrfscontainerfoo/config /var/lib/lxc/mybtrfscontainerfoo/config

It sounds to me like your trying to setup btrfs containers or copy them so hopefully this helps. OpenWRT, I'm not sure what your doing there. I've only used it to get non-standard firmware on a home router.

Hopefully this helps, if not then maybe describing your environment a little more, may help me get a clearer picture.

let me know how you get on.

Best endeavours,

Jason-C

  • Thanks again for your great (insight packed) replies! Your 1st reply answered my question perfectly (in the context it got asked: generic/Ubuntu)! I didn't mention my specs to prevent deferring from Ubuntu too much. I hoped generic knowledge would be applicable. It seems system-specific though: Turris Omnia+ForrisOS (OpenWRT-fork) with LXC tooling preinstalled. I have root access and added an mSATA disk; formatted/mounted BTRFS for containers (functional). I think my containers are BTRFS (snapshotable) backed, just not specified as such in the config files. – woosting Nov 25 '17 at 16:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.