Install Fedora 37 with Snapper and Grub-Btrfs - Feature Image

How to Install Fedora 37 with Snapper and Grub-Btrfs for Full System Rollback

In this blog, I will show you how to install Fedora 37 with snapper and grub-btrfs packages, allowing you to take snapshots of the / and /home subvolume as well as perform a full system rollback on the / volume if something goes wrong.

Fedora 37 includes the latest GNOME 43 desktop, which seeks to improve the user experience. Apart from some package upgrades and downgrades, not much has changed under the hood compared to Fedora 36.

Just like the RPM database was relocated to /usr (/usr/lib/sysimage/rpm) in Fedora 36, I anticipated the DNF database to be relocated to /usr in Fedora 37. But, sadly, this did not happen. It is still held back in /var/lib/dnf. The good news is that this will happen in Fedora 38 with the new DNF5 package manager.

If both databases were in /usr, you could have completely excluded the /var directory from the rollback regime. The /usr could then be rolled back as a unit and there would be no mismatch in the database regarding packages. This would prevent any failed or undesired changes to the operating system.

So, to avoid package mismatches between the two databases, I need to keep the /var directory in the rollback regime. I will, however, exclude the /var/log directory so that log data are not lost during rollbacks. You may add more directories if you wish.

If you prefer to install Fedora 37 with LUKS Full Disk Encryption and Full System Rollback feature, please visit my other article ‘How to Install Fedora 37 with LUKS Full Disk Encryption, Snapper, and Grub-Btrfs for Full System Rollback

So let's get started.

Table of Contents

1. Disk Layout for Fedora 37

I'll be using a 100 GiB hard disk, and this is how the disk partition looks. No separate swap partition is needed because Fedora automatically generates a SwapOnZRAM on boot.

NAME         SIZE  FSTYPE LABEL   MOUNTPOINT
/dev/vda     100G              
├─/dev/vda1  512M  vfat   EFI     /boot/efi
└─/dev/vda2 99.5G  btrfs  FEDORA  /

These are the subvolumes that will be created from the btrfs volume (/dev/vda2).

NAME               MOUNTPOINT          TYPE
[main]             /                   mainvolume
home               /home               subvolume 
var/log            /var/log            subvolume
.snapshots         /.snapshots         subvolume
home/.snapshots    /home/.snapshots    subvolume

Below are the directories for which subvolumes are created and the reasons for doing so.

/home

Contains user data. It is created to keep user data separate and also to avoid loss of user data on / volume rollbacks.

/var/log

Contains log files. It is created to avoid the loss of log data during rollbacks.

/.snapshots

Contains snapshots of / volume. Allows you to undo any changes or completely roll back a snapshot from the GRUB menu.

/home/.snapshots

Contains snapshots of /home subvolume. Allows you to undo any changes in the /home directory. No rollbacks from the GRUB menu on the /home directory.

Depending on your needs, you may also want to create some additional subvolumes. For example, /opt, /var/www, /var/lib/libvirt/images, and so on.

2. Install Fedora 37 Workstation

Boot your system using the Fedora 37 Workstation installer in UEFI mode. On the welcome screen, select the Install to Hard Drive option. Next, select your LanguageKeyboard, and configure Time & Date. Following that, from the INSTALLATION SUMMARY screen, select Installation Destination.

You should now be on the INSTALLATION DESTINATION screen. To proceed, pick the Advanced Custom (Blivet-GUI) radio button and then hit the Done button.

Install Fedora 37 with Snapper and Grub-Btrfs Blivet

On the BLIVET GUI PARTITIONING screen, create the partitions, file systems, and btrfs subvolumes necessary to install Fedora 37 Workstation.

First, you need to create and mount the EFI partition. Select the free space and click the + sign to create a partition.

Install Fedora 37 with Snapper and Grub-Btrfs Blivet Partition

Set the partition Size to 512 MiB, the Filesystem to EFI System Partition, and the Mountpoint to /boot/efi.

Install Fedora 37 with Snapper and Grub-Btrfs Blivet EFI

Then, you need to create a btrfs volume where you can create all the subvolumes needed to install Fedora 37 Workstation.

