Snapper and grub-btrfs in Arch Linux

Up to now, I’ve been using Timeshift and grub-btrfs in my Linux installations because I found Timeshift easy to use and straightforward to install. I was scared by Snapper because I thought it was hard to use and complex to install. I had been fooled by many tutorials I found online, but maybe they were obsolete, or they were not using the right packages. I was wrong: using the right packages provided in Arch and AUR repositories makes it straightforward to use Snapper and grub-btrfs. You also get a program that automatically takes a snapshot when installing/updating your system.

This is more of a report than a tutorial.

I tried this procedure on EndeavourOS and Arch, and, as expected, the final result was the same. However, as shown later, Arch requires a few adjustments in the /etc/fstab file.

The BTRFS subvolume layout of EndeavourOS is ideal for snapper snapshots and for booting them with grub: the subvolume “@” for “/”, “@home” for “/home”, and separate subvolumes for “/var/log” and “/var/cache”. That’s basically the same as I use for Arch installations.

If you already have grub-btrfs because you use it with Timeshift (e.g., with the procedure described in one of my previous posts), it’s better to remove the package so that it will also remove possible enabled services and the custom configurations for timeshift:

If you were using Timeshift, you also provided a custom configuration for grub-btrfsd, which is not automatically removed during the previous command. The files must be removed explicitly:

Also, remove timeshift and timeshift-autosnap

If you don’t do that now, you will be asked to do that when installing the packages for snapper anyway.

If you installed Arch the Arch way, when generating /etc/fstab, the command has added “subvolid=…” entries in /etc/fstab, which will disturb when restoring snapper snapshots. For example, if you tried to restore a snapshot with btrfs-assistant (which we’ll install in a minute), you’ll get such a warning dialog:

Since the generated /etc/fstab contains both “subvolid=…” and “subvol=…”, I find it safe to remove the “subvolid” parts. I do that with this sed command (of course, do that at your own risk and take a backup of the file first):

If you installed another Arch-based distro, like EndeavourOS, the /etc/fstab should already contain only “subvol=…” entries, so the above command is not required.

Install the following two packages with an AUR helper (e.g., “yay” in my case). The first one is a meta-package that will install snapper and other utilities like “snap-pac” (“Pacman hooks that use snapper to create pre/post btrfs snapshots when installing/upgrading/removing packages”) and “grub-btrfs” (the default configuration of grub-btrfs works already with snapshots created by snapper).

If you haven’t previously uninstalled timeshift and timeshift-autosnap, you’ll get this message, as I mentioned above:

During the installation of the above two packages, we can see a few interesting things in the log:

The installation creates a configuration for snapper for the root subvolume and configures the service to automatically update the grub menu for booting snapshots. It also creates the very first snapshot, “1”. Since we then install btrfs-assistant, it also creates a “pre” snapshot, “2”, and when the installation of btrfs-assistant finishes, it creates a “post” snapshot, “3”.

Let’s run btrfs-assistant:

Let’s explore its tabs:

Note the existing subvolumes and the newly created subvolume for snapshots “.snapshots”.

The next tab shows the snapshots taken during the installation command we issued to install the programs. Note the numbers of the snapshots and compare them with the installation log shown above. Moreounlike from “timeshift-autosnap”, “snap-pac” creates meaningful and comprehensible names for the snapshots.

Note that you act on a single configuration in this and in the next tab. By default, we have the one created during the installation for the root subvolume (see the “Select config” drop-down menu). If you have other configurations (e.g., for snapshots of the home subvolume), you must select the intended configuration.

With the first tab, you can create/delete snapshots. With the second tab, you can browse them or restore them:

On the last tab, you can see the enabled services and possibly perform further configuration. For the moment, I’m not touching that part: I’m OK without automatic snapshots (since I know they will be taken when installing/upgrading/removing commands) and with the automatic cleanup of old snapshots:

From btrfs-assistant, you can also select the checkbox to show existing Timeshift snapshots:

You might want to remove them once you’re sure the new setup with snapper and grub-btrfs works correctly.

Let’s do some experiments browsing the current snapshots. For example, let’s select the second one and click “Browse”:

Navigating to “/usr/bin,” we can verify that “btrfs-assistant” is not there. In fact, snapshot “2” was taken before installing btrfs-assistant.

Let’s browse snapshot “3”:

This time, “btrfs-assistant” is present in “/usr/bin”. In fact, snapshot “3” was taken after the installation of btrfs-assistant (it’s a “post” snapshot).

From the screenshots above, we can see that snapshots are also browsable from the file system: they are all inside “/.snapshots” (for the root subvolume configuration), each one with the corresponding number. You must be root to browse them.

Let’s experiment with booting snapshots from grub.

Before installing snapper and the other programs, I had previously installed “neofetch” on this machine. I’m going to remove it:

Two new snapshots have been automatically created by “snap-pac” (one before the removal and one afterward):

