Skip to content

Btrfs for Mere Mortals

A traditional filesystem writes new data over old, and what is overwritten is gone. Btrfs — the copy-on-write filesystem built into the Linux kernel — writes every change to a fresh place instead, and that one decision buys a remarkable set of talents: snapshots that freeze a whole system in a second, checksums on every block so silent rot is caught rather than served, several disks acting as one pool with mirroring of its own, and send and receive, which ships the difference between two snapshots to another machine as a backup.

This guide explains how those talents work, builds a first filesystem, lays out subvolumes, takes snapshots and rolls an upgrade back, sends a backup somewhere else, chooses RAID profiles with their warnings attached, keeps the whole thing proofread and packed with scrub and balance, and — when it breaks anyway — checks, repairs and salvages it.

The rule that governs everything here is stated in chapter 1 and repeated wherever it matters most: a snapshot is not a backup. A snapshot lives on the same disk as the original, and copies on the same disk die with the disk. Snapshots defend you against your own mistakes; only a copy that has travelled — chapter 7's send and receive — defends you against the disk itself.

The lab behind this guide ran the real thing: btrfs-progs 6.6.3 on a Linux sandbox. The sandbox granted no loop devices and no permission to mount, so the lab's rule was absolute: every write operation ran on image files, never on a real disk, and no real disk was ever at risk. Within that fence the lab did a great deal for real: created single-disk, RAID1 and RAID10 filesystems at mkfs time with two different checksum algorithms and read the choices back from their superblocks; filled a filesystem with files at creation time and restored them all back out, hash-verified, without a mount; flipped bytes inside a copy's data and watched the checksum machinery name the damage to the byte range; zeroed a copy's superblock and recovered every file through its backup superblock; and met the tools' own rough edges — including a reporting command that crashed on a healthy filesystem — and kept them in the transcripts.

What the lab could not do, it did not fake. Mounting, and with it subvolumes, snapshots, send and receive, scrub, balance, quotas, device changes and watching a disk fail, are taught from the project's documentation and labelled documented-only wherever they appear. criteria.md keeps the full ledger of what was run and what was only read.

What this guide covers

  • What Btrfs is — copy-on-write, the talents it buys, and the rule: a snapshot is not a backup
  • The moving parts — subvolumes, snapshots, checksums, chunks and profiles, the trees, and the one tool that drives them all
  • Installing the tools — btrfs-progs on the common distributions, the kernel half of the pair, and where to practise safely
  • Your first filesystem — mkfs.btrfs, meeting it again offline, and a hash-verified round trip of real files with no mount anywhere
  • Subvolumes and layout — carving one filesystem into trees that roll back separately, and the fstab that mounts them
  • Snapshots and rolling back — the safety net: snapshots before upgrades, rollback as a swap, and keeping the right number of them
  • Send and receive — backups that travel — snapshots turned into streams, shipped to another disk or machine, incremental after the first
  • RAID and profiles — mirroring, striping and parity, chosen per chunk; RAID1 and RAID10 built for real, the RAID5/6 write hole stated unsoftened
  • Balancing and scrubbing — the rearrangement and the proofread: the two maintenance jobs and the symptom each one answers
  • Quotas and qgroups — limits and honest accounting per subvolume, and the performance price, stated before you pay it
  • Checking and repair — read-only checks, checksum verification, backup superblocks, the last-resort --repair, and salvage with restore — most of it run for real on copies the lab broke on purpose
  • Recipes — snapshot before upgrades, backups that leave the building, a two-disk mirror, taming VM images, and rehearsing disaster on a file
  • The neighbours — ZFS, ext4 and LVM: what each does that btrfs doesn't, and vice versa, with the choice made on facts
  • Limits — snapshots are not backups, checksums detect rather than repair, parity's write hole, CoW-fighting workloads, quota costs and repair's ceiling, all in one place
  • Troubleshooting — "No space left" with space showing, the growing error counter, the filesystem that turned read-only by itself, the tool crash that wasn't the filesystem's fault, and the traps this guide's lab fell into so you don't have to
  • Glossary — the terms, collected in one place

What it doesn't cover

Btrfs on anything but Linux. Replacing a backup strategy with snapshots — chapter 1 explains why that is not this guide's advice but its central warning. Tuning for maximum performance (this guide aims at correct and safe), filesystems on phones and appliances, and the internals of the B-tree code itself: the trees are named and respected here, not reimplemented.

How to use this guide

Read chapter 1 for the model and the rule, and chapter 2 before creating anything — knowing which part does what turns later error messages into named problems. Chapter 4 builds your first filesystem the lab's way, on an image file, where every mistake is free; do the same before pointing mkfs at a real device. Chapters 5 to 7 are the daily craft; chapter 11 is the one to have read before the night it is needed. The lab's transcripts live in btrfs-lab/transcripts/; its notes are examples/lab-notes.txt.


Part of the series

This guide is one of the For Mere Mortals guides: plain-language guides to the tools programmers and makers use.

Related guides:

License

The writing in this guide is licensed under CC BY 4.0. Code examples and lab scripts are licensed under the MIT License.