Safeguarding AlmaLinux 9 Updates with Btrfs Snapshots
AlmaLinux 9’s root Btrfs lets you snapshot the entire system before updates. Learn how to create, automate, and roll back snapshots, plus the trade‑offs and best‑practice cleanup strategy.
16 Jul 2025, 02:26 UTC

Why Snapshots Matter for AlmaLinux 9 Updates
AlmaLinux 9 ships the root filesystem on Btrfs by default. That means every file change during an update is recorded in a copy‑on‑write structure that can be frozen into a snapshot. A snapshot is a point‑in‑time, read‑only view of the filesystem that consumes no extra space until data diverges. If an update breaks something, you can roll back to the snapshot and restore the system to a known‑good state in minutes, rather than hunting logs or reinstalling packages.
Thesis: Use Btrfs snapshots as a first‑line defense for production systems
Rather than treating updates as a black box, integrate snapshot creation into your update workflow. The steps are simple, the recovery time is short, and the risk of data loss is dramatically reduced.
Prerequisites and Quick Check
- AlmaLinux 9 (or newer) with the root filesystem on Btrfs. If you’re on XFS or ext4, snapshots will not work.
- Root or sudo privileges.
- At least 10 % free space on the root partition to hold the snapshot’s delta.
Confirm the filesystem type:
# mount | grep btrfs
/dev/mapper/almalinux-root on / type btrfs (rw,relatime,space_cache,subvolid=5,subvol=/)
Only when the output shows btrfs can you rely on the native snapshot API.
Step‑by‑Step Snapshot Workflow
- Create a pre‑upgrade snapshot
Run before you start the upgrade so you have a clean rollback point.
# btrfs subvolume snapshot / /@preupgrade-$(date +%Y%m%d%H%M%S)Replace
/@preupgrade-…with a name that includes the date for easy identification. - Proceed with the update
Use the standard
dnf system-upgradeworkflow.# dnf system-upgrade download --releasever=10 # dnf system-upgrade rebootDuring the reboot, the system will install the new packages. If the update fails, the machine will still boot into the previous kernel, preserving the snapshot.
- Verify the upgrade
After reboot, check that you’re on the new release:
# cat /etc/os-release | grep VERSION_ID VERSION_ID="10" - Rollback if necessary
If you detect a broken service, reboot into the snapshot by editing the GRUB entry or using the
btrfs-replacecommand.# grubby --update-kernel=ALL --args="root=/dev/mapper/almalinux-root@preupgrade-202610151200" # rebootAfter a successful rollback, delete the snapshot to free space.
# btrfs subvolume delete /@preupgrade-202610151200
Automating Snapshots with DNF Hooks
Instead of manual snapshot creation, you can let dnf run a script before and after the upgrade. Create a hook script in /usr/lib/dnf/hooks/:
# cat /usr/lib/dnf/hooks/99-snapshot-pre-upgrade.d
#!/bin/bash
set -e
SNAP=/@preupgrade-$(date +%Y%m%d%H%M%S)
btrfs subvolume snapshot / $SNAP
Make it executable:
# chmod +x /usr/lib/dnf/hooks/99-snapshot-pre-upgrade.d
DNF will now automatically create a snapshot before any upgrade. You can add a corresponding post‑upgrade script that removes old snapshots if the upgrade succeeds.
Trade‑offs and Limitations
- Storage Growth – Snapshots only consume space for changed data. A large, heavily modified system can quickly fill the free space, causing the root filesystem to run out of room for new snapshots or even for normal operations.
- Write Performance – Frequent snapshot creation and deletion can add overhead to write operations because Btrfs must maintain copy‑on‑write metadata.
- Scope of Protection – Snapshots protect only the filesystem. External state such as database contents, external services, or network configuration that changed during the upgrade are not covered.
- Retention Policy Needed – Without a cleanup routine, old snapshots accumulate and can exhaust disk space. A simple cron job that deletes snapshots older than X days is recommended.
Practical Checklist Before You Roll Out
- Verify root is Btrfs.
- Ensure you have at least 10 % free space.
- Test the snapshot‑create and rollback process on a non‑production VM.
- Implement a retention policy: e.g., keep the last 3 pre‑upgrade snapshots.
- Document the rollback steps for your ops team.
Actionable Closing
Adopting Btrfs snapshots for AlmaLinux 9 updates gives you a fast, reliable rollback path that’s built into the OS. By integrating snapshot creation into your update scripts and enforcing a cleanup policy, you can reduce downtime from a failed upgrade to a matter of minutes. Test the workflow on a staging environment, then roll it out to production with confidence that you have a safety net that’s both cheap and fast.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.