6

The system administrator guide of the Btrfs wiki (here) says:

A Btrfs subvolume can be thought of as a POSIX file namespace.

I remember at first it saying that a subvolume is, as opposed to being able to be thought of as, a "POSIX file namespace". A Google search for "POSIX file namespace" turn up only things about Btrfs, so the phrase is unhelpful.

Just what is a subvolume in Btrfs? If a subvolume is accessible as a directory from the filesystem root, then how is mounting subvolume any different from bind mounting a directory on any other filesystem to another location without intermediately mounting the root of said filesystem? This is what I mean:

# standard bind mount
mkdir /mnt/data
mkdir /mnt/docs
mount /dev/sda2 /mnt/data
mount --bind /mnt/data/docs /mnt/docs
umount /mnt/data
rmdir /mnt/data

# hypothetical method of directly mounting
# a file/directory on a filesystem
# to some path that achieves the same
# as the above
mkdir /mnt/docs
mount -o path_on_fs=/docs /dev/sda2 /mnt/docs

# if /docs on sda2 was a subvolume
mkdir /mnt/docs
mount -o subvol=/mnt /dev/sda2 /mnt/docs

What is the purpose of the subvolume feature? An example: /var/lib/machines.raw is a Btrfs filesystem image that is used by systemd-machined and machinectl to store virtual machines and/or containers. Presumably, Btrfs is used for subvolumes. What do the subvolumes do for that?

If a subvolume is useful for containers, does it have built-in isolation for processes running in different subvolumes?

1
  • Not sure if you can snapshot individual directories in btrfs, but you can snapshot subvolumes.
    – muru
    Feb 2, 2021 at 18:57

1 Answer 1

7

I’m no expert—not even close!—but since I’ve been reading a lot about Btrfs lately, and since your question has gone unanswered for six months, I figured I’d give it a shot.

Here are two possible use cases. I don’t know if these are common or even recommended reasons for having subvolumes (like I said, not an expert), but I’ll include links to where I’ve seen them discussed to help you judge for yourself.

Independent snapshots

A Btrfs snapshot is a copy of an entire subvolume. This could be useful in a snapshot-based recovery or backup strategy. For instance, having / separate from /home means you can roll back a system update without affecting user data; conversely, you can back up user data without keeping system files.

You can also use subvolumes to exclude directories you don’t want to back up. For example, if /home and /home/bob/Downloads are different subvolumes, then a snapshot of /home excludes bob’s downloads.

Discussion:

Different mount options

Because each subvolume is mounted individually, they can be mounted with different mount options from one another.

Or at least, that’s the theory. In practice, it appears only some mount options are currently supported per-subvolume.

I don’t know exactly what scenarios this would enable (again: not an expert), but one that I just made up is setting the compression so that one subvolume is optimised for speed, while another optimises for space. Once per-subvolume compress is supported, of course.

Discussion:

1
  • Another reason is quotas per subvolume.
    – rrauenza
    Jul 26 at 20:06

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.