I wanted to recover a btrfs snapshot. I eventually made it but I encountered a few hiccups.

First of all, given the subvolume scheme I chose, I shouldn’t rely on snapper rollback, explanation here.

Instead, I have to boot from the Arch live USB

loadkeys it
cryptsetup open /dev/sda2 cryptroot
mount -o subvolid=5 /dev/mapper/cryptroot /mnt
cat /mnt/@snapshots/NUMBER/info.xml
mv /mnt/@ /mnt/@broken
btrfs subvol snapshot /mnt/@snapshots/NUMBER/snapshot /mnt/@

Here’s a brief explanation. First I unlock the encrypted partition containing the root partition, then mount it to /mnt using the root subvolume of btrfs, which always has id=5. Inside /mnt I’ll find the various subvolumes, which I named using the @ prefix for easier recognition. I rename the root subvolume @ to @broken, then proceed to create a new subvolume for the root partition, with name @ and read/write permissions, by using a snapshot. I can look for the correct snapshot by peeking at xml files.

Actually, I already knew the correct snapshot thanks to snapper-gui, but I double checked just to be sure.

At this point the @broken subvolume can be removed.

Booting now causes some problems mostly because I run snapper rollback previously, which I shouldn’t use considering the subvolume scheme. Don’t quote me on this, but I think that snapper rollback modifies /etc/fstab by setting the subvolumeid option for each subvolume. Simply edit fstab to the normal version, i.e something like this

/dev/mapper/cryptroot / btrfs rw,relatime,compress=lzo,discard,ssd,space_cache,subvol=@     0 0
/dev/mapper/cryptroot /home btrfs rw,relatime,discard,compress=lzo,ssd,space_cache,subvol=@home 0 0
/dev/mapper/cryptroot /.snapshots btrfs rw,relatime,compress=lzo,discard,ssd,space_cache,subvol=@snapshots    0 0
/dev/sda1 /boot/  vfat rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro  0 2

I also need to reset the default subvolume for root:

btrfs subvolume get-default /mnt
btrfs subvolume set-default SUBVOLID /mnt

The subvolume id can be obtained by btrfs subvolume list /mnt.

As the last problem, the boot stops quickly due to a kernel mismatch between the modules present in the root filesystem and the kernel booted from the sda1 EFI partition. All I need is arch-chroot

loadkeys it
cryptsetup open /dev/sda2 cryptroot
mount /dev/mapper/cryptroot /mnt
mount /dev/sda1 /mnt/boot
arch-chroot /mnt
pacman -U /var/cache/pacman/pkg/linux-VERSION

As an alternative, I could configure the internet connection and download the last linux kernel.


Comments

comments powered by Disqus