SystemD boot + secure boot + TPM2 unlocking + UKI + Dual boot (windows) + Dracut + BTRFS + LUKS2 + boot from Snapshots

The script takes a snapshot and I’ve to use a larger boot partition. When the snapshot is taken, the recent kernel.img, etc. gets copied, renamed and the script changes the /etc/fstab inside the snapshot and changes the loader entries to reflect the date of the snapshot taken.

Well guess it’s a lot of tinkering :smiley:

If you just want to have it running, grub would be the better choice.

DISCLAIMER: You should understand the Script, and perhaps you have to modify it to fit your needs, to make it work on your system. Don‘t use it blindly, Grub + btrfs is the easier and perhaps better alternative.


# Create btrfs snapshot in .snapshots/STABLE and move kernel,ramfs to bootloader
# triggered by 00-autosnap.hook for pacman


# Move snapshot 4 to Position 5
$BTRFS sub delete /.snapshots/STABLE5
$BTRFS sub snap /.snapshots/STABLE4 /.snapshots/STABLE5

$SED -i 's|subvol=@snapshots/STABLE4\t|subvol=@snapshots/STABLE5 |' /.snapshots/STABLE5/etc/fstab
$SED -i 's|subvol=@snapshots/STABLE4 |subvol=@snapshots/STABLE5 |' /.snapshots/STABLE5/etc/fstab

$MV /boot/vmlinuz-linux-stable4 /boot/vmlinuz-linux-stable5
$MV /boot/amd-ucode-stable4.img /boot/amd-ucode-stable5.img
$MV /boot/initramfs-linux-stable4.img /boot/initramfs-linux-stable5.img

$CP /boot/loader/entries/stable4.conf /boot/loader/entries/stable5.conf
$SED -i 's|stable4|stable5|' /boot/loader/entries/stable5.conf
$SED -i 's|STABLE4|STABLE5|' /boot/loader/entries/stable5.conf

# Move snapshot 3 to Position 4
$BTRFS sub delete /.snapshots/STABLE4
$BTRFS sub snap /.snapshots/STABLE3 /.snapshots/STABLE4

$SED -i 's|subvol=@snapshots/STABLE3\t|subvol=@snapshots/STABLE4 |' /.snapshots/STABLE4/etc/fstab
$SED -i 's|subvol=@snapshots/STABLE3 |subvol=@snapshots/STABLE4 |' /.snapshots/STABLE4/etc/fstab

$MV /boot/vmlinuz-linux-stable3 /boot/vmlinuz-linux-stable4
$MV /boot/amd-ucode-stable3.img /boot/amd-ucode-stable4.img
$MV /boot/initramfs-linux-stable3.img /boot/initramfs-linux-stable4.img

$CP /boot/loader/entries/stable3.conf /boot/loader/entries/stable4.conf
$SED -i 's|stable3|stable4|' /boot/loader/entries/stable4.conf
$SED -i 's|STABLE3|STABLE4|' /boot/loader/entries/stable4.conf

# Move snapshot 2 to Position 3
$BTRFS sub delete /.snapshots/STABLE3
$BTRFS sub snap /.snapshots/STABLE2 /.snapshots/STABLE3

$SED -i 's|subvol=@snapshots/STABLE2\t|subvol=@snapshots/STABLE3 |' /.snapshots/STABLE3/etc/fstab
$SED -i 's|subvol=@snapshots/STABLE2 |subvol=@snapshots/STABLE3 |' /.snapshots/STABLE3/etc/fstab

$MV /boot/vmlinuz-linux-stable2 /boot/vmlinuz-linux-stable3
$MV /boot/amd-ucode-stable2.img /boot/amd-ucode-stable3.img
$MV /boot/initramfs-linux-stable2.img /boot/initramfs-linux-stable3.img

$CP /boot/loader/entries/stable2.conf /boot/loader/entries/stable3.conf
$SED -i 's|stable2|stable3|' /boot/loader/entries/stable3.conf
$SED -i 's|STABLE2|STABLE3|' /boot/loader/entries/stable3.conf

# Move snapshot 1 to Position 2
$BTRFS sub delete /.snapshots/STABLE2
$BTRFS sub snap /.snapshots/STABLE1 /.snapshots/STABLE2

$SED -i 's|subvol=@snapshots/STABLE1\t|subvol=@snapshots/STABLE2 |' /.snapshots/STABLE2/etc/fstab
$SED -i 's|subvol=@snapshots/STABLE1 |subvol=@snapshots/STABLE2 |' /.snapshots/STABLE2/etc/fstab

$MV /boot/vmlinuz-linux-stable1 /boot/vmlinuz-linux-stable2
$MV /boot/amd-ucode-stable1.img /boot/amd-ucode-stable2.img
$MV /boot/initramfs-linux-stable1.img /boot/initramfs-linux-stable2.img

$CP /boot/loader/entries/stable1.conf /boot/loader/entries/stable2.conf
$SED -i 's|stable1|stable2|' /boot/loader/entries/stable2.conf
$SED -i 's|STABLE1|STABLE2|' /boot/loader/entries/stable2.conf

# Take new snapshot on Position 1
$BTRFS sub delete /.snapshots/STABLE1
$BTRFS sub snap / /.snapshots/STABLE1

$SED -i 's|subvol=@\t|subvol=@snapshots/STABLE1 |' /.snapshots/STABLE1/etc/fstab
$SED -i 's|subvol=@ |subvol=@snapshots/STABLE1 |' /.snapshots/STABLE1/etc/fstab

$CP /boot/vmlinuz-linux /boot/vmlinuz-linux-stable1
$CP /boot/amd-ucode.img /boot/amd-ucode-stable1.img
$CP /boot/initramfs-linux.img /boot/initramfs-linux-stable1.img

$SED -i '/title/a title\tArch Linux - Snapshot - '"`date`"' -' /boot/loader/entries/stable1.conf 
$SED -i '1d' /boot/loader/entries/stable1.conf

I’ve extended the script for snapshot resorting and boot entry with dates in it, the original basic version I’ve found in an arch install tutorial.