Select the free space again and click on the + sign to create a Btrfs volume. Set the Filesystem to btrfs and the Mountpoint to /. I used the entire remaining space. However, you can specify the size you want for the btrfs volume.

Install Fedora 37 with Snapper and Grub-Btrfs Blivet BTRFS

Next, you must create a home subvolume. (1) Select the Btrfs Volume from the left panel, and (2) click on the + sign on the right panel.

Install Fedora 37 with Snapper and Grub-Btrfs Blivet Subvolume

Create a home subvolume. Enter the Name as home and Mountpoint as /home. Click OK to finish.

Install Fedora 37 with Snapper and Grub-Btrfs Blivet Home

I will create the remaining subvolumes when the installation is finished. This is because the Anaconda installer does not allow you to create subvolumes with slashes (/) in their names, such as var/log.

For now, click Done to finish creating subvolumes.

On the SUMMARY OF CHANGES screen, double-check that everything is properly defined. To finalize the changes, click the Accept Changes button.

Install Fedora 37 with Snapper and Grub-Btrfs Summary

You will be returned to the INSTALLATION SUMMARY screen. Press the Begin Installation button to start the installation process. The installation process will start. Just sit back and relax.

Install Fedora 37 with Snapper and Grub-Btrfs Installation

When the installation is finished, click the Finish installation button and restart the system.

The last phase of the installation procedure will start. Click the Start Setup button to complete the remaining customization steps, such as setting a new login, password, and so on.

You will then be logged into the Fedora 37 Workstation with the all-new Gnome 43 desktop interface.

Install Fedora 37 with Snapper and Grub-Btrfs Blivet NOME 43

Now, open the Gnome terminal.

Set the btrfs volume label. I named the btrfs volume FEDORA, but you may name it whatever you want.

$ sudo btrfs filesystem label / FEDORA

$ sudo btrfs filesystem show /
Label: 'FEDORA'  uuid: ff003a16-2819-493a-b4a5-4a8dec85ea7d
	Total devices 1 FS bytes used 6.40GiB
	devid    1 size 99.50GiB used 9.02GiB path /dev/vda2

Create the /var/log subvolume.

$ sudo mv -v /var/log /var/log-old
$ sudo btrfs subvolume create /var/log
$ sudo cp -arv /var/log-old/. /var/log/
$ sudo restorecon -RFv /var/log
$ sudo rm -rvf /var/log-old

In the /etc/fstab file, add the newly created /var/log subvolume. The updated line is displayed in amber. Replace UUID with your setup's UUID.

$ sudo vi /etc/fstab
UUID=ff003a16-2819-493a-b4a5-4a8dec85ea7d /         btrfs defaults 0 0
UUID=0799-62F5                            /boot/efi vfat  umask=0077,shortname=winnt 0 2
UUID=ff003a16-2819-493a-b4a5-4a8dec85ea7d /home     btrfs subvol=home,compress=zstd:1 0 0
UUID=ff003a16-2819-493a-b4a5-4a8dec85ea7d /var/log  btrfs subvol=var/log,compress=zstd:1 0 0

Reload the /etc/fstab file to mount all filesystems.

$ sudo systemctl daemon-reload
$ sudo mount -va

Your setup should now look somewhat like this.

$ lsblk -p
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
/dev/zram0  251:0    0  3.8G  0 disk [SWAP]
/dev/vda    252:0    0  100G  0 disk 
├─/dev/vda1 252:1    0  512M  0 part /boot/efi
└─/dev/vda2 252:2    0 99.5G  0 part /var/log
                                     /home
                                     /

Finally, list all subvolumes.

$ sudo btrfs subvolume list /
ID 256 gen 61 top level 5 path home
ID 257 gen 51 top level 5 path var/lib/machines
ID 258 gen 65 top level 5 path var/log

The var/lib/machines subvolume is created by systemd implicitly in Fedora 37 Workstation for systemd-nspawn containers.

The Fedora 37 Workstation installation is now complete.

3. Install and Configure Snapper

Install snapper and the optional package python3-dnf-plugin-snapper. The python3-dnf-plugin-snapper package allows you to create pre and post snapshots every time you install a package on the system with the dnf package manager.

$ sudo dnf install snapper python3-dnf-plugin-snapper

