From 87b408b49bb8aa47331de7314fc44bbc4ce8510d Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Thu, 26 Aug 2021 12:12:03 +0200 Subject: [PATCH] TT#118659 EFI support: provide workaround for grml-debootstrap versions <=0.96 When we run current versions of deployment.sh, which include the fix from commit f9aea18c, in combination with grml-debootstrap <=0.96 (as shipped by our Grml deployment ISO version sipwise20210511), deployments using EFI might fail with: | Mounting /dev/nvme0n1p2 on /boot/efi | Invoking efibootmgr | EFI variables are not supported on this system. | -> Failed (rc=1) | [...] | Mounting /dev (via bind mount) | Mounting efivarfs on /sys/firmware/efi/efivars | Invoking grub-install with proper EFI environment | chroot: failed to run command 'grub-install': No such file or directory | -> Failed (rc=127) This is caused by a failing invocation of efibootmgr from within grml-debootstrap (versions <=0.96 and running with Debian kernel >=5.10), causing grml-debootstrap to exit then. As a result, the EFI specific GRUB steps in grml-debootstrap's grub_install() from within chroot-script doesn't get executed. Therefor the grub-efi-amd64 package is missing for usage by our efivarfs post-script. By re-introducing the efivarfs pre-script from commit 535e6df3 we can work around this bug. Furthermore, when /boot/efi should be mounted within the target system by our efivarfs post-script, it might fail when /proc isn't available, like: | # chroot /mnt mount /boot/efi | mount: /boot/efi: can't find UUID=FE60-5B75. This can be fixed by ensuring to mount /proc, /sys etc *before* /boot/efi. Then scanning for the UUID device (as configured in /etc/fstab) works as expected. While at it fix a comment regarding grml-debootstrap >=v0.97 vs >=v0.99, as only v0.99 behaves as expected with our EFI requirements. Change-Id: I9db677a06f7e161f971743fc18b034ad3191a449 (cherry picked from commit 9ec2c3d4598bc82675c759ed0dabfb40b03c1478) --- templates/scripts/includes/deployment.sh | 39 +++++++++++++++++++----- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/templates/scripts/includes/deployment.sh b/templates/scripts/includes/deployment.sh index 26bfe59..1149a5c 100755 --- a/templates/scripts/includes/deployment.sh +++ b/templates/scripts/includes/deployment.sh @@ -362,6 +362,30 @@ efivars_workaround() { echo "Present grml-debootstrap version is not recent enough, falling back to workarounds using local script" + # pre script, relevant for grml-debootstrap versions <=0.96 with EFI environments + mkdir -p /etc/debootstrap/pre-scripts/ + cat > /etc/debootstrap/pre-scripts/efivarfs << "EOL" +#!/bin/bash +set -eu -p pipefail + +echo "Executing $0" + +if ! ls "${MNTPOINT}"/sys/firmware/efi/efivars/* &>/dev/null ; then + # we need to have /sys available to be able to mount /sys/firmware/efi/efivars + if ! chroot "${MNTPOINT}" test -d /sys/kernel ; then + echo "Mointing /sys" + chroot "${MNTPOINT}" mount -t sysfs none /sys + fi + + echo "Mounting efivarfs on /sys/firmware/efi/efivars" + chroot "${MNTPOINT}" mount -t efivarfs efivarfs /sys/firmware/efi/efivars +fi +echo "Finished execution of $0" +EOL + + chmod 775 /etc/debootstrap/pre-scripts/efivarfs + PRE_SCRIPTS_OPTION="--pre-scripts /etc/debootstrap/pre-scripts/" + # post script mkdir -p /etc/debootstrap/post-scripts/ cat > /etc/debootstrap/post-scripts/efivarfs << "EOL" @@ -370,11 +394,6 @@ set -eu -p pipefail echo "Executing $0" -if ! [ -d "${MNTPOINT}"/boot/efi/EFI ] ; then - echo "Mounting /boot/efi" - chroot "${MNTPOINT}" mount /boot/efi -fi - if ! [ -e "${MNTPOINT}"/dev/mapper/ngcp-root ] ; then echo "Mounting /dev (via bind mount)" mount --bind /dev "${MNTPOINT}"/dev/ @@ -396,10 +415,15 @@ if ! ls "${MNTPOINT}"/sys/firmware/efi/efivars/* &>/dev/null ; then chroot "${MNTPOINT}" mount -t efivarfs efivarfs /sys/firmware/efi/efivars fi +if ! [ -d "${MNTPOINT}"/boot/efi/EFI ] ; then + echo "Mounting /boot/efi" + chroot "${MNTPOINT}" mount /boot/efi +fi + echo "Invoking grub-install with proper EFI environment" chroot "${MNTPOINT}" grub-install -for f in /sys/firmware/efi/efivars /sys /proc /dev /boot/efi ; do +for f in /boot/efi /sys/firmware/efi/efivars /sys /proc /dev ; do if mountpoint "${MNTPOINT}/$f" &>/dev/null ; then echo "Unmounting $f" umount "${MNTPOINT}/$f" @@ -2004,7 +2028,7 @@ if [[ -n "${EFI_PARTITION}" ]] ; then echo "EFI support present, enabling EFI support within grml-debootstrap" EFI_OPTION="--efi ${EFI_PARTITION}" - # this can be dropped once we have grml-debootstrap >=v0.97 available in our squashfs + # this can be dropped once we have grml-debootstrap >=v0.99 available in our squashfs efivars_workaround else echo "EFI support NOT present, not enabling EFI support within grml-debootstrap" @@ -2028,6 +2052,7 @@ echo y | grml-debootstrap \ -r "$DEBIAN_RELEASE" \ -t "$ROOT_FS" \ $EFI_OPTION \ + $PRE_SCRIPTS_OPTION \ $POST_SCRIPTS_OPTION \ --password 'sipwise' 2>&1 | tee -a /tmp/grml-debootstrap.log