The Moving Parts
This chapter names the pieces, so that every later chapter's commands have somewhere to land. By the end you will be able to say what a subvolume, a snapshot, a chunk and a checksum each do, and which of them you are looking at when a report mentions one.
Subvolumes
A subvolume is a separate file tree
inside one filesystem. It looks like a
directory, mounts like a filesystem, and
can be snapshotted on its own, but it draws
its space from the same shared pool as
every other subvolume — no fixed partition
sizes to guess in advance. A typical system
keeps the operating system in one subvolume
and home directories in another, so the
system can be rolled back (chapter 6)
without touching anyone's files. The first
subvolume every filesystem has, created by
mkfs.btrfs itself, is called the
top-level subvolume, ID 5, and it is
the parent of the rest.
Snapshots
A snapshot is a subvolume that began life as a copy-on-write twin of another: it shares every block with its source at the moment it is taken, and the two diverge only as either side changes files. A snapshot can be read-only (frozen, the usual choice for backups) or writable (a branch you can boot or work in). Chapter 6 is devoted to them, and chapter 1's rule applies to everything said there: a snapshot shares its disk with the original.
Checksums
Every data block and every metadata block
carries a checksum: crc32c by default,
with xxhash, sha256 and blake2 available,
chosen once when the filesystem is created.
(The lab created both kinds and read the
choice back from the superblock —
transcript t02.) Checksums are stored in
their own tree, so a block can be verified
the moment it is read. A mismatch means the
bytes on disk are not the bytes that were
written: rot, a failing disk, a bad cable.
What happens next depends on whether a
second, good copy of the block exists —
which is what profiles are about.
Chunks and profiles
Btrfs does not write files straight onto the disk. It first carves the device into chunks: large regions (typically 256 MiB to 1 GiB) each dedicated to one kind of content — data, metadata (the trees that describe everything), or system data (the map of the chunks themselves). Each chunk is governed by a profile, the rule for how its blocks are placed:
- single — one copy, on one device.
- DUP — two copies, both on the same device. This is the default for metadata on a lone disk: it survives a bad patch of disk, not a dead one.
- RAID0 — striped across devices: fast, more room, and the loss of any device loses the chunk.
- RAID1 — mirrored onto two devices: the setting that lets checksums repair rather than merely report.
- RAID10 — striped mirrors, four devices or more.
- RAID5 / RAID6 — parity across three or more devices; chapter 8 carries btrfs's own long-standing warning about these two.
Data and metadata have separate profiles,
so a filesystem can mirror its metadata
(small, precious) while striping its data
(large, replaceable). The lab's very first
mkfs.btrfs (transcript t01) shows the
single-disk defaults: data single,
metadata and system DUP.
The trees
Everything Btrfs knows, it stores in B-trees — the data structure the filesystem is named after. There is a tree for each subvolume's files, a tree of checksums, a tree of extents (which blocks are used where), and a tree of tree roots keeping the addresses of all the others. The superblock, near the start of each device (with backup copies further in — chapter 11 leans on them), points at the trees and carries the filesystem's label and UUID, its identity card.
The tool
Nearly everything in this guide is done
with one program, btrfs, whose
subcommands mirror the parts: btrfs
subvolume …, btrfs filesystem …, btrfs
device …, btrfs balance …, btrfs scrub
…, btrfs send and btrfs receive. The
only companions are mkfs.btrfs, which
creates filesystems, and btrfstune, which
edits a filesystem's identity while it is
unmounted. Chapter 3 installs them.