Btrfs system snapshots and rollbacks with Timeshift v2


The snapshot feature of the Btrfs filesystem can be used to perform system snapshots and rollbacks. With Timeshift there is also an easy to use a graphical application for that.
Unfortunately, the current RebornOS installer only allows installation on the bare Btrfs filesystem, and not on the @ subvolume, which would be needed to perform system snapshots and rollbacks with Timeshift.

In this guide I will explain the steps to move RebornOS from the bare Btrfs filesystem to a Timeshift-compatible subvolume layout.

Before you start

I would advise against using a boot partition (mount point /boot) with Btrfs system subvolumes, as that would exclude the /boot directory from system snapshots. A quick way to remove your boot partition is explained here: to remove your systems boot partition.

Check if your system partition uses Btrfs (df -Th /). If not, you can use Btrfs-convert to convert your system partition to Btrfs if it uses the ext2/3/4 or ReiserFS filesystem. The process is explained here:

Move RebornOS to Btrfs subvolumes

1. First, create a snapshot of your system partition to /@:
sudo btrfs subvolume snapshot / /@
A snapshot is a normal subvolume, but it won't consume extra space as long as the content stays the same as it can share all data blocks with the source subvolume. All files on yor system partition are now present a second time on that subvolume.

2. Unless you want to use a separate home partition, run
sudo btrfs subvolume create /@home && sudo find /@/home -mindepth 1 -prune -exec mv -v '{}' /@home \;
to create a Timeshift-compatible home subvolume which lets you exclude the home directory /home from Btrfs system snapshots.

3. I also recommend creating additional sbuvolumes for all directories that should be excluded from Btrfs system snapshots and thereby preserved during system rollbacks.
However, you can just skip this step if you are in a hurry.
For the subvolume layout used in this guide you'll need to create snapshot of the future system subvolume @ first:
sudo btrfs subvolume snapshot /@ /@2

You can now execute the following commands to replace the relevant directories in the @ subvolume with Btrfs subvolumes of the same name and move the content snapshotted to subvolume @2 back to its place:
Warning: Don't run any of the following commands twice. If you happen to do that just run sudo btrfs subvolume delete /@, sudo btrfs subvolume delete /@2,sudo btrfs subvolume delete /@home, and sudo btrfs subvolume snapshot / /@ and start from the beginning of step 1 (1.) again.
/var contains variable data like system logs (/var/log), temporary files (/var/cache, /var/tmp), and program data from various applications, including default locations for virtual machine images and databases, and should be excluded from system snapshots to avoid data loss, keep system logs accessible and keep snapshots small:
sudo rm -rfv /@/var && sudo btrfs subvolume create /@/var && sudo find /@2/var -mindepth 1 -prune -exec mv -v '{}' /@/var \;
/root, the root users home directory, should be preserved on rollbacks:
sudo rm -rfv /@/root && sudo btrfs subvolume create /@/root && sudo find /@2/root -mindepth 1 -prune -exec mv -v '{}' /@/root \;
/opt is the default location for third-party programs and should be excluded so the programs don't get removed on rollbacks:
sudo rm -rfv /@/opt && sudo btrfs subvolume create /@/opt && sudo find /@2/opt -mindepth 1 -prune -exec mv -v '{}' /@/opt \;
/usr/local is used when manually installing software and should be excluded to avoid uninstalling these installations on rollbacks:
sudo rm -rfv /@/usr/local && sudo btrfs subvolume create /@/usr/local && sudo find /@2/usr/local -mindepth 1 -prune -exec mv -v '{}' /@/usr/local \;
/srv might contain important data if you use your system as a web or file server and should be excluded from system snapshots to avoid data loss on system rollbacks:
sudo rm -rfv /@/srv && sudo btrfs subvolume create /@/srv && sudo find /@2/srv -mindepth 1 -prune -exec mv -v '{}' /@/srv \;
/tmp is only used for temporary files and should therefore be excluded from system snapshots:
sudo rm -rfv /@/tmp && sudo btrfs subvolume create /@/tmp

You can now safely remove the @2 subvolume:
sudo btrfs subvolume delete /@2

4. Make sure the top-level subvolume (id=5) is the default, otherwise Timeshift will not work:
sudo btrfs subvolume set-default 5 /

Edit the new systems file systems table (fstab)

To account for the changes, you have to edit /etc/fstab for the new RebornOS system on the new system subvolume, /@/etc/fstab.
You can use nano for that:
sudo nano /@/etc/fstab

Every subvolume that should be mounted during boot needs its own entry in fstab, a minimum entry for a non-default subvolume would look like this:

UUID=<UUID of filesystem the subvolume resides in>  btrfs  subvol=<path of subvolume relative to the top-level subvolume>  0  0

This is an example of how fstab could look like after editing:

