Configuring Snapper on Fedora: The Ultimate “Undo Button” Before DNF Updates

Fedora tutorial - IT technology blog
Fedora tutorial - IT technology blog

Why Btrfs on Fedora Still Needs Snapper?

After over 2 years of using Fedora as my primary coding machine, I absolutely love its package update speed. However, everything has a price. I once “suffered” when a Kernel 6.x update conflicted with NVIDIA drivers, freezing my machine right before a demo. Although Fedora uses Btrfs by default, it lacks an automatic user protection mechanism.

Btrfs is powerful at creating snapshots (point-in-time images) in an instant. Unfortunately, Fedora doesn’t automatically take a system image before you type dnf update. Snapper was created to fill exactly this gap.

Think of Snapper as an automatic camera. Every time you install software or upgrade the OS, it saves the system state. If an update breaks your Wi-Fi or audio, you just need one command to “travel back in time” to when the machine was working perfectly.

Step 1: Installing Snapper and the DNF Plugin

First, we need to install Snapper along with a plugin so it triggers automatically whenever DNF is working.

sudo dnf install snapper python3-dnf-plugin-snapper

The python3-dnf-plugin-snapper package is the heart of this combo. It helps the system automatically create a “Pre” snapshot and a “Post” snapshot every time you install anything.

Step 2: Configuring Snapper for the Root Partition

By default, Snapper doesn’t track any partitions. You need to specify it to protect the root partition (/) — where the soul of the operating system resides.

Run the following command to initialize:

sudo snapper -c root create-config /

This command creates a configuration file at /etc/snapper/configs/root. Simultaneously, a hidden subvolume at /.snapshots is created to store future snapshots.

Granting Permissions to Standard Users

Usually, only root can view snapshots. For convenience, you should add your user to the configuration file:

sudo vi /etc/snapper/configs/root

Find the line ALLOW_USERS="" and enter your username, for example: ALLOW_USERS="haoit".

Step 3: Optimizing Storage (Cleanup)

Btrfs snapshots don’t consume space immediately. However, if you modify 10GB of data, the old snapshot will retain that 10GB for backup. Without cleanup, your hard drive will fill up very quickly.

Adjust the parameters in the /etc/snapper/configs/root file to balance safety and storage space:

# Keep only 5 hourly snapshots and 7 daily snapshots
TIMELINE_LIMIT_HOURLY="5"
TIMELINE_LIMIT_DAILY="7"
TIMELINE_LIMIT_WEEKLY="0"
TIMELINE_LIMIT_MONTHLY="0"

# Keep a maximum of 10 DNF-created snapshots
NUMBER_LIMIT="10"
NUMBER_LIMIT_IMPORTANT="5"

Don’t forget to enable the system’s automatic cleanup service:

sudo systemctl enable --now snapper-cleanup.timer

Step 4: Verifying the Results

Try installing a lightweight package like htop to see Snapper in action:

sudo dnf install htop

Then, check the snapshot list:

snapper list

You will see two new lines appear with the description “number”. This is the insurance that gives you peace of mind before tinkering with the system.

Step 5: How to Rollback When Issues Occur

This is where Snapper shines. Suppose a new driver prevents you from accessing the graphical interface.

Case 1: Terminal is Still Accessible

Identify the ID of the most stable snapshot (usually the most recent “Pre” one) using the snapper list command. If that ID is 15, type:

sudo snapper rollback 15

At this point, Snapper will set snapshot 15 as the default root partition. You just need to reboot, and the machine will return exactly to its state at that time.

Case 2: System Fails to Boot

If you’re unlucky enough not to even see the login screen, you should install grub-btrfs. This tool adds the snapshot list directly to the GRUB boot menu.

sudo dnf install grub-btrfs
sudo grub2-mkconfig -o /boot/grub2/grub.cfg

From now on, if the system fails, you just need to select an old snapshot right from the boot menu for recovery.

Quick Tips for Managing Btrfs

  • Measuring actual space: The df -h command often reports Btrfs capacity incorrectly. Use sudo btrfs filesystem du -s / to know exactly how many GBs the snapshots are taking up.
  • Excluding directories: Don’t snapshot directories like /var/cache or /var/tmp. They change constantly but have no value for OS recovery.
  • Manual deletion: If you’ve just upgraded your Fedora version (e.g., from 39 to 40) and it feels stable, use snapper delete [ID] to free up several GBs of old data.

Setting up Snapper takes only 5 minutes but can save you hours of reinstalling your OS. From now on, every time you type sudo dnf upgrade, you can confidently hit Enter without worrying about breakage risks.

Share: