Btrfs snapshots with snapper

arch / published / guide #12 / ≈ 3 min read

If you installed Arch (or Manjaro) on the modern filesystem Btrfs, you have a superpower available: cheap, instant snapshots of your whole filesystem. Combined with a tool called snapper, you get something close to time travel — boot into any past state of the system if today's update breaks something.

What's a snapshot? A read-only view of the filesystem at a specific moment. It takes almost no disk space to create — Btrfs only stores the differences. You can have hundreds of them.

Step 1: Install the tools

sudo pacman -S snapper snap-pac grub-btrfs
  • snapper — the snapshot tool itself.
  • snap-pac — hooks into pacman so a snapshot is taken before every package install/upgrade.
  • grub-btrfs — adds a submenu to GRUB listing your snapshots so you can boot into them.

Step 2: Configure snapper for the root filesystem

sudo snapper -c root create-config /

This creates a config file at /etc/snapper/configs/root. You can leave it at the defaults — snapper will keep hourly/daily/weekly/monthly snapshots with sensible counts.

Step 3: Turn on the timers

Snapper runs as systemd timers — small scheduled tasks. Two need to be on:

sudo systemctl enable --now snapper-timeline.timer
sudo systemctl enable --now snapper-cleanup.timer

The timeline timer creates the periodic snapshots; the cleanup timer prunes old ones according to the limits in the config.

Step 4: Snapshots around every pacman command

snap-pac works automatically with no config. The next time you run sudo pacman -Syu, two snapshots are taken — one before, one after. List them:

snapper list

You'll see entries like "pre-upgrade" and "post-upgrade" with timestamps.

Step 5: How to boot into a snapshot

Regenerate the GRUB menu so it picks up the snapshots:

sudo grub-mkconfig -o /boot/grub/grub.cfg

Now reboot. Hold Shift when the BIOS finishes to show the GRUB menu. You'll see a new submenu called something like Arch Linux snapshots. Pick a snapshot from before things broke.

Important: a snapshot boot is read-only by default. You're looking at the past, you're not living in it. To make a snapshot your real present, you need to "promote" it.

Step 6: Promoting a snapshot

If you decide you want to live in a past snapshot, find its subvolume id:

sudo btrfs subvolume list /

Then set it as the default subvolume:

sudo btrfs subvolume set-default 256 /

Replace 256 with the id of the snapshot. Reboot and the system is now running from that point in time.

Worth keeping in mind

Snapshots only protect the filesystem. They aren't backups in the disaster sense — if the disk dies, all snapshots die with it. Keep an off-disk backup for anything important.

One more Btrfs habit: monthly scrub

While we are here: snapshots are not the only Btrfs maintenance worth doing. Scrub is Btrfs's built-in integrity check — it walks every block, verifies its checksum, and corrects silent corruption against the second copy if you are using a raid1 data profile. It is not run automatically; you have to opt in.

There is a systemd timer that does it monthly:

sudo systemctl enable --now btrfs-scrub@-.timer

The funny @- part is systemd's way of escaping / — this timer is "scrub the filesystem mounted at /." Since scrub is filesystem-level, it covers every subvolume that lives on that filesystem, including all your snapper snapshots.

Verify it is scheduled:

systemctl list-timers btrfs-scrub@-.timer

If you have additional Btrfs mounts (e.g. a separate /home on its own Btrfs filesystem rather than as a subvolume), enable a scrub timer for each — substitute the mount point with / replaced by - in the unit name (so /home becomes btrfs-scrub@-home.timer).

← back to index