UUID=11111111-1111-1111-1111-111111111111 /                     btrfs subvol=@,defaults,noatime,discard=async,compress=zstd 0 0
UUID=11111111-1111-1111-1111-111111111111 /home                 btrfs subvol=@home,relatime                                 0 0
UUID=11111111-1111-1111-1111-111111111111 /var                  btrfs subvol=@/var                                          0 0
UUID=11111111-1111-1111-1111-111111111111 /root                 btrfs subvol=@/root                                         0 0
UUID=11111111-1111-1111-1111-111111111111 /opt                  btrfs subvol=@/opt                                          0 0
UUID=11111111-1111-1111-1111-111111111111 /usr/local            btrfs subvol=@/usr/local                                    0 0
UUID=11111111-1111-1111-1111-111111111111 /srv                  btrfs subvol=@/srv                                          0 0
tmpfs                                     /tmp                  tmpfs defaults,mode=1777                                    0 0
UUID=0000-0000                            /boot/efi             vfat  defaults,noatime                                      0 2
UUID=22222222-2222-2222-2222-222222222222 swap                  swap  sw                                                    0 0
Btrfs mount options propagate down through mount points when the mounted subvolumes are on the same filesystem, unless mount options that can be applied independently per subvolume contradict with mount options set for a subvolume mounted to a lower directory on the same filesystem. That's why mount options defaults and compress are only specified once for the system subvolume.

Mount your new RebornOS system to a temporary mountpoint

After editing /@/etc/fstab, the only thing left to do to make the new RebornOS system on the new system subvolume bootable is to reinstall the bootloader for the new RebornOS system, so it will actually boot the new RebornOS system. To do this, you have to mount the new RebornOS system so you can chroot into it.

If you chose to use a separate home partition which is also used by your current system you'll have to perform the following commands from a live ISO.

1. Find out the device name of the system partition (mount point /) and, if present, the EFI system partition (mount point /boot/efi). lsblk, fdisk -l or a graphical partition manager are good ways to do that.

2. Mount the new system subvolume to /mnt: sudo mount -o subvol=@ /dev/<device name of system partition> /mnt
Mounting the @home subvolume (sudo mount -o subvol=@home /dev/<device name of system partition> /mnt/home) is not necessary.
Now the only thing missing is the EFI system partition (if you have one):
/boot/efi: sudo mount /dev/<device name of EFI system partition> /mnt/boot/efi

Now all the necessary parts of your new RebornOS system should be mounted.

Chroot into the new system and reinstall GRUB

1. Chroot into the new RebornOS system:
sudo arch-chroot /mnt

2. If you are on an UEFI system with EFI system partition, run grub-install --target=x86_64-efi --efi-directory=/boot/efi.
If you are on a Legacy BIOS system, run grub-install /dev/<device name of system disk> instead.
A simple grub-install might do the job as well, for both legacy BIOS and UEFI installations.

3. After (re)installing the bootloader you also have to update the GRUB configuration file:
grub-mkconfig -o /boot/grub/grub.cfg

4. Run exit to leave the chroot jail. You can now reboot and should end up in the new RebornOS system on the @ subvolume. The system is now ready for Btrfs snapshots with Timeshift.

You might have to manually activate *cronie.service* by running sudo systemctl enable --now cronie.service for Timeshift scheduled snapshots to work.

Remove the old RebornOS system

1. Mount the top-level subvolume to /mnt:
sudo mount /dev/<device name of system partition> /mnt

2. Remove everything except system subvolumes and their content from the system partition:
sudo find /mnt -mindepth 1 -prune \! -name @* -exec rm -rfv '{}' +

Boot into Timeshift Btrfs snapshots from GRUB with grub-btrfs

This feature allows you to easily boot into Timshift Btrfs system snapshots and perform system rollbacks from there.

After installing grub-btrfs (sudo pamac install grub-btrfs), GRUB boot entries for existing Timeshift Btrfs snapshots get created every time the GRUB configuration file gets updated (sudo grub-mkconfig -o /boot/grub/grub.cfg).

Grub-btrfs can perform the GRUB update automatically each time a new Timeshift Btrfs snapshot is created.

1. First, run sudo systemctl enable --now grub-btrfs.path to activate the automatic update of the GRUB configuration file.

2. sudo systemctl edit grub-btrfs.path

3. sudo rm -rfv /mnt/timeshift-btrfs (Warning: This will remove all existing Timeshift Btrfs snapshots)

4. Paste or write the following text, save and exit:


5. {{{In case you want to revert your changes, for example to use Snapper instead of Timeshift to manage your system snapshots, run
systemctl revert grub-btrfs.path

6. Grub-btrfs can be configured by editing /etc/default/grub-btrfs/config.

Automatic Timeshift Btrfs system snapshot before package upgrades with timeshift-autosnap

You might also want to install timeshift-autosnap, which creates Timeshift snapshots before package upgrades using a pacman hook.
To prevent the Grub update from being performed twice when timeshift-autsnap creates a snapshot, I recommend changing the line updateGrub=true in /etc/timeshift-autosnap.conf to updateGrub=false.

I hope this guide helped you to successfully set up Btrfs system snapshots with Timeshift.