Skip to content

Instantly share code, notes, and snippets.

@akhilman
Last active August 16, 2024 05:09
Show Gist options
  • Save akhilman/bfbfe6a9cd14669ab921e890560e1240 to your computer and use it in GitHub Desktop.
Save akhilman/bfbfe6a9cd14669ab921e890560e1240 to your computer and use it in GitHub Desktop.
Fix Arch Linux'es snapper for easy rollbacks

Snapper's rollbacks work fine in Arch after a few tweaks:

  1. Install snapper, grub-btrfs, snap-pac;
  2. Enable grub-btrfsd.service;
  3. Add the hook grub-btrfs-overlayfs at the end of HOOKS in /etc/mkinitcpio.conf;
  4. Remove the subvol=... option from root's fstab entry;
  5. Remove code that adds rootflags=subvol=... from /etc/grub.d/10_linux;
  6. Rebuild the grub configuration with sudo grub-mkconfig -o /boot/grub/grub.cfg;
  7. Take a snapshot with snapper create;
  8. Rollback to the just created snapshot with snapper --ambit classic rollback <id>;
  9. Reboot.

Snapper will no longer require an `--ambit'.

Here is how I changed my /etc/grub.d/10_linux to handle both Arch and Snapper rollbacks:

--- 10_linux.bak	2024-03-17 02:09:18.000000000 +0700
+++ 10_linux	2024-08-15 17:27:50.336843993 +0700
@@ -69,7 +69,8 @@
     xbtrfs)
 	rootsubvol="`make_system_path_relative_to_its_root /`"
 	rootsubvol="${rootsubvol#/}"
-	if [ "x${rootsubvol}" != x ]; then
+	# Use default subvolume in case of snapper's rollback is used
+	if [ "x${rootsubvol}" != x ] && [ "x$(btrfs subvolume get-default / | cut -d' ' -f2)" == x5 ]; then
 	    GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
 	fi;;
     xzfs)

Pacman hook to backup kernels and modules /etc/pacman.d/hooks/zx-kernel-backup.hook:

[Trigger]
Operation = Upgrade
Operation = Install
Operation = Remove
Type = Path
Target = usr/lib/modules/*/vmlinuz

[Action]
Depends = rsync
Description = Backing up /boot and /lib/modules...
When = PostTransaction
Exec = /usr/bin/rsync -a -u --delete --exclude=.old /boot /usr/lib/modules /.kernel_backup/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment