Skip to content

Snapshots and Rolling Back

This chapter takes a snapshot, breaks things on purpose, and rolls back. The outcome: the confidence that a system change can be undone in minutes — and a clear head about what a snapshot does not protect (chapter 1's rule: the same disk holds both copies). Snapshots are a mounted-filesystem operation the lab could not run (transcript t00); the chapter is documented-only and labelled so, as criteria point 7 requires of every chapter like it. The commands are the standard ones, exactly as a reader runs them.

Taking one

sudo btrfs subvolume snapshot /mnt/data/projects /mnt/data/projects-2026-01-15
sudo btrfs subvolume snapshot -r / /mnt/snapshots/root-before-upgrade

The first is a writable snapshot: a living branch of projects. The second, with -r, is read-only: frozen, which is what safety nets and backups (chapter 7) are made of. Both finish almost instantly whatever the size, because copy-on-write (chapter 1) means the snapshot at birth shares every block with its source. Space is spent only as the two sides diverge.

Prove that to yourself the first time: check the size of both trees with btrfs filesystem du -s, write a large file into the source, and check again — the snapshot did not grow; the difference did.

Rolling back

Suppose the upgrade went badly. The root subvolume @ is sick; the read-only snapshot from before the upgrade is well. The rollback is a swap:

sudo btrfs subvolume snapshot /mnt/snapshots/root-before-upgrade /mnt/@-recovered

then point the boot mount at @-recovered (the subvol= name in /etc/fstab or the bootloader) and reboot. The sick @ stays where it was until you delete it, which is the forgiving part: a rollback you regret can itself be rolled back. Distributions built around btrfs automate this dance — openSUSE's snapper is the famous one — but the dance itself is these two moves and a reboot, and knowing the steps by hand is what saves you when the automation is the thing that broke.

Keeping the right number

Snapshots are cheap to take and quietly expensive to keep: every old snapshot pins the blocks that later edits would have freed, so a busy filesystem with a year of forgotten snapshots can fill with data nobody can see. The habits that keep them honest:

  • Name them with dates and a reason (root-before-upgrade, not snap3).
  • Keep a schedule, not a museum: most keepers hold a handful of recent ones, not fifty.
  • Delete deliberately with btrfs subvolume delete, and watch the pool, not just the snapshots, shrink or fail to — the difference is other snapshots still holding the same blocks.
  • Snapshots of what matters, taken before what risks it: upgrades, migrations, bulk edits. A snapshot taken after the accident is a photograph of a fire.

And the rule, once more, in the place it matters most: every snapshot above lives on the same device as the original. If the disk dies tonight, the rollback dies with it. Chapter 7 is how a snapshot becomes something better.