Snapper btrfs snapshots on Gentoo, need pointers

I’m learning to use Snapper with my btrfs to make snapshots of my root. Snapper is used in openSUSE and available to other linux oses too. My system is Gentoo and I’ve followed the wiki
and got it working. At the moment it makes a new snapshot everytime I update my system.
here’s the status of my system before I did first update after followed the wiki:

$ snapper list
# │ Type   │ Pre # │ Date                             │ User │ Cleanup │ Description │ Userdata
──┼────────┼───────┼──────────────────────────────────┼──────┼─────────┼─────────────┼─────────
0 │ single │       │                                  │ root │         │ current     │
1 │ single │       │ Thu 10 Oct 2024 08:59:47 PM EEST │ pete │         │             │

then after sync&update (there was 7 packages to update)

$ snapper list
 # │ Type   │ Pre # │ Date                             │ User │ Cleanup │ Description                                                                   │ Userdata
───┼────────┼───────┼──────────────────────────────────┼──────┼─────────┼───────────────────────────────────────────────────────────────────────────────┼─────────
 0 │ single │       │                                  │ root │         │ current                                                                       │
 1 │ single │       │ Thu 10 Oct 2024 08:59:47 PM EEST │ pete │         │                                                                               │
 2 │ pre    │       │ Fri 11 Oct 2024 10:34:15 AM EEST │ root │ number  │ Upgrading to dev-lang/spidermonkey-115.16.0 replacing version(s) 115.15.0     │
 3 │ post   │     2 │ Fri 11 Oct 2024 10:34:18 AM EEST │ root │ number  │ Upgrading to dev-lang/spidermonkey-115.16.0 replacing version(s) 115.15.0     │
 4 │ pre    │       │ Fri 11 Oct 2024 10:34:29 AM EEST │ root │ number  │ Upgrading to dev-libs/ell-0.69 replacing version(s) 0.66                      │
 5 │ post   │     4 │ Fri 11 Oct 2024 10:34:32 AM EEST │ root │ number  │ Upgrading to dev-libs/ell-0.69 replacing version(s) 0.66                      │
 6 │ pre    │       │ Fri 11 Oct 2024 10:34:34 AM EEST │ root │ number  │ Upgrading to net-libs/libpsl-0.21.5 replacing version(s) 0.21.5               │
 7 │ post   │     6 │ Fri 11 Oct 2024 10:34:37 AM EEST │ root │ number  │ Upgrading to net-libs/libpsl-0.21.5 replacing version(s) 0.21.5               │
 8 │ pre    │       │ Fri 11 Oct 2024 10:35:03 AM EEST │ root │ number  │ Upgrading to net-firewall/ufw-0.36.1-r1 replacing version(s) 0.36.1           │
 9 │ post   │     8 │ Fri 11 Oct 2024 10:35:10 AM EEST │ root │ number  │ Upgrading to net-firewall/ufw-0.36.1-r1 replacing version(s) 0.36.1           │
10 │ pre    │       │ Fri 11 Oct 2024 10:35:48 AM EEST │ root │ number  │ Upgrading to www-client/firefox-bin-131.0.2 replacing version(s) 131.0        │
11 │ post   │    10 │ Fri 11 Oct 2024 10:35:52 AM EEST │ root │ number  │ Upgrading to www-client/firefox-bin-131.0.2 replacing version(s) 131.0        │
12 │ pre    │       │ Fri 11 Oct 2024 10:36:13 AM EEST │ root │ number  │ Upgrading to mail-client/thunderbird-bin-128.3.1 replacing version(s) 128.3.0 │
13 │ post   │    12 │ Fri 11 Oct 2024 10:36:17 AM EEST │ root │ number  │ Upgrading to mail-client/thunderbird-bin-128.3.1 replacing version(s) 128.3.0 │
14 │ pre    │       │ Fri 11 Oct 2024 10:36:29 AM EEST │ root │ number  │ Upgrading to app-portage/emlop-0.7.0 replacing version(s) 0.6.1               │
15 │ post   │    14 │ Fri 11 Oct 2024 10:36:32 AM EEST │ root │ number  │ Upgrading to app-portage/emlop-0.7.0 replacing version(s) 0.6.1  

I think this is a bit too much to have a pre and post snapshot of every updated package. Optimal would be one snapshot before update and one snapshot after update of all packages.

Maybe I remove the /etc/portage/bashrc script (seen in the wiki link) for now and just make a scheduled snapshot for now.

This snapper thing is very cool but I need to read more about it… Do you have any tips / tricks?

Have you tried recovering fronm a snapshot? You need to know recovery will work.

1 Like

You’re right. Although I don’t think snapper is enough for backup. I think it as a quick recovery option and still take real backups to cloud and USB.

I’m still just starting to understand it. Now reading the openSUSE manual:

Right… like Timeshift, only hopefully without making assumptions and doing things behind your back.

2 Likes

a quick update: I installed app-backup/grub-btrfs and now I can boot from grub to a snapshot. GitHub - Antynea/grub-btrfs: Include btrfs snapshots at boot options. (Grub menu)

I can boot from grub menu to my snapshots.

That is neat.
I suppose a snapshot is a .img file? If that is the case , what grub would do is loop mount the snapshot file, so it looks like a device.

1 Like

it’s just a full snapshot of my root and there is also the /boot/ in the snapshot. It’s not read-only, I’ve chown -R /.snapshots

