Skip to content

Subvolumes and Layout

This chapter carves one filesystem into subvolumes and lays out a system that can be rolled back in pieces. The outcome: a layout you can draw on paper, and the commands that create, list and mount each part. These are mounted-filesystem operations, and this guide's lab could not mount (transcript t00), so the chapter is taught from the documentation and says so; every command is the standard one a reader runs, unchanged, on their own machine.

Creating and listing

With the filesystem mounted at /mnt/data:

sudo btrfs subvolume create /mnt/data/projects
sudo btrfs subvolume create /mnt/data/backups-stage
sudo btrfs subvolume list /mnt/data

A new subvolume looks like an empty directory. The difference is visible in the list: every subvolume has an ID, a generation, and a parent. Two checks identify one beyond doubt:

stat -f -c %T /mnt/data/projects     # prints btrfs
lsattr -d /mnt/data/projects        # (subvolumes show their own inode, 256)

Deleting is equally plain, and permanent — a deleted subvolume's space returns to the pool once nothing references it:

sudo btrfs subvolume delete /mnt/data/old-draft

The layout that earns its keep

The arrangement most systems settle on keeps things that change for different reasons in different subvolumes:

  • @ — the root system itself: programs, configuration, everything an upgrade rewrites.
  • @home — users' files, which upgrades should never touch.
  • @var-log or @snapshots — logs, and the snapshot storage, kept apart so neither can fill the system by accident (a snapshot kept inside the subvolume it snapshots is also a fine way to confuse yourself).

Each is mounted by name at boot, using the subvol= option in /etc/fstab:

UUID=<the-filesystem-uuid>  /      btrfs  subvol=@,defaults        0 0
UUID=<the-filesystem-uuid>  /home  btrfs  subvol=@home,defaults    0 0

One UUID, several mounts: the subvolumes are one filesystem wearing several doors. Check the result with btrfs subvolume list / and findmnt after a reboot — the layout you can see is the layout you have.

What a subvolume is not

A subvolume is not a partition: it has no size of its own, and one greedy subvolume can fill the whole filesystem for all the others (chapter 10's quotas exist because of exactly this). It is not a directory, either, in one sneaky respect: snapshots do not cross subvolume boundaries, so a snapshot of @ does not include @home if home is a separate subvolume living under the root mount. Lay out with that in mind: what must roll back together belongs in one subvolume; what must not is split on purpose, and written down.