This whole article starts with the idea that you just installed Archlinux, with the archinstall tool, using that tool's btrfs subvolume setup.
If you aren't using that, you'll have to adapt the steps to your situation.
First, install yay or paru.
For yay it's :
pacman -S --needed git base-devel
git clone https://aur.archlinux.org/yay.git
cd yay
makepkg -si
For paru :
pacman -S --needed git base-devel
git clone https://aur.archlinux.org/paru.git
cd paru
makepkg -si
As you can see it's very similar for both. In the rest of the article, replace yay with paru if needed.
First of all, install those two AUR packages.
yay -S snapper-support btrfs-assistant inotify-tools
Btrfs-assistant is a good GUI tool to handle your snapshots.
Snapper-support will install :
inotify-tools allows grub-btrfs to receive a message when a snapshot is taken, allowing it to rebuild the grub snapshot menu.
Then we're rebuilding the initrd image because of a verification we have to make :
sudo mkinitcpio -P
We check that the output of that command mentions grub-btrfs-overlayfs :
lsinitcpio -a /boot/initrd-linux.img
If that isn't the case, you'll have to add in the HOOKS array in /etc/mkinitcpio.conf.
If you use sway or another wayland window manager, btrfs-assistant might ask you for your password and then... not start.
It's because it needs dependencies to handle QT on wayland (QT is the GUI toolkit btrfs-assistant uses).
To install it for sure, given I don't know which version of QT btrfs-assistant uses :
yay -S qt5-wayland qt6-wayland
There, now you should be able to open btrfs-assistant just fine.
The default setup for subvolumes done by archinstall is very neat, it already includes a @.snapshots subvolume...
Except that to initialize snapper, and create its configuration, we have to let snapper create that subvolume, which leads to funky steps.
First, we'll unmount and delete the /.snapshots directory.
sudo umount /.snapshots
sudo rm -rf /.snapshots
Now, no subvolume is tied to /.snapshots. We create the snapper configuration :
sudo snapper -c root create-config /
Snapper just recreated a subvolume tied to the folder /.snapshots. That's good. We can delete it, that's not the one we'll use.
sudo btrfs subvolume delete /.snapshots
Then, we recreate the /.snapshots folder and remount it as it was before the snapper commmand. We also give it adequate permissions.
sudo mkdir /.snapshots
sudo mount -a
sudo chmod 750 /.snapshots
So, after all this, snapper created its configuration, and the directory it uses is now tied to the @.snapshots subvolume archinstall created.
Finally, make sure any user member of the wheel group can actually take snapshots. To that end, edit /etc/snapper/configs/root
and add wheel to ALLOW_GROUPS=""
Maintenant, on doit activer plusieurs services pour que tout ceci fonctionne bien.
Commençons par grub-btrfs :
sudo systemctl enable --now grub-btrfsd
sudo systemctl status grub-btrfsd
sudo grub-mkconfig -o /boot/grub/grub.cfg
That should be all good. Next, let's activate two timers for snapper : the first one will take snapshots according to the settings in your configuration, the second will clean up old snapshots, also according to that configuration
sudo systemctl enable --now snapper-timeline.timer
sudo systemctl enable --now snapper-cleanup.timer
That's it for services, now for some configuration that needs doing.
First, you might want to edit /etc/snapper/configs/root
and change some of the settings regarding the "timeline" snapshots. It's tied to how many daily/weekly/monthly snapshots snapper should do maximum. And for how long/how many it should keep.
Then it's in theory almost ready. One last step is to allow btrfs-assistant to exactly know where we're storing the snapshots, as we're not using snapper's defaults, but archinstall's defaults.
For that, edit /etc/btrfs-assistant.conf
and at the end, you'll need to add a line similar to this one under [Subvol-Mapping]
:
root = "@.snapshots,@,8421b3f7-7a99-4db1-818b-86762a56b09e"
That says to btrfs-assistant that the snapshots subvolume is @.snapshots, that the root subvolume is @, and the UUID (unique identifier) of the partition where the subvolumes are. You can get that UUID from your /etc/fstab
file.
Note : it's better to set up btrfs-assistant now, before taking any snapshot, so that configuration is also inside said snapshots. If you don't do it, btrfs-assistant inside the snapshots won't know where the snapshots and root subvolumes are.
We'll create our first manual snapshot with this command :
sudo snapper -c root create --description "first snapshot"
Now, if you start btrfs-assistant, in the "browse/restore" tab, you should see that snapshot.
Then, let's install a package to try it out, micro (a tiny terminal text editor).
sudo pacman -S micro
Finally, go to that same "browse/restore" tab of btrfs-assistant. You should see more snapshots were taken, by snap-pac this time. The description should match the package you installed (micro if you followed my example).
Reboot the system.
The first thing to check is if you now have a "Archlinux snapshots" menu (or something named closely to that).
If you do, boot on one ! For example, the one taken pre-pacman install of micro ? You'll see some weird messages but it should boot as usual.
Log in, open btrfs-assistant, go to the "Browse/Restore" tab. It should list the snapshots, and offer to restore to @ (the root subvolume).
Choose a snapshot (the one you booted in, for example, pre pacman install of micro), and restore that. It will tell you to immediately reboot, please do so.
Reboot on the normal "Archlinux" entry in Grub.
Once you're logged in, open a terminal and type findmnt /
. Check the output. You should see /dev/<thedeviceyouuse>[/@] btrfs
/@ indicates we're back on the @ subvolume (your "real" root, the subvolume we're taking snapshots of).
Now, try to use micro, the command should be not found (as we restored to the snapshot of @/root taken before it was installed).
Finally, one last thing to do, if you restored to a snapshot taken "pre" pacman install, the pacman database will still be locked in your freshly restored system.
So, try to install a package (micro again ?). Check the locked db path pacman is showing you.
Then rm that !
That was a lot of steps, but if all that went well, you can actually do the rest of your system prep for your regular tasks, cause snapshots are working and can be restored correctly in case of an issue.