[neon/neon/livecd-rootfs/Neon/release-lts] /: Add mechanism to detect initrdless boot fallback

Pat Viafore null at kde.org
Fri Mar 12 10:45:26 GMT 2021


Git commit 0775862a25ab2900fe6d08b4acd5d572dd62fe6b by Pat Viafore.
Committed on 18/02/2021 at 21:47.
Pushed by jriddell into branch 'Neon/release-lts'.

Add mechanism to detect initrdless boot fallback

With this change, when we attempt to boot with an initramfs and fail,
initrdless_boot_fallback_triggered is set to non-zero in the grubenv.
This value can be checked after boot by looking in /boot/grub/grubenv
or by using the grub-editenv list command.

Addresses LP: #1870189

M  +8    -0    debian/changelog
M  +32   -0    live-build/functions
M  +1    -0    live-build/ubuntu-cpc/hooks.d/base/disk-image-uefi.binary
M  +5    -0    live-build/ubuntu-cpc/hooks.d/base/disk-image.binary

https://invent.kde.org/neon/neon/livecd-rootfs/commit/0775862a25ab2900fe6d08b4acd5d572dd62fe6b

diff --git a/debian/changelog b/debian/changelog
index 93c6c544..2b9bcd05 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,11 @@
+livecd-rootfs (2.664.18) UNRELEASED; urgency=medium
+
+  * Only try without initrd-less on replaced kernels, not all kernels
+  * Provide a mechanism to detect initrd-less fallback 
+
+ -- Patrick Viafore <patrick.viafore at canonical.com>  Tue, 09 Feb 2021 12:40:04 -0600
+
+
 livecd-rootfs (2.664.17) focal; urgency=medium
 
   [ David Krauser ]
diff --git a/live-build/functions b/live-build/functions
index e18c4097..03d637d8 100644
--- a/live-build/functions
+++ b/live-build/functions
@@ -990,6 +990,38 @@ replace_kernel () {
 
     # If running a custom kernel, we should try to boot without an initramfs
     # We do this by setting GRUB_FORCE_PARTUUID, which forces initramfs-less boot
+    force_boot_without_initramfs ${mountpoint}
+}
+
+track_initramfs_boot_fallback() {
+    mountpoint=$1
+    cat <<END > "${mountpoint}/etc/grub.d/01_track_initrdless_boot_fallback"
+#! /bin/sh
+# ${IMAGE_STR}
+# This will detect if we attempt to boot with an initramfs and fail.
+# In the case of a failure, initrdless_boot_fallback_triggered is set to
+# a non-zero value in the grubenv. This value can be checked after boot
+# by looking in /boot/grub/grubenv or by using the grub-editenv list command.
+set -e
+END
+    cat <<"END" >> "${mountpoint}/etc/grub.d/01_track_initrdless_boot_fallback"
+cat <<"EOF"
+if [ -n "${have_grubenv}" ]; then
+  if [ -n "${initrdfail}" ]; then
+    set initrdless_boot_fallback_triggered="${initrdfail}"
+  else
+    set initrdless_boot_fallback_triggered=0
+  fi
+  save_env initrdless_boot_fallback_triggered
+fi
+EOF
+END
+    chmod +x "${mountpoint}/etc/grub.d/01_track_initrdless_boot_fallback"
+}
+
+force_boot_without_initramfs() {
+    mountpoint=$1
+
     partuuid=$(blkid -s PARTUUID -o value $(findmnt -n -o SOURCE --target "${mountpoint}"))
     if [ -n "${partuuid}" ]; then
         echo "Force booting without an initramfs..."
diff --git a/live-build/ubuntu-cpc/hooks.d/base/disk-image-uefi.binary b/live-build/ubuntu-cpc/hooks.d/base/disk-image-uefi.binary
index 19f5e15f..25035316 100755
--- a/live-build/ubuntu-cpc/hooks.d/base/disk-image-uefi.binary
+++ b/live-build/ubuntu-cpc/hooks.d/base/disk-image-uefi.binary
@@ -214,6 +214,7 @@ EOF
     fi
 
     divert_grub mountpoint
+    track_initramfs_boot_fallback mountpoint
     chroot mountpoint update-grub
     replace_grub_root_with_label mountpoint
     undivert_grub mountpoint
diff --git a/live-build/ubuntu-cpc/hooks.d/base/disk-image.binary b/live-build/ubuntu-cpc/hooks.d/base/disk-image.binary
index 1b31b446..f00fbbd7 100755
--- a/live-build/ubuntu-cpc/hooks.d/base/disk-image.binary
+++ b/live-build/ubuntu-cpc/hooks.d/base/disk-image.binary
@@ -119,6 +119,11 @@ if [ "${should_install_grub}" -eq 1 ]; then
         --device-map=/tmp/device.map \
         ${loop_device}
 
+    divert_grub mountpoint
+    track_initramfs_boot_fallback mountpoint
+    chroot mountpoint update-grub
+    undivert_grub mountpoint
+
     rm mountpoint/tmp/device.map
 fi
 



More information about the Neon-commits mailing list