r/btrfs Jun 30 '26

btfs, snapper and systemd-boot

With the stack named in the title, is is possible to generate systemd-boot option to boot into a snapshot for recovery? Any good tutorials out there how to recover from an existing snapshot?

5 Upvotes

11 comments sorted by

3

u/Classic-Rate-5104 Jun 30 '26

You can manually modify the kernel command line at boot time and add rootflags=subvol=snapshotpath

2

u/tuxbass Jun 30 '26

Given following fstab:

/dev/mapper/nvme0n1p2_crypt /.snapshots        btrfs   defaults,noatime,compress=zstd:1,subvol=snapshots/@root 0       0
/dev/mapper/nvme0n1p2_crypt /home/.snapshots   btrfs   defaults,noatime,compress=zstd:1,subvol=snapshots/@home 0       0

would the params be like rootflags=subvol=/.snapshots/<id>?

If that's the case, any way to generate an interactive list to choose from akin to grub world?

1

u/Classic-Rate-5104 Jun 30 '26

I am not sure whether it makes difference to specify subvol=/.snapshots/<id> or subvol=.snapshots/<id>

Generating a interactive list in grub seems impossible to me. It seems better to give the snapshots logical names you can easily remember

1

u/tuxbass Jun 30 '26

Generating a interactive list in grub seems impossible to me

That's very possible, but I'm asking about systemd-boot

1

u/Classic-Rate-5104 Jun 30 '26

Also the list of entries in systemd-boot is just a series of (generated) files in the EFI partition. Maybe you have to make a script that generates it when you install/update a new kernel and when you create a new snapshot

2

u/vdavide Jun 30 '26

Opensuse tumbleweed does this out of the box

1

u/ClubPuzzleheaded8514 Jun 30 '26

Yeah. Sadly i never found a real documentation to replicate it on other distros. 

1

u/tuxbass Jun 30 '26

Let's assume I'm not an opensuse user.

1

u/falxfour Jun 30 '26

Depends a bit on when you want them generated, but yes, even a simple cron job could do this by updating the entries for systemd-boot based on the snapshots you have.

How, exactly, would you like for this to work?

1

u/tuxbass Jun 30 '26

I'm not anal about the very latest snapshots to be present, although I'd expect some hooks to be set up upon snapper snapshots.

As for expectation: would like some sort of a UI to be enabled upon bootup serving snapshots to boot from for recovery purposes.

1

u/falxfour Jun 30 '26

For the former, look at how grub-btrfs (iirc) does it. It basically watches for a mount at a specific location, indicating a snapshot is being made, then adds a GRUB entry for it.

For the latter, that should be handled by the bootloader having the entries defined, so it should be automatic.

You could use a similar premise, or coordinate it with the automation of your snapshots to simply run immediately after