From 83499f1a95392772ed4af3ad933f867c11067621 Mon Sep 17 00:00:00 2001 From: David Krauser Date: Wed, 22 Jul 2020 09:43:11 -0400 Subject: [PATCH] Add mechanism to detect initrdless boot fallback In v2.672 the default boot behavior of cloud images changed: - Prior to v2.672, cloud images with the linux-generic kernel attempt to boot without an initramfs, would fail, and then retry with an initramfs. - After v2.672, cloud images with the linux-generic kernel boot with an initramfs on the first try. While the behavior is different between the two, they both result in an instance that has booted with an initramfs. To ensure the changes in v2.672 do not regress, we need an automated way to check if we are attempting to boot without an initramfs and failing. 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. --- debian/changelog | 6 +++++ live-build/functions | 26 +++++++++++++++++++ .../hooks.d/base/disk-image-uefi.binary | 1 + .../ubuntu-cpc/hooks.d/base/disk-image.binary | 5 ++++ 4 files changed, 38 insertions(+) diff --git a/debian/changelog b/debian/changelog index 0ebdecf4..5e2607a5 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +livecd-rootfs (2.678) UNRELEASED; urgency=medium + + * Add mechanism to detect initrdless boot fallback + + -- David Krauser Wed, 22 Jul 2020 14:43:09 -0400 + livecd-rootfs (2.677) groovy; urgency=medium * Avoid rbind /sys for chroot snap pre-seeding (cgroups fail to unmount) diff --git a/live-build/functions b/live-build/functions index 483fc807..ccf961aa 100644 --- a/live-build/functions +++ b/live-build/functions @@ -962,6 +962,32 @@ replace_kernel () { force_boot_without_initramfs ${mountpoint} } +track_initramfs_boot_fallback() { + mountpoint=$1 + cat < "${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 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 9b59117a..910f67a9 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 @@ -133,6 +133,7 @@ install_grub() { chroot mountpoint dpkg-query -W > binary/boot/filesystem.packages 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 d0e4e228..8998df68 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