Create new snapper configurations named root and home for the Btrfs volume at / and /home, respectively.

$ sudo snapper -c root create-config /
$ sudo snapper -c home create-config /home

Verify the snapper configuration files have been created.

$ sudo snapper list-configs
Config | Subvolume
-------+----------
home   | /home    
root   | /

Allow the regular user to list snapshots. Add your user name in the snapper's root and home configurations.

$ sudo snapper -c root set-config ALLOW_USERS=$USER SYNC_ACL=yes
$ sudo snapper -c home set-config ALLOW_USERS=$USER SYNC_ACL=yes

Change the group permissions of the /.snapshots and /home/.snapshots directories to your user name.

$ sudo chown -R :$USER /.snapshots
$ sudo chown -R :$USER /home/.snapshots

Finally, in the /etc/fstab file, add the newly created snapshots subvolumes. The updated lines are displayed in amber.

$ sudo vi /etc/fstab
UUID=ff003a16-2819-493a-b4a5-4a8dec85ea7d /                btrfs defaults 0 0
UUID=0799-62F5                            /boot/efi        vfat  umask=0077,shortname=winnt 0 2
UUID=ff003a16-2819-493a-b4a5-4a8dec85ea7d /home            btrfs subvol=home,compress=zstd:1 0 0
UUID=ff003a16-2819-493a-b4a5-4a8dec85ea7d /var/log         btrfs subvol=var/log,compress=zstd:1 0 0
UUID=ff003a16-2819-493a-b4a5-4a8dec85ea7d /.snapshots      btrfs subvol=.snapshots,compress=zstd:1 0 0
UUID=ff003a16-2819-493a-b4a5-4a8dec85ea7d /home/.snapshots btrfs subvol=home/.snapshots,compress=zstd:1 0 0

Reload the /etc/fstab file.

$ sudo systemctl daemon-reload
$ sudo mount -va

Your setup should look something like this.

$ lsblk -p /dev/vda
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
/dev/vda    252:0    0  100G  0 disk 
├─/dev/vda1 252:1    0  512M  0 part /boot/efi
└─/dev/vda2 252:2    0 99.5G  0 part /home/.snapshots
                                     /.snapshots
                                     /home
                                     /var/log
                                     /

And your subvolumes will look like this.

$ sudo btrfs subvolume list /
ID 256 gen 86 top level 5 path home
ID 257 gen 70 top level 5 path var/lib/machines
ID 258 gen 89 top level 5 path var/log
ID 259 gen 82 top level 5 path .snapshots
ID 260 gen 82 top level 256 path home/.snapshots

Enable snapshot booting by appending the SUSE_BTRFS_SNAPSHOT_BOOTING="true" option to the /etc/default/grub file.

$ echo 'SUSE_BTRFS_SNAPSHOT_BOOTING="true"' | sudo tee -a /etc/default/grub

Because snapshot booting is now enabled, you must make changes to the /boot/efi/EFI/fedora/grub.cfg file as well.

$ sudo sed -i '1i set btrfs_relative_path="yes"' /boot/efi/EFI/fedora/grub.cfg

Update the grub.cfg file.

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

Finally, disable the GRUB menu auto-hide feature.

$ sudo grub2-editenv - unset menu_auto_hide

The snapper configuration is now complete.

List the snapshots for / volume. For the root, you may use snapper -c root ls or simply snapper ls. Both provide the same output.

$ snapper ls
 # | Type   | Pre # | Date | User | Cleanup | Description | Userdata
---+--------+-------+------+------+---------+-------------+---------
0  | single |       |      | root |         | current     |

List the snapshots for /home subvolume.

$ snapper -c home ls
 # | Type   | Pre # | Date | User | Cleanup | Description | Userdata
---+--------+-------+------+------+---------+-------------+---------
0  | single |       |      | root |         | current     |

At this stage, you do not have any snapshots, we will create some later.

4. Install and Configure Grub-Btrfs

Consider the following scenario: you make a mistake, and the system fails to start properly the next time. You may want to revert to a previously working snapshot and reboot again.

The grub-btrfs package provides this functionality. The package adds "Fedora Linux snapshots" to the GRUB menu and allows you to boot to a snapshot in read-only mode to test it before rolling back to it in read-write mode.

