Grub2 with Opensuse snapper helper PATCH

Hi, i have been using Opensuse for last five years, above all, for the out-of-the-box btrfs and snapper configuration. Now i'm on Manjaro, traing to replicate the Suse btrfs+snapper functionality, but I needed GRUB to respect the default subvolume that is set on the BTRFS filesystem so i can use snapper rollback . I found these patches from Opensuse grub2 source package:

grub2-btrfs-01-add-ability-to-boot-from-subvolumes.patch
grub2-btrfs-02-export-subvolume-envvars.patch
grub2-btrfs-03-follow_default.patch
grub2-btrfs-04-grub2-install.patch
grub2-btrfs-05-grub2-mkconfig.patch

but i don't know how-to apply and build my patched grub2, can be applied on upstream grub package?

Thanks for your great job, and sorry for my bad, bad english.

Ste

double posting:

So in a different topic we found the solution in the Arch Wiki

Now the question is: Is there any interest among the developers to further automate the restore from snapshot functionality in Manjaro?

I found a little partial workaround, editing /etc/grub.d/10_linux, i remove line from 67 to 79:

case x"$GRUB_FS" in
    xbtrfs)
	rootsubvol="`make_system_path_relative_to_its_root /`"
	rootsubvol="${rootsubvol#/}"
	if [ "x${rootsubvol}" != x ]; then
	    GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
	fi;;
    xzfs)
	rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true`
	bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`"
	LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs%/}"
	;;
esac

Now grub2 follow the btrfs get-default variable, but with two limits:

  1. Now there are two Manjaro grub entry, the first with no rootflag which follow btrfs get-default variable, (by grub.d/10_linux) and a second Manjaro entry at default @/ (by grub.d/30_os-prober)
  2. Until the next update-grub vmlinuz and initramfs are loaded from @/ and not from btrfs get-default variable
1 Like

As always, the easy way is better. Now i can restore my system with 2 commands without fighting with grub patches only for snapper rollback ability.

First my fstab:

UUID=A177-C4C8                            /boot/efi      vfat    umask=0077 0 2
UUID=965a21e4-f1d4-4682-b5c1-ca969ac58c9b swap           swap    defaults,noatime,discard 0 2
UUID=09c87d93-2927-4500-9c83-2e8619542e1e /              btrfs   subvol=@,defaults,noatime,space_cache,autodefrag,ssd_spread,compress=zstd  0 1
UUID=09c87d93-2927-4500-9c83-2e8619542e1e /var           btrfs   subvol=@var,defaults,noatime,space_cache,autodefrag,ssd_spread,compress=zstd  0 1
UUID=09c87d93-2927-4500-9c83-2e8619542e1e /home          btrfs   subvol=@home,defaults,noatime,space_cache,autodefrag,discard,compress=zstd  0 2
UUID=09c87d93-2927-4500-9c83-2e8619542e1e /.snapshots    btrfs   subvol=@snapshots,defaults,noatime,space_cache,autodefrag,ssd_spread,compress=zstd  0 1
UUID=09c87d93-2927-4500-9c83-2e8619542e1e /master        btrfs   subvolid=0,defaults,noatime,space_cache,autodefrag,ssd_spread,compress=zstd  0 1
tmpfs                                     /tmp           tmpfs   defaults,noatime,mode=1777 0 0

Now i have /var in a separate subvolume, with cow disable (so it always mount r/w if i boot from a subvolume, and in this way i can boot read-only snapshot) and a /master folder with the master btrfs id 0.
If something goes wrong, i can boot (with btrfs-grub) in last working snapshot, and move @ to a bad@ (just for diff)

 sudo mv /master/@ /master/@bad

Create a snapshot of current (xxx) booted one to @

 sudo btrfs subvolume snapshot /master/@snapshots/xxx/snapshot  /master/@

Where xxx is the number of the snapper snapshot i wish to restore.
On reboot i have a working system. So i can restore my system by arch itself, instead booting into a live Arch Linux USB/CD. (what I wanted from the beginning)

Thanks to all!!

1 Like

Forum kindly sponsored by