0202-templates-Check-for-EFI-at-runtime-instead-of-config.patch 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Javier Martinez Canillas <javierm@redhat.com>
  3. Date: Tue, 6 Jul 2021 00:38:40 +0200
  4. Subject: [PATCH] templates: Check for EFI at runtime instead of config
  5. generation time
  6. The 30_uefi-firmware template checks if an OsIndicationsSupported UEFI var
  7. exists and EFI_OS_INDICATIONS_BOOT_TO_FW_UI bit is set, to decide whether
  8. a "fwsetup" menu entry would be added or not to the GRUB menu.
  9. But this has the problem that it will only work if the configuration file
  10. was created on an UEFI machine that supports booting to a firmware UI.
  11. This for example doesn't support creating GRUB config files when executing
  12. on systems that support both UEFI and legacy BIOS booting. Since creating
  13. the config file from legacy BIOS wouldn't allow to access the firmware UI.
  14. To prevent this, make the template to unconditionally create the grub.cfg
  15. snippet but check at runtime if was booted through UEFI to decide if this
  16. entry should be added. That way it won't be added when booting with BIOS.
  17. There's no need to check if EFI_OS_INDICATIONS_BOOT_TO_FW_UI bit is set,
  18. since that's already done by the "fwsetup" command when is executed.
  19. Resolves: rhbz#1823864
  20. Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
  21. ---
  22. util/grub.d/30_uefi-firmware.in | 21 ++++++++-------------
  23. 1 file changed, 8 insertions(+), 13 deletions(-)
  24. diff --git a/util/grub.d/30_uefi-firmware.in b/util/grub.d/30_uefi-firmware.in
  25. index d344d3883d7..b6041b55e2a 100644
  26. --- a/util/grub.d/30_uefi-firmware.in
  27. +++ b/util/grub.d/30_uefi-firmware.in
  28. @@ -26,19 +26,14 @@ export TEXTDOMAINDIR="@localedir@"
  29. . "$pkgdatadir/grub-mkconfig_lib"
  30. -EFI_VARS_DIR=/sys/firmware/efi/efivars
  31. -EFI_GLOBAL_VARIABLE=8be4df61-93ca-11d2-aa0d-00e098032b8c
  32. -OS_INDICATIONS="$EFI_VARS_DIR/OsIndicationsSupported-$EFI_GLOBAL_VARIABLE"
  33. +LABEL="UEFI Firmware Settings"
  34. -if [ -e "$OS_INDICATIONS" ] && \
  35. - [ "$(( $(printf 0x%x \'"$(cat $OS_INDICATIONS | cut -b5)"\') & 1 ))" = 1 ]; then
  36. - LABEL="UEFI Firmware Settings"
  37. +gettext_printf "Adding boot menu entry for UEFI Firmware Settings ...\n" >&2
  38. - gettext_printf "Adding boot menu entry for UEFI Firmware Settings ...\n" >&2
  39. -
  40. - cat << EOF
  41. -menuentry '$LABEL' \$menuentry_id_option 'uefi-firmware' {
  42. - fwsetup
  43. -}
  44. -EOF
  45. +cat << EOF
  46. +if [ "\$grub_platform" = "efi" ]; then
  47. + menuentry '$LABEL' \$menuentry_id_option 'uefi-firmware' {
  48. + fwsetup
  49. + }
  50. fi
  51. +EOF