Let’s reboot the machine and navigate through the snapshots menus, selecting the snapshot corresponding to the state before the removal of neofetch:

Now, we’re inside that snapshot, and we can verify that neofetch is still there:

Let’s say that we want to restore this snapshot for good. Let’s run btrfs-assistant, select the snapshot we have just booted, and press “Restore”:

We get a confirmation dialog, and we can specify a name for the backup that will be taken (in this example, I’ll specify “before-restoring”):

Upon confirmation, we get a warning that urges us to reboot as soon as possible:

Let’s reboot. This time we select the default grub menu entry (not a snapshot).

We can verify once again that neofetch is still there.

From btrfs-assistant, we can see the subvolume with the backup, which we can delete once we’re sure that everything is still working:

If you are using “plocate” or “locate” (see also my older post about locate and BTRFS), you should also exclude “.snapshots” to “PRUNENAMES” (this should already contain some directories like “.git .hg .svn”:

And add “.snapshots” to “PRUNENAMES”, e.g.,

Configuration files are in the directory “/etc/snapper/configs/“. Currently, we have only one configuration, “root” (for the root subvolume), created during the installation.

In that file, we can see the line

corresponding to the setting in btrfs-assistant that disables the automatic timeline snapshots.

Moreover, we have the following:

which again corresponds to the setting in the btrfs-assistant screenshot shown above.

For further configurations, I suggest looking at Snapper’s great Arch wiki page.

To summarize, snapper with these additional programs looks nice and is more flexible than Timeshift and timeshift-autosnap.

You might want to give it a try! As usual, you might start with a virtual machine 😉

12 thoughts on “Snapper and grub-btrfs in Arch Linux

  1. CGA

    Excellent write up, makes me wanting to try to replace Timeshift with Snapper again. Didn’t work out that well last time but I can see now what errors I made.

    Reply
    1. Lorenzo Bettini Post author

      Glad you enjoyed it!
      I suggest you try Snapper again on a virtual machine. It works like a charm, thanks to the snapper-support package.

      Reply
    2. jupiter

      Thank you, a very clear and well-documented explanation, i don’t use timeshift (and never did), i do use snapper and btrfs-assistant for snapshots, and its good to get some extra insights, i did install grub-btrfs when i installed arch, and it is still there, no conflicts or problems whatsoever, i am unsure on why you start with uninstalling it, but i am pretty sure you probably have a good reason, anyway, thank you!

      Reply
      1. Lorenzo Bettini Post author

        Hi
        If I remember correctly, I had to first uninstall grub-btrfs because I had configured that for timeshift. Removing that was the easiest thing.
        Of course, when using snapper and btrfs-assistant I also re-installed grub-btrfs.

        Reply
  2. T. V. Sivaraman

    Excellent, I followed your steps and the Snapper is working great in my Manjaro installation.
    Thank you very much.

    Reply
  3. brian mullan

    I am new to Snapper, Snapper-gui, btrfs-assistant, apt install snapshot support etc.

    [I know this article is Arch oriented but I assume this same question applies]

    On my ubuntu 22.04 system when I do:

    $ sudo apt install some_app

    btrfs-assistant as expected shows:
    – pre snapshot
    – timeline snapshot
    – post snapshot

    But all of the Snapshot “Description” fields are blank and require me to enter a description manually?

    Is there not a way to have the “Description” field auto-populated when using installation tools like “pacman” or “apt install”?

    For instance auto-populate Description with the “pacman” or “apt install” command that was executed or something similar to give you a Clue later when you go back to btrfs-assistant as to what the pre/post/timeline snapshots were for?

    Thanks for any info.
    Brian

    Reply
    1. Lorenzo Bettini Post author

      Maybe you’re referring to automatic snapshot when you install/update packages? For that you need something similar to snap-pac but for apt, if it exists.

      Reply
  4. Erich Carter

    Hi-
    Using an Arch-derivitive here (ezarcher which is really close to Arch). My question/issue is that on the initial install I did not receive 3 snapshots but raher only 1 at the end of the installation with the description stating it was a single type and the description stating “btrfs-assistant grub btrfs snap-pac snapper snapper-support. Is this now normal? The backup and restore worked flawlwssly (before I forget the FSTAB showed the same setup you recommended and I never installled timeshift).

    Reply
  5. Robin Hood

    Thanks it was helpful. It would be great if you add boot recovery tutorial as well. I tried old snapshots but got a read write error, even the ro=false command didn’t make any difference. Anyway, I’m probably making a basic mistake and I’ll figure that out later.

    Reply
    1. Lorenzo Bettini Post author

      That’s strange: you should be able to seamlessly boot into a snapshot (and then immediately restore it). I’ve never had such a problem.
      Concerning boot recovery I wouldn’t know…

      Reply

Leave a Reply to Lorenzo BettiniCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.