So, clone the grub-btrfs repository.

$ git clone https://github.com/Antynea/grub-btrfs
$ cd grub-btrfs
$ git switch Add-systemd-volatile

The setup is initially configured to work with Arch and Gentoo out of the box. To make it work with Fedora, you must make a few changes to the grub-btrfs config file.

$ sed -i 's/#GRUB_BTRFS_SYSTEMD_VOLATILE=/GRUB_BTRFS_SYSTEMD_VOLATILE=/' config
$ sed -i 's/#GRUB_BTRFS_GRUB_DIRNAME=/GRUB_BTRFS_GRUB_DIRNAME=/' config
$ sed -i '/#GRUB_BTRFS_MKCONFIG=/c\GRUB_BTRFS_MKCONFIG=/sbin/grub2-mkconfig' config
$ sed -i 's/#GRUB_BTRFS_SCRIPT_CHECK=/GRUB_BTRFS_SCRIPT_CHECK=/' config

Then install it.

$ sudo make INITCPIO=true install

Update the grub.cfg file. You will receive the 'No snapshots found' error since you have not yet created any snapshots, but don't worry, it will function properly after you do.

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

Finally, enable the grub-btrfs.path

$ sudo systemctl enable --now grub-btrfs.path

Your grub-btrfs installation is now complete. You may now delete the cloned grub-btrfs repository.

$ cd ..
$ rm -rvf grub-btrfs

5. Test the Snapper's Undochange and Rollback Features.

I will run three tests here to ensure that everything is working properly and that there are no issues.

Test 1: Undo the Changes Made by the DNF Installer

In this test, I will install a small package called ps_mem using the dnf package manager. After it has been installed, I will check the system to see what changes have been made. I will then attempt to undo the changes and see if I can restore the system to its pre-installation state.

Install the ps_mem package. It displays the core memory used per program (not per process).

$ sudo dnf install ps_mem

Run the ps_mem program.

$ sudo ps_mem
 Private  +   Shared  =  RAM used	Program

144.0 KiB +  16.5 KiB = 160.5 KiB	fusermount3
288.0 KiB +  14.5 KiB = 302.5 KiB	mcelog
316.0 KiB +  41.5 KiB = 357.5 KiB	rtkit-daemon
432.0 KiB +  51.5 KiB = 483.5 KiB	gnome-session-ctl
...
 45.5 MiB +   7.2 MiB =  52.8 MiB	gnome-software
 50.6 MiB +   3.8 MiB =  54.4 MiB	python3.11
209.8 MiB +  25.3 MiB = 235.1 MiB	gnome-shell
361.4 MiB +   1.8 MiB = 363.1 MiB	packagekitd
---------------------------------
                          1.2 GiB
=================================

The ps_mem package has been successfully installed. Check the snapper for snapshots.

$ snapper ls
 # | Type   | Pre # | Date                                 | User | Cleanup | Description                 | Userdata
---+--------+-------+--------------------------------------+------+---------+-----------------------------+---------
0  | single |       |                                      | root |         | current                     |         
1  | pre    |       | Tuesday 15 November 2022 10:18:12 AM | root | number  | /usr/bin/dnf install ps_mem |         
2  | post   |     1 | Tuesday 15 November 2022 10:18:19 AM | root | number  | /usr/bin/dnf install ps_mem |

