The awk expressions parsing `btrfs subvolume show` used `\s`, a GNU
extension. mawk and the One True Awk treat it as a literal `s`, so
`/^\s*UUID/` never matches a tab-indented line and the UUID comes back
empty. Since `awk` is mawk by default on Debian, Ubuntu and derivatives,
grub-mkconfig aborted there with "UUID of the root subvolume is not
available".
Replace `\s` with `[ \t]`, which every awk implementation supports and
which matches the notation already used by the gsub on the same line.
Closes#425
On a multi-device Btrfs filesystem `grub-probe --target=device /` prints
one device per line (e.g. /dev/vda3 and /dev/vdb). The whole multi-line
result was then passed to `grub-probe --device "${root_device}"
--target=fs_uuid`, which cannot handle several devices at once and
returns an empty string. The blkid fallback fails for the same reason,
so grub-btrfs aborts with "Cannot determine UUID".
Pipe the device probe through `head -n1` and keep only the first member
device. Every member of a Btrfs pool reports the same pool-wide fs UUID,
so the first device is sufficient. For single-device setups `head -n1`
is a no-op, so existing configurations are unaffected.
The same one-line-per-device behaviour applies to a /boot that lives on
a multi-device Btrfs, so the identical guard is added to boot_device.
Closes#412
Refs #425
The "Detecting snapshots ..." message was still a bare printf and bypassed the logging helpers added in #435.
Use print_info so it carries the "grub-btrfs:" prefix;
the trailing newline is handled by the helper.
Fedora uses non-standard paths and command names for GRUB (e.g., /boot/grub2 instead of /boot/grub, and grub2-mkconfig).
This change adds a conditional block to detect Fedora via /etc/fedora-release and automatically sets the appropriate variables, improving the out-of-the-box experience for Fedora users.
Two hard failures prevented 41-snapshots-btrfs from generating a
snapshot submenu when the root LUKS header is detached and cryptdevice=
uses a /dev/disk/by-id path:
* grub-probe --target=fs_uuid aborted on detached headers.
* grep-based extraction of UUID from GRUB_CMDLINE_LINUX_DEFAULT failed
when cryptdevice= did not contain “UUID=…”.
This patch:
1. Wraps grub-probe in a try/blkid/lsblk cascade that always returns the
filesystem UUID or prints a clear error.
2. Replaces the fixed “cryptomount -u $(grep …UUID=…)” line with logic
that:
• accepts both UUID=… and /dev/disk/by-id/… syntaxes,
• resolves paths to a canonical UUID with blkid,
• emits ‘cryptomount -u <uuid>’ when possible,
• falls back to ‘cryptomount -a’ only if no UUID can be extracted.
3. Keeps the previous behavior unchanged for unencrypted systems or for
installations that already worked.
Result: snapshot menu is produced and boots correctly on standard
(setup with inline header), detached-header, and by-id configurations;
no regression for existing users.
Some GRUBs out there (Fedora, openSUSE) have an option that makes all
paths relative to the default subvolume of the filesystem. This can be
used to include /boot in your snapshots and roll them back without
having to regenerate grub.cfg.
However, enabling that option will break grub-btrfs, because loading the
kernel from a different snapshot requires the paths to be absolute.
To make this work, GRUB has to be told explicitly to access the root
subvolume when booting to a snapshot.