From c03e46d9e1244d6ee2ac85ff119fed54b7e08c0e Mon Sep 17 00:00:00 2001 From: Steve Baker Date: Wed, 17 Apr 2024 10:36:03 +1200 Subject: [PATCH] Overwrite EFI grub.cfg when it exists Currently a partition image with existing EFI assets may produce an invalid image because the EFI grub.cfg may reference a partition UUIDs that don't exist in the partition image case. This change replaces the EFI grub.cfg if the EFI directory exists at all, ensuring the EFI grub.cfg is valid in more cases. Also, add missing EFI_BOOT_DIR for fedora-container element. Change-Id: Id4f8cd2cb16bbb1a392f531cf5b8455f81162c42 --- .../bootloader/finalise.d/50-bootloader | 18 +++++++++--------- .../10-01-fedora-distro-name.bash | 1 + 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/diskimage_builder/elements/bootloader/finalise.d/50-bootloader b/diskimage_builder/elements/bootloader/finalise.d/50-bootloader index 0786154bc..cfedd9b3e 100755 --- a/diskimage_builder/elements/bootloader/finalise.d/50-bootloader +++ b/diskimage_builder/elements/bootloader/finalise.d/50-bootloader @@ -207,16 +207,16 @@ fi # linuxefi/initrdefi for the image to boot under efi if [[ ${DIB_BLOCK_DEVICE} == "efi" ]]; then sed -i 's%\(linux\|initrd\)16 /boot%\1efi /boot%g' $GRUB_CFG +fi - # Finally copy the grub.cfg and grubenv to the EFI specific dir - # to support functionality like secure boot. We make a copy because - # /boot and /boot/efi may be different partitions and uefi looks - # for a specific partition UUID preventing symlinks from working. - if [ -d /boot/efi/$EFI_BOOT_DIR ] ; then - cp $GRUB_CFG /boot/efi/$EFI_BOOT_DIR/grub.cfg - if [ -a $GRUBENV ]; then - cp $GRUBENV /boot/efi/$EFI_BOOT_DIR/grubenv - fi +# Finally copy the grub.cfg and grubenv to the EFI specific dir +# to support functionality like secure boot. We make a copy because +# /boot and /boot/efi may be different partitions and uefi looks +# for a specific partition UUID preventing symlinks from working. +if [ -n "${EFI_BOOT_DIR:-}" ] && [ -d /boot/efi/$EFI_BOOT_DIR ] ; then + cp $GRUB_CFG /boot/efi/$EFI_BOOT_DIR/grub.cfg + if [ -a $GRUBENV ]; then + cp $GRUBENV /boot/efi/$EFI_BOOT_DIR/grubenv fi fi diff --git a/diskimage_builder/elements/fedora-container/environment.d/10-01-fedora-distro-name.bash b/diskimage_builder/elements/fedora-container/environment.d/10-01-fedora-distro-name.bash index f4fd47a54..511e19e95 100644 --- a/diskimage_builder/elements/fedora-container/environment.d/10-01-fedora-distro-name.bash +++ b/diskimage_builder/elements/fedora-container/environment.d/10-01-fedora-distro-name.bash @@ -1,2 +1,3 @@ export DISTRO_NAME=fedora export DIB_RELEASE=${DIB_RELEASE:-34} +export EFI_BOOT_DIR="EFI/fedora"