As you can see, the pre (#1) and the post (#2) snapshots have been created for the ps_mem package.

Let me examine the changes it has made to the system, between snapshots #1 and #2.

$ snapper status 1..2
+..... /boot/grub2/grub.cfg.new
+..... /usr/bin/ps_mem
c..... /usr/lib/sysimage/rpm/rpmdb.sqlite-shm
c..... /usr/lib/sysimage/rpm/rpmdb.sqlite-wal
+..... /usr/share/doc/ps_mem
+..... /usr/share/doc/ps_mem/LICENSE
+..... /usr/share/man/man1/ps_mem.1.gz
c..... /var/cache/dnf/packages.db
+..... /var/cache/man/2957
c..... /var/lib/dnf/history.sqlite-shm
c..... /var/lib/dnf/history.sqlite-wal
-..... /var/lib/dnf/rpmdb_lock.pid
+..... /var/lib/os-prober/mount

Now I'll undo the changes.

$ sudo snapper undochange 1..2
create:1 modify:5 delete:7

Check again to ensure that the package ps_mem has been successfully uninstalled.

$ sudo ps_mem
sudo: ps_mem: command not found

Cool! The undo has been successful. But, because I want to keep the package ps_mem, I’ll undo the changes once again. This time from snapshot #2 to snapshot #1.

$ sudo snapper undochange 2..1
create:7 modify:5 delete:1

Now run the ps_mem again to see if it exists.

$ sudo ps_mem
 Private  +   Shared  =  RAM used	Program

144.0 KiB +  17.5 KiB = 161.5 KiB	fusermount3
288.0 KiB +  15.5 KiB = 303.5 KiB	mcelog
316.0 KiB +  42.5 KiB = 358.5 KiB	rtkit-daemon
432.0 KiB +  52.5 KiB = 484.5 KiB	gnome-session-ctl
...
 45.5 MiB +   7.2 MiB =  52.8 MiB	gnome-software
 50.6 MiB +   3.8 MiB =  54.4 MiB	python3.11
209.9 MiB +  25.3 MiB = 235.2 MiB	gnome-shell
361.4 MiB +   1.8 MiB = 363.1 MiB	packagekitd
---------------------------------
                          1.2 GiB
=================================

Test 1 is successful.

Test 2: Undo the Changes Made by the GNOME Software

While you can easily create pre-post snapshots when using the command-line dnf package installer, this is not the case when using the GNOME Software to install a package. Hopefully, the next major upgrade to the new package manager DNF5 with a new libdnf5 library and a new DNF Daemon will resolve this issue.

For now, the only way to create a pre-post snapshot while using the GNOME Software is to create them manually.

So, in this test, I will install a package called Audacious using the GNOME Software. To install Audacious, I will manually create pre and post snapshots for both the / and /home directories to capture all the files that will be added or altered. Then I'll try to undo all of the changes and see if I can get the system back to its pre-installation state.

Before you install Audacious, create a manual 'pre' snapshot for both the / and /home directories.

$ sudo snapper -c root create -t pre -c number -d 'Before Audacious'
$ sudo snapper -c home create -t pre -c number -d 'Before Audacious'

List the snapshots.

$ snapper -c root ls
 # | Type   | Pre # | Date                                 | User | Cleanup | Description                 | Userdata
---+--------+-------+--------------------------------------+------+---------+-----------------------------+---------
0  | single |       |                                      | root |         | current                     |         
1  | pre    |       | Tuesday 15 November 2022 10:18:12 AM | root | number  | /usr/bin/dnf install ps_mem |         
2  | post   |     1 | Tuesday 15 November 2022 10:18:19 AM | root | number  | /usr/bin/dnf install ps_mem |         
3  | pre    |       | Tuesday 15 November 2022 10:30:10 AM | root | number  | Before Audacious            |         
$ snapper -c home ls
 # | Type   | Pre # | Date                                 | User | Cleanup | Description      | Userdata
---+--------+-------+--------------------------------------+------+---------+------------------+---------
0  | single |       |                                      | root |         | current          |         
1  | pre    |       | Tuesday 15 November 2022 10:30:19 AM | root | number  | Before Audacious |

As you can see, a manual 'pre' snapshot for both directories has been created.

Launch the GNOME Software and install the Audacious package.

Install Fedora 37 with Snapper and Grub-Btrfs Audacious Install

Launch the Audacious to test if it is installed.

Install Fedora 37 with Snapper and Grub-Btrfs Audacious Open

The Audacious has been successfully installed.

Now, create a 'post' snapshot for the previously created 'pre' snapshot for both directories.

$ sudo snapper -c home create -t post --pre-number 1 -c number -d 'After Audacious'
$ sudo snapper -c root create -t post --pre-number 3 -c number -d 'After Audacious'

List the snapshots.

$ snapper -c root ls
 # | Type   | Pre # | Date                                 | User | Cleanup | Description                 | Userdata
---+--------+-------+--------------------------------------+------+---------+-----------------------------+---------
0  | single |       |                                      | root |         | current                     |         
1  | pre    |       | Tuesday 15 November 2022 10:18:12 AM | root | number  | /usr/bin/dnf install ps_mem |         
2  | post   |     1 | Tuesday 15 November 2022 10:18:19 AM | root | number  | /usr/bin/dnf install ps_mem |         
3  | pre    |       | Tuesday 15 November 2022 10:30:10 AM | root | number  | Before Audacious            |         
4  | post   |     3 | Tuesday 15 November 2022 10:34:04 AM | root | number  | After Audacious             |         

$ snapper -c home ls
 # | Type   | Pre # | Date                                 | User | Cleanup | Description      | Userdata
---+--------+-------+--------------------------------------+------+---------+------------------+---------
0  | single |       |                                      | root |         | current          |         
1  | pre    |       | Tuesday 15 November 2022 10:30:19 AM | root | number  | Before Audacious |         
2  | post   |     1 | Tuesday 15 November 2022 10:33:52 AM | root | number  | After Audacious  |

Review the changes made to the system between the pre and post snapshots.

$ snapper -c home status 1..2
c..... /home/madhu/.bash_history
c..... /home/madhu/.cache/gnome-software/appstream/components.xmlb
+..... /home/madhu/.cache/gnome-software/odrs/audacious.desktop.json
...
-..... /home/madhu/.local/share/gvfs-metadata/root-f6371618.log
c..... /home/madhu/.local/state/wireplumber/restore-stream

$ snapper -c root status 3..4
c..... /boot/grub2/grub-btrfs.cfg
....x. /etc/dconf/db/distro
c...x. /etc/dconf/db/gdm
...
....x. /var/lib/flatpak/oci/fedora.index.gz
c..... /var/lib/PackageKit/transactions.db

This is the total number of files added, removed, or modified.

$ snapper -c home status 1..2 | wc -l
91

$ snapper -c root status 3..4 | wc -l
3513

I'll now undo the changes in the / and /home directories.

$ sudo snapper -c home undochange 1..2
create:2 modify:8 delete:81

$ sudo snapper -c root undochange 3..4
create:7 modify:15 delete:3491

The Audacious package will be completely removed from the system. However, if you launch the GNOME Software and check, it will show that the program is still installed. Just restart the packagekit service, log out, and then log back in to update the changes in the GNOME Software.

$ sudo systemctl restart packagekit
$ gnome-session-quit
Install Fedora 37 with Snapper and Grub-Btrfs Audacious Clean

Test 2 is successful.

When you undo changes, snapshot links in the GRUB menu are sometimes deleted as well. Check /boot/grub2/grub-btrfs.cfg file to ensure that snapshots have not been deleted from the GRUB menu. To rebuild links in the GRUB menu, run the following command.

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

Since you removed the Audacious package, and if you do not intend to use it again, there is no reason to keep its pre-post snapshots. So you can delete those snapshots as well.

$ sudo snapper -c home delete 1-2
$ sudo snapper -c root delete 3-4

List the snapshots. All the snapshots related to Audacious have been deleted.

$ snapper -c home ls
 # | Type   | Pre # | Date | User | Cleanup | Description | Userdata
---+--------+-------+------+------+---------+-------------+---------
0  | single |       |      | root |         | current     |         

$ snapper -c root ls
 # | Type   | Pre # | Date                                 | User | Cleanup | Description                 | Userdata
---+--------+-------+--------------------------------------+------+---------+-----------------------------+---------
0  | single |       |                                      | root |         | current                     |         
1  | pre    |       | Tuesday 15 November 2022 10:18:12 AM | root | number  | /usr/bin/dnf install ps_mem |         
2  | post   |     1 | Tuesday 15 November 2022 10:18:19 AM | root | number  | /usr/bin/dnf install ps_mem |

Test 3: Rollback to a Previous Snapshot from the GRUB Menu

In this rollback test, I will delete the most critical files and directories on which the Linux operating system relies. These include Linux kernel and initramfs files in the /boot directory, the /etc directory, which contains all configuration files, and the /usr directory, which contains all drivers, kernel modules, and library files.

Once I delete these files and directories, I will be unable to issue any commands because the Linux OS is pretty much dead, and the system will undoubtedly fail the next time it boots. So I'll hard boot the system and see if I can save the day by rolling back to a working snapshot.

So, before I delete them, here's how they appear.

$ sudo du -sch /boot /etc /usr
180M	/boot
32M	/etc
5.3G	/usr
5.5G	total

Now delete the files and directories.

$ sudo rm -rf /boot/{vmlinuz,initramfs}* /etc /usr

Boom!!! All of the critical files have been deleted. Your Linux system has been rendered inoperable.

Restart the system. Your system should now fail to boot and display an error message similar to this.

Install Fedora 37 with Snapper and Grub-Btrfs Boot Error

Return to the GRUB menu and this time boot from snapshot #2.

Install Fedora 37 with Snapper and Grub-Btrfs Snapshots Menu
Install Fedora 37 with Snapper and Grub-Btrfs Snapshot No 2
Install Fedora 37 with Snapper and Grub-Btrfs Snapshot Latest

Open the terminal and make sure everything is back to normal.

$ sudo ls /boot /etc /usr

Because you booted into the snapshot, the '/' file system is read-only.

$ sudo btrfs property get -ts /
ro=true

Now that everything appears to be operating properly, it is time to roll back this snapshot in read-write mode.

$ snapper ls
 # | Type   | Pre # | Date                                 | User | Cleanup | Description                 | Userdata
---+--------+-------+--------------------------------------+------+---------+-----------------------------+---------
0  | single |       |                                      | root |         | current                     |         
1  | pre    |       | Tuesday 15 November 2022 10:18:12 AM | root | number  | /usr/bin/dnf install ps_mem |         
2- | post   |     1 | Tuesday 15 November 2022 10:18:19 AM | root | number  | /usr/bin/dnf install ps_mem |         

$ sudo snapper --ambit classic rollback 2
Ambit is classic.
Creating read-only snapshot of current system. (Snapshot 3.)
Creating read-write snapshot of snapshot 2. (Snapshot 4.)
Setting default subvolume to snapshot 4.

$ sudo reboot

After the reboot, check the system once again.

$ sudo du -sch /boot /etc /usr
180M	/boot
32M	/etc
5.3G	/usr
5.5G	total

$ sudo btrfs property get -ts /
ro=false

$ snapper ls
 # | Type   | Pre # | Date                                 | User | Cleanup | Description                 | Userdata     
---+--------+-------+--------------------------------------+------+---------+-----------------------------+--------------
0  | single |       |                                      | root |         | current                     |              
1  | pre    |       | Tuesday 15 November 2022 10:18:12 AM | root | number  | /usr/bin/dnf install ps_mem |              
2  | post   |     1 | Tuesday 15 November 2022 10:18:19 AM | root | number  | /usr/bin/dnf install ps_mem |              
3  | single |       | Tuesday 15 November 2022 11:31:10 AM | root | number  | rollback backup             | important=yes
4* | single |       | Tuesday 15 November 2022 11:31:11 AM | root |         | writable copy of #2         |

$ sudo btrfs subvolume list /
ID 256 gen 203 top level 5 path home
ID 257 gen 183 top level 5 path var/lib/machines
ID 258 gen 204 top level 5 path var/log
ID 259 gen 204 top level 5 path .snapshots
ID 260 gen 183 top level 256 path home/.snapshots
ID 261 gen 125 top level 259 path .snapshots/1/snapshot
ID 262 gen 194 top level 259 path .snapshots/2/snapshot
ID 263 gen 193 top level 259 path .snapshots/3/snapshot
ID 264 gen 203 top level 259 path .snapshots/4/snapshot

$ sudo btrfs subvolume get-default /
ID 264 gen 203 top level 259 path .snapshots/4/snapshot

You successfully restored the system with the latest working snapshot in read and write mode.

After a successful rollback, always ensure that the grub.cfg file is updated so that the snapshots on the grub-btrfs menu are always in sync.

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

Test 3 is successful.

6. Conclusion

You have now installed and configured Fedora 37 to properly rollback to any snapshots. Going from here, you can also configure the snapper to take snapshots at predetermined intervals. Visit the Arch Wiki’s Snapper page for more information.

Watch on YouTube