Ramblings of an aging IT geek
← Ramblings of an aging IT geek
linux

One Core, Many Bootloaders

refind-btrfs-snapshots grows beyond rEFInd. A shared core now drives BLS entries and per-snapshot Unified Kernel Images, with a pure-Go signer, and multi-profile UKIs in design.

Listen to this post
A boot menu listing several bootloader entries

refind-btrfs-snapshots started life answering one question, "how do I make rEFInd offer my btrfs snapshots?", but the interesting work, snapshot discovery, kernel inspection and fstab alignment, was never really about rEFInd. It was about figuring out how a given snapshot wants to boot. rEFInd was just the first thing I rendered that into.

So the project has been refactored into a shared core with a focused binary per boot story:

  • refind-btrfs-snapshots: rEFInd submenu entries (where it began).
  • bls-btrfs-snapshots: Boot Loader Spec entries for systemd-boot and BLS-aware GRUB.
  • uki-btrfs-snapshots: per-snapshot Unified Kernel Images (more on this below).
  • peseal: a pure-Go Authenticode signer for PE/UKI binaries, sbctl-compatible, so the UKI path stays CGO-free.
  • kernel-spy: a read-only diagnostic that dumps every kernel, initramfs, microcode and UKI the discovery layer can see.

One core, many front-ends: the same shape I keep coming back to, because the hard part is the analysis, not the output format.

The UKI problem

Unified Kernel Images are where this gets genuinely tricky, and they're the "support other formats more generically" goal I'd been circling. A UKI bundles kernel, initramfs, cmdline and os-release into one signed EFI binary, and crucially the cmdline lives inside the image, in its .cmdline section. Under Secure Boot that embedded cmdline is authoritative: the boot loader can't override it with an external options= string.

That's fatal for snapshot booting, because a snapshot-bootable cmdline has to differ per snapshot: it carries rootflags=subvol=<snapshot>. Neither the rEFInd nor the BLS output can fix this, because the thing that needs to change is sealed inside the UKI. The cmdline has to go inside an image the firmware will actually run.

What ships today is Mode 1, cloned UKIs. For each bootable snapshot, clone the source UKI into <esp>/EFI/Linux/, copying the kernel and initrd straight across and rewriting only the .cmdline to target that snapshot's subvolume. It costs a full UKI's worth of space per snapshot, but it boots anywhere that can launch an .efi, and peseal signs each one so Secure Boot stays intact.

What's still in design

The cheaper approach is Mode 2, a single multi-profile UKI per kernel, with one .profile section per snapshot sharing the kernel and initrd and carrying only its own cmdline. It's a lovely idea with a sharp edge: today, passing a profile selector at boot is essentially a systemd-boot story, so it isn't yet the universal answer cloning is. That, plus a proper reconciliation engine (compute the desired set of entries from scratch each run, diff against what's on the ESP, delete before adding, and pre-flight the free space so it refuses loudly rather than half-filling your boot partition), is written up in the project's wishlist and is what I'm building toward next.

The throughline: a snapshot you can't boot is just a backup you haven't tested. The point of all five binaries is to make "boot last Tuesday" work whatever your firmware, bootloader and Secure Boot setup happen to be. Repo and wishlist on GitHub.