Improve EFI detection by checking for /sys/firmware/efi
authorMichael Prokop <mika@grml.org>
Fri, 2 Oct 2020 08:51:51 +0000 (10:51 +0200)
committerMichael Prokop <mika@grml.org>
Fri, 2 Oct 2020 10:59:50 +0000 (12:59 +0200)
It might be possible that we can load the efivars module, while
/sys/firmware/efi still doesn't exist and efibootmgr then fails
to execute.

We noticed this on Hetzner's Dell PowerEdgeâ„¢ R6515 DX181 server,
which was booted in BIOS mode via PXE, while the hardware itself
is EFI capable. Loading the efivars module worked there, but
invoking efibootmgr then fails, and the resulting system isn't
bootable.

Thanks: Darshaka Pathirana for reporting and feedback

grml-debootstrap

index 52adf78..ae601f8 100755 (executable)
@@ -987,14 +987,18 @@ format_efi_partition() {
 
 # check for EFI support or try to enable it {{{
 efi_support() {
-  if lsmod | grep -q efivars ; then
+  local efivars_loaded=false
+  if modprobe efivars &>/dev/null ; then
+    efivars_loaded=true
+  fi
+
+  if [ -d /sys/firmware/efi ] ; then
     einfo "EFI support detected." ; eend 0
     return 0
   fi
 
-  if modprobe efivars &>/dev/null ; then
-    einfo "EFI support enabled now." ; eend 0
-    return 0
+  if ! [ -d /sys/firmware/efi ] && [ "${efivars_loaded:-}" = "true" ] ; then
+    einfo "EFI support detected, but system seems to be running in BIOS mode."
   fi
 
   return 1