If you are using snapper
Snapper assumes complete control over what is the active root, via btrfs subvolume set-default
.
You will need to remove the And also modify subvol=root
option from fstab./etc/default/grub
adding the line:
SUSE_BTRFS_SNAPSHOT_BOOTING=true
And then run grub2-mkconfig -o /boot/...
filling out the rest of the path based on the location to grub.cfg for your firmware type.
Hmmm, when I do this, it does work but there’s an unwanted $(extra_cmdline)
item at the end of the boot parameters. I’m not sure where it’s coming from.
/etc/grub.d/00_header:383:if [ -n "\$extra_cmdline" ]; then
/etc/grub.d/10_linux:70: GRUB_CMDLINE_LINUX="${GRUB_CMDLINE_LINUX} \${extra_cmdline}"
/etc/grub.d/20_linux_xen:77: GRUB_CMDLINE_LINUX="${GRUB_CMDLINE_LINUX} \${extra_cmdline}"
OK it’s related to finding read-only snapshots. I think. None of that is wired up with BootLoaderSpec stuff yet. Also, while booting read-only snapshots works up to a point, because /etc and /var are in the read-only root subvolume snapshot, they’re read-only too which will cause startup to fail.
So doing a rollback on boot is not exactly ready, you’re pretty much in adventure land if you’re playing with this (which is why none of it’s installed or enabled by default yet).
If you can boot, snapper rollback should work since it’ll just change the default subvolume.
If you aren’t using snapper
I’ll describe what I do since I’m also not using snapper. I assume that you haven’t modified fstab or any of the grub stuff and that you haven’t changed the default subvolume.
Mount the top level of the file system, make a read-only snap shot
mount /dev/sdXY /mnt
cd /mnt
btrfs sub snap -r root root.20201224
I make read-only snapshots out of habit, mostly. Ok let’s say I mess up something and want to do a rollback.
mount /dev/sdXY /mnt
cd /mnt
mv root rootmessedup
btrfs sub snap root.20201224 root
reboot
In this case I’m renaming the current root subvolume to something descriptive. Renaming it while it’s in use is not a problem (I do it all the time; and behind the scenes, btrfs tracks subvolumes by ID not name). Next I make a read-write snapshot of the snapshot I want to rollback to. And then reboot.
An optimization probably is to remove subvol=root
from fstab, that way you could instead directly choose to rollback to read-write snapshots from within GRUB if you know the name. Just change rootflags=subvol=root
to rootflags=subvol=root.20201224
. Of course, you’d need to be making read-write snapshots in this case.
The reason I prefer snapshots “hidden” away in the normally not mounted top-level, is so they don’t clutter up other commands like find, du, backup programs, and so on. Also there is a (perhaps small) security concern with keeping stale binaries in a readily available search path, even if it is a hidden .directory. So I just prefer to keep them totally out of site.