You take a dnf-automatic security update overnight. The next morning a service won’t start because the new glibc broke a vendored binary in /opt. On ext4 the answer is “restore from last night’s backup” — thirty minutes minimum, plus the backlog of work that piled up while the box was down. On a properly snapper’d Btrfs root, the answer is “boot the pre-update snapshot from the GRUB menu, take the service back to where it was at 02:00, and triage in daylight.” That’s the entire pitch for snapper in production: the time between “this update broke us” and “we’re serving again” should be measured in reboots, not restores.
What’s happening
Btrfs snapshots are constant-time, copy-on-write subvolumes. Taking a snapshot is essentially free in I/O terms and uses almost no extra space until the original blocks are rewritten. Snapper is a userspace tool that gives them a retention policy, timeline-based pruning, and — critically — pre/post hooks that wrap RPM transactions so every dnf update produces a pair of snapshots: “before the update” and “after the update.” The companion package grub-btrfs walks those snapshots and writes a GRUB submenu that boots each one read-write as the live root.
The pieces fit together as follows:
- Layout. The default RHEL/SUSE Btrfs layout has the root filesystem on subvolume
@and/homeon@home. Snapper takes snapshots of@only — you don’t usually want a userland snapshot to roll back home directory changes. - Timeline. Hourly snapshots with declining density: keep N hourly, M daily, K weekly, P monthly. Defaults are sensible; tune them once and forget.
- Pre/post hooks. A dnf plugin (
dnf-plugin-snapper) or the libzypp snapper plugin on SUSE takes apresnapshot before the transaction begins and apostsnapshot after. The two share a transaction number and snapper marks them as a pair. - GRUB integration.
grub-btrfsregenerates/boot/grub2/grub.cfgwhenever snapshots change, adding a “Snapshots” submenu with bootable entries for the recent snapshots. - The rollback itself. From a booted snapshot,
snapper rollback <number>makes that snapshot the new default subvolume. Next reboot, the system is permanently on that state.
What you do not want is to roll back across a /home boundary you didn’t intend — a snapper rollback only affects subvolumes snapper is configured to manage. Keep /home, /var/lib/postgresql, /var/lib/mysql, and any dataset that holds live application state on separate Btrfs subvolumes that snapper is not snapshotting. Their durability is the backup system’s job, not snapper’s. A snapper rollback that includes a database directory is a database restore, not an OS rollback.
How to verify
After installation, four checks confirm the system is wired correctly.
Snapper is configured for root:
snapper -c root list
# Type | # | Pre # | Date | User | Cleanup | Description | Userdata
# --------+---+-------+---------------------------------+------+---------+-----------------------+----------
# single | 0 | | | root | | current |
# single | 1 | | Wed May 14 10:00:00 2026 | root | timeline| timeline |
# pre | 2 | | Wed May 14 10:23:11 2026 | root | number | dnf | important=yes
# post | 3 | 2 | Wed May 14 10:23:54 2026 | root | number | | important=yes
Pre/post pairs (rows 2 and 3 above) confirm the dnf hook is firing. Timeline rows confirm the snapper timer is firing.
grub-btrfs is regenerating the menu:
systemctl status grub-btrfsd
# active (running)
ls -la /boot/grub2/grub.cfg.snapshot* 2>/dev/null || true
grep -c "submenu 'Btrfs Snapshots'" /boot/grub2/grub.cfg
# 1
Subvolume layout shows the production boundaries:
btrfs subvolume list /
# ID 256 ... path @
# ID 257 ... path @home
# ID 258 ... path @var-lib-mysql
# ID 259 ... path @var-log
# ID 1234 ... path @/.snapshots/42/snapshot
If @var-lib-mysql does not appear as its own subvolume, your DB directory is part of the @ root subvolume and will be rolled back with it — that is rarely what you want.
Test a rollback in a non-production window:
snapper -c root create -d "rollback drill" # numbered, say #99
echo "hello-world" > /etc/rollback-marker
snapper -c root rollback 99
# Reboot now.
# After reboot:
cat /etc/rollback-marker # file should not exist; we're back at snapshot 99
If the marker file survives, snapper isn’t actually rolling back the root subvolume — usually because the default subvolume is something other than what snapper expects.
The fix
The procedure below is for AlmaLinux 9 with a Btrfs root. (On openSUSE Leap, this is the out-of-box default and most of these commands are unnecessary — but the verification still applies.)
Confirm the root is Btrfs and identify the subvolume:
findmnt -no FSTYPE,SOURCE /
# btrfs /dev/mapper/almalinux-root[/@]
If your root is xfs or ext4, this article doesn’t apply — you’d need to reinstall onto Btrfs or use a different snapshot strategy (LVM snapshots, ZFS root).
Install snapper, the dnf hook, and grub-btrfs:
dnf -y install epel-release
dnf -y install snapper python3-dnf-plugin-snapper grub-btrfs inotify-tools
Create the snapper config for the root subvolume:
snapper -c root create-config /
Edit /etc/snapper/configs/root and tune retention. A pragmatic set:
TIMELINE_CREATE="yes"
TIMELINE_CLEANUP="yes"
TIMELINE_MIN_AGE="1800"
TIMELINE_LIMIT_HOURLY="6"
TIMELINE_LIMIT_DAILY="7"
TIMELINE_LIMIT_WEEKLY="4"
TIMELINE_LIMIT_MONTHLY="6"
TIMELINE_LIMIT_YEARLY="0"
NUMBER_CLEANUP="yes"
NUMBER_MIN_AGE="1800"
NUMBER_LIMIT="50"
NUMBER_LIMIT_IMPORTANT="20"
EMPTY_PRE_POST_CLEANUP="yes"
EMPTY_PRE_POST_MIN_AGE="1800"
Six hourly, seven daily, four weekly, six monthly is roughly the smallest envelope that survives “yesterday’s update broke us” plus “last week’s update introduced a slow leak that we only noticed today.” Tune up if your filesystem has room; the cost is mostly metadata.
Enable the timers and the GRUB regenerator:
systemctl enable --now snapper-timeline.timer
systemctl enable --now snapper-cleanup.timer
systemctl enable --now grub-btrfsd
Move volatile state off the root subvolume. This is the step operators most often skip. For a typical production server:
# Move MySQL/MariaDB
systemctl stop mariadb
mv /var/lib/mysql /var/lib/mysql.tmp
btrfs subvolume create /var/lib/mysql
rsync -aXSH /var/lib/mysql.tmp/ /var/lib/mysql/
restorecon -RF /var/lib/mysql
chown -R mysql:mysql /var/lib/mysql
rm -rf /var/lib/mysql.tmp
systemctl start mariadb
# Same pattern for PostgreSQL, /var/log, /var/cache
Add a nodatacow attribute on database directories to disable CoW for files inside them, which Btrfs handles poorly under heavy random write:
chattr +C /var/lib/mysql
chattr +C /var/lib/pgsql
(+C only applies to files created after; for an existing directory, move-and-recreate is cleaner than trying to retag the existing files.)
Force grub-btrfs to regenerate now:
systemctl restart grub-btrfsd
grub2-mkconfig -o /boot/grub2/grub.cfg
Reboot. At the GRUB menu, the “Btrfs Snapshots” submenu should list the most recent snapshots. Pick one, boot it read-write, and you’re running on history.
Two practical drills before this is “in production”:
-
Pre/post drill. Run
dnf -y update --advisory=ALSA-2026:0001(or any small update). After it completes, runsnapper -c root list. There should be a fresh pre/post pair tagged “dnf”. If not, the dnf hook isn’t loaded —rpm -q python3-dnf-plugin-snapper. -
Rollback drill. As shown in the verification section: create a marker file, take a snapshot, modify the filesystem, reboot into the snapshot via GRUB, then
snapper rollback. The marker file should be gone after the second reboot. Document the keystrokes in your runbook — the operator who has to do this at 03:00 should not be reading the manual.
Snapshots are not backups. A snapper rollback restores the root subvolume from local CoW data; it does nothing if the disk dies, the rack catches fire, or someone runs mkfs.btrfs on the wrong device. Snapshots cover “the update broke us” and “I deleted the wrong config file.” Off-host backups cover everything else — keep both.
Stack Harbor operates Btrfs and ZFS-backed Linux fleets under Managed Cloud Ops, including snapshot-aware patching windows so updates that misbehave get rolled back, not debugged at 03:00. If your update playbook today is “restore from backup and pray,” book a patching review.