here’s the latest snapshot of my /boot:

ls -al /.snapshots/27/snapshot/boot/
total 388544
drwxr-xr-x 1 root root      990 Oct  4 07:43 .
drwxr-xr-x 1 root root      302 Oct 11 10:15 ..
-rw-r--r-- 1 root root        0 Jun 16 14:28 .keep
-rw-r--r-- 1 root root  9475938 Jun 17 13:00 System.map-6.6.32-gentoo-dist
-rwxr-xr-x 1 root root  9411543 Aug 22 18:01 System.map-6.6.47-gentoo-dist
-rw-r--r-- 1 root root  9413378 Oct  4 07:39 System.map-6.6.51-gentoo-dist
-rw-r--r-- 1 root root  9413378 Sep 27 10:54 System.map-6.6.51-gentoo-dist.old
-rw-r--r-- 1 root root    77312 Sep 22 16:45 amd-uc.img
-rw-r--r-- 1 root root   266734 Jun 17 13:00 config-6.6.32-gentoo-dist
-rwxr-xr-x 1 root root   266812 Aug 22 18:01 config-6.6.47-gentoo-dist
-rw-r--r-- 1 root root   266814 Oct  4 07:39 config-6.6.51-gentoo-dist
-rw-r--r-- 1 root root   266814 Sep 27 10:54 config-6.6.51-gentoo-dist.old
drwxr-xr-x 1 root root      102 Oct  7 17:09 grub
-rw-r--r-- 1 root root 77038809 Jun 17 14:07 initramfs-6.6.32-gentoo-dist.img
-rwxr-xr-x 1 root root 66414539 Aug 22 18:01 initramfs-6.6.47-gentoo-dist.img
-rw-r--r-- 1 root root 68048193 Oct  4 07:39 initramfs-6.6.51-gentoo-dist.img
-rw-r--r-- 1 root root 67924532 Sep 27 10:54 initramfs-6.6.51-gentoo-dist.img.old
-rw-r--r-- 1 root root 16665600 Oct  4 07:43 intel-uc.img
-rw-r--r-- 1 root root 15723504 Jun 17 13:00 vmlinuz-6.6.32-gentoo-dist
-rwxr-xr-x 1 root root 15707120 Aug 22 18:02 vmlinuz-6.6.47-gentoo-dist
-rw-r--r-- 1 root root 15715312 Oct  4 07:39 vmlinuz-6.6.51-gentoo-dist
-rw-r--r-- 1 root root 15715312 Sep 27 10:54 vmlinuz-6.6.51-gentoo-dist.old

The difference is in /boot/grub as in the snapshot there is no grub-btrfs.cfg file.

pete@gentoo ~ $ ls /boot/grub/
fonts  grub-btrfs.cfg  grub.cfg  grub.cfg~  grubenv  locale  themes  x86_64-efi
pete@gentoo ~ $ ls /.snapshots/27/snapshot/boot/grub/
fonts  grub.cfg  grub.cfg~  grubenv  locale  themes  x86_64-efi

So the boot process uses /boot/grub and there is grub-brtfs.cfg which adds a boot menu item “Gentoo” where it lists all snapshots. I can choose at boot to continue normally, use Debian(dual boot) or go to the snapshot menu. The GitHub link I posted earlier has more info.

Oh, so it is like an rsync copy.
I guess grub can boot that quite easily… it is the same as an installed OS as far as grub is concerned.

Sorry, but I like to understand how grub does things.

1 Like

me too :smiley:
here’s the start of the 41_snapshots-btrfs:

cat /etc/grub.d/41_snapshots-btrfs
#! /usr/bin/env bash
#
# Written by: Antynea
# BTC donation address: 1Lbvz244WA8xbpHek9W2Y12cakM6rDe5Rt
# Github: https://github.com/Antynea/grub-btrfs
#
# Purpose:
#   Improves Grub by adding "btrfs snapshots" to the Grub menu.
#   You can boot your system on a "snapshot" from the Grub menu.
#   Supports manual snapshots, snapper, timeshift ...
#   Warning : booting on read-only snapshots can be tricky.
#   (Read about it, https://github.com/Antynea/grub-btrfs#warning-booting-on-read-only-snapshots-can-be-tricky)
#
# What this script does:
# - Automatically List snapshots existing on root partition (btrfs).
# - Automatically Detect if "/boot" is in separate partition.
# - Automatically Detect kernel, initramfs and intel/amd microcode in "/boot" directory on snapshots.
# - Automatically Create corresponding "menuentry" in grub.cfg.
# - Automatically detect the type/tags and descriptions/comments of snapper/timeshift snapshots.
# - Automatically generate grub.cfg if you use the provided systemd service.
#
# Installation:
# - Refer to https://github.com/Antynea/grub-btrfs#%EF%B8%8F-installation
#
# Customization:
#  You have the possibility to modify many parameters in /etc/default/grub-btrfs/config.
#  Read more here https://github.com/Antynea/grub-btrfs#installation- an in the manpage
#  'man grub-btrfs'
#
# Automatically update Grub
#  If you would like grub-btrfs menu to automatically update when a snapshot is created or deleted:
#  - Refer to https://github.com/Antynea/grub-btrfs#-automatically-update-grub-upon-snapshot.
#
# Special thanks for assistance and contributions:
# - My friends
# - All contributors on Github
#

OK, I get it, it makes a custom entry in grub.d

2 Likes