Balancing and Scrubbing
Two maintenance jobs keep a multi-disk
btrfs honest, and this chapter runs the
reader through both: balance, which
rearranges where chunks live, and scrub,
which reads everything and checks the
checksums. The outcome: knowing which job
fixes which symptom, and reading their
reports without panic. Both are
mounted-filesystem operations; the lab
could not mount (transcript t00), so the
procedures are documented-only, and the
one piece of live evidence — what a scrub
hunts for — is transcript t04, where a
flipped byte was caught by exactly the
checksum machinery scrub exercises.
Scrub: the proofread
sudo btrfs scrub start /mnt/vault
sudo btrfs scrub status /mnt/vault
A scrub reads every data and metadata
block, verifies each checksum, and — where
a profile keeps a second copy (RAID1, DUP)
— repairs mismatches from the good twin.
It runs in the background, throttled so
the machine stays usable, and its status
report ends with the numbers that matter:
bytes scrubbed, and errors found, split
into corrected and uncorrectable. Zero
uncorrectable errors is a healthy line.
Non-zero means a disk is lying to you, and
chapter 15's first move is to read
btrfs device stats (chapter 11), which
tallies the same events per device.
How often: monthly is the common rhythm for archives, and after any event that smells of hardware — a hang, a power cut, a new clicking noise from the cupboard.
Balance: the rearrangement
Over time a filesystem's chunks end up half-empty and lopsided: space is used but the allocator cannot find a whole free chunk of the profile it needs, and a write fails with "No space left" while reports insist gigabytes are free. (Chapter 14 explains why the reports are both telling the truth.) Balance is the cure: it rewrites chunks, packing them tight and spreading them across devices as the current profiles demand.
sudo btrfs balance start -dusage=50 /mnt/vault
sudo btrfs balance status /mnt/vault
-dusage=50 limits the pass to data chunks
less than half full — the gentle,
overnight-sized version. A full balance
rewrites everything, takes as long as
that sounds, and is resumable if
interrupted (btrfs balance resume).
Balance is also the tool that applies a
profile conversion (chapter 8) and the
tool that empties a device before removal.
Two cautions, both learned by the whole community the hard way: never balance a filesystem that is nearly full and already failing — it needs free working room, and deleting something (or adding a device) comes first; and never run balance and scrub at a problem you have not yet diagnosed. Maintenance is for healthy filesystems. Chapter 11 is for sick ones.