LP: #1938635 and LP: #1993066 are the same trigger. What makes
update-grub report success here is the exit status of 10_linux_zfs,
not only the mount: the script always exits 0, so any abort is
reported as success and grub-mkconfig installs the new grub.cfg
without its entries. On a ZFS root 10_linux leaves the kernel entries
to 10_linux_zfs (util/grub.d/10_linux.in:131-135), so the result is a
grub.cfg without any kernel. Still the same in grub-common
2.14-2ubuntu3 (26.10, 27.04), 2.14-2ubuntu2.1 (26.04) and
2.12-1ubuntu7.3 (24.04).
Cause (util/grub.d/10_linux_zfs.in in 2.14-2ubuntu3; the installed
/etc/grub.d/10_linux_zfs has the same line numbers):
- :51-64: RC=0 is never changed, and on_exit, the trap for EXIT INT
QUIT ABRT PIPE TERM, ends with exit "${RC}". With dash, the status
of an abort by "set -e" is replaced by the trap's explicit exit, so
the script always exits 0.
- :380: get_dataset_info() mounts each root-like dataset without
checking the result, unlike validate_system_dataset() (:127-130). A
locked encrypted dataset with mountpoint=/ on another pool aborts
the whole script there.
- :1104: the menu is printed only at the end, so an abort anywhere
loses every entry, not only the failing dataset's.
- grub-mkconfig (util/grub-mkconfig.in:296-329) installs the new
grub.cfg when every script exits 0.
The fix is attached twice: as a plain patch
(10_linux_zfs-exit-status.patch, against util/grub.d/10_linux_zfs.in
as debian/patches leaves it) and as a debdiff for tenacious
(grub2_2.14-2ubuntu4.debdiff), which adds it as
d/p/ubuntu-zfs-exit-status.patch at the end of the series. It does two
things:
1. Keep the exit status: "RC=$?" as the first line of on_exit, the
EXIT trap on its own, and "exit 1" for the signals. An abort then
makes grub-mkconfig stop and leave the current grub.cfg in place.
2. Guard the mount at :380 as :127 does (and as LP: #1849347 did for
another mount): warn "Failed to mount <dataset>. Ignoring
<dataset>" and return, so the other datasets still get their
entries.
On a machine whose root is not on ZFS, 10_linux provides the kernel
entries and today's abort is harmless; with part 1 alone its
update-grub would fail. Part 2 removes the commonest such abort, so
the two should go together.
It complements the patch in comment #3: that one skips datasets whose
keystatus is "unavailable" before trying to mount them; this one also
covers a mount that fails for any other reason, and makes every other
abort of the script (LP: #2153118, #1973669, #1899372) fail
update-grub instead of installing a menu without entries. The mounts
left behind in LP: #2170880 are a separate matter. Both patches apply
together, in either order, to 2.14-2ubuntu3, 2.14-2ubuntu2.1 and
2.12-1ubuntu7.3 (checked with patch and sh -n; not run together).
Reproducer, as root on a throwaway system (file pools under /dev/shm;
the system's grub.cfg is not touched), run on Ubuntu 26.10 with
kernel 7.3.0-9-generic, zfsutils-linux 2.4.4-1ubuntu4 and grub-common
2.14-2ubuntu3:
W=/dev/shm/lp-repro; mkdir -p $W/mnt $W/tmp
truncate -s 256M $W/a.img $W/b.img
# a bootable-looking pool (compatibility=grub2 so grub-probe reads it)
zpool create -o cachefile=none -o compatibility=grub2 \
-O mountpoint=none -O canmount=off good $W/a.img
zfs create -o canmount=off -o mountpoint=none good/ROOT
zfs create -o canmount=noauto -o mountpoint=/ good/ROOT/os
mount -t zfs -o zfsutil good/ROOT/os $W/mnt
mkdir -p $W/mnt/etc $W/mnt/boot
echo 0123456789abcdef0123456789abcdef > $W/mnt/etc/machine-id
echo 'PRETTY_NAME="Repro Linux"' > $W/mnt/etc/os-release
touch $W/mnt/boot/vmlinuz-9.9.9-repro $W/mnt/boot/initrd.img-9.9.9-repro
umount $W/mnt
# 1. Only that pool: entries, exit 0
TMPDIR=$W/tmp pkgdatadir=/usr/share/grub /etc/grub.d/10_linux_zfs \
> $W/out1; echo "exit $?"; grep -c 'linux.*good' $W/out1
# 2. Add a second pool, as a backup drive would be, with a locked
# encrypted dataset whose mountpoint is /
zpool create -o cachefile=none -O mountpoint=none -O canmount=off \
backup $W/b.img
echo repro-passphrase > $W/key
zfs create -o encryption=on -o keyformat=passphrase \
-o keylocation=file://$W/key -o canmount=noauto -o mountpoint=/ \
backup/os
zfs unload-key backup/os
TMPDIR=$W/tmp pkgdatadir=/usr/share/grub /etc/grub.d/10_linux_zfs \
> $W/out2; echo "exit $?"; grep -c 'linux.*good' $W/out2
# 3. What update-grub runs, with the output in /dev/shm
TMPDIR=$W/tmp grub-mkconfig -o $W/grub.cfg; echo "exit $?"
sed -n '/BEGIN .*10_linux_zfs/,/END .*10_linux_zfs/p' $W/grub.cfg
zpool destroy backup; zpool destroy good; rm -r $W
Results:
- As shipped: step 1 exits 0 with 7 linux lines. Step 2 prints
"zfs_mount_at() failed: encryption key not loaded" and exits 0 with
0 lines. Step 3 exits 0 and writes a grub.cfg whose 10_linux_zfs
section is empty.
- With part 1 only: step 2 exits 2; grub-mkconfig exits 2 and does
not write grub.cfg.
- With parts 1 and 2: step 2 exits 0 with the 7 lines of good/ROOT/os
and the warning; grub-mkconfig exits 0 and writes a grub.cfg with
them.
The debdiff only adds that patch and a changelog entry. It was checked
with dpkg-source: the series applies and the resulting
util/grub.d/10_linux_zfs.in is the file tested above. The binary
packages were not built.
--
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2016778
Title:
Update-grub fails with a second encrypted, but locked rpool
To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/grub2/+bug/2016778/+subscriptions
--
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs