#253 PR merged: Fix UEFI detection on some distributions

Florent38 opened issue at 2013-06-21 07:22:

For example in RHEL where efivarskernel module is builtin. The check of /sys/firmware/efi/{efi,efivars} is enough IMHO.
Example on RHEL 6.4 on an UEFI system:

modprobe efivars

FATAL: Module efivars not found.

Florent38 commented at 2013-06-21 08:34:

efivars module create and populate /sys/firmware/efi directory. On a BIOS system, this directory will never be created.
After the modprobe command, rear test if this directory exists and return if not. According to the test-efivars in Systemd, we see that the test of the directory is enough :

Systemd test the efi boot with this function :
bool is_efi_boot(void) {
return access("/sys/firmware/efi", F_OK) >= 0;
}

dagwieers commented at 2013-06-21 10:43:

@Florent38 Alright, I understand it now. The patch looks fine.

There is one other thing I don't like from that same file, which are the '||' and '&&' statements. For me they break the flow of the logic and I always have a hard time interpreting the intended flow. (In the past I wanted a coding standard to avoid certain shell statements and have a more consistent way of writing shell).

Especially this I find confusing:

cat /proc/cmdline | grep -q noefi || {    # 'noefi' option not found, so check for the dir itself
    if [ -d /sys/firmware/efi/vars ]; then
        SYSFS_DIR_EFI_VARS=/sys/firmware/efi/vars
    elif [ -d /sys/firmware/efi/efivars ]; then
        SYSFS_DIR_EFI_VARS=/sys/firmware/efi/efivars
    else 
        return    # when UEFI is enabled the dir is there
    fi
    }

I would expect that in case someone would configure the kernel to not do EFI by setting noefi that we would not bother including UEFI support. So I would expect this:

if grep -qE '\bnoefi\b' /proc/cmdline; then
    return
fi

if [ -d /sys/firmware/efi/vars ]; then
    SYSFS_DIR_EFI_VARS=/sys/firmware/efi/vars
elif [ -d /sys/firmware/efi/efivars ]; then
    SYSFS_DIR_EFI_VARS=/sys/firmware/efi/efivars
else 
    return    # when UEFI is enabled the dir is there
fi

Now it seems that if noefi was specified on the kernel command line, it will not bother checking /sys/firmware/efi/vars and continues using UEFI. What am I missing ? :-)

Florent38 commented at 2013-06-21 12:15:

I'm agree with you.

The noefi option on the kernel command line instructs the kernel not to access the UEFI Runtime Services (don't load efivars module in fact, so the directory in /sys/firmware/efi isn't populated).
What do you think about the rear handling of this noefi option ?

Why don't use the -w option of grep instead of the -E "\befi\b" ?

Source for noefi option : https://wiki.archlinux.org/index.php/Unified_Extensible_Firmware_Interface

gdha commented at 2013-06-21 13:46:

Be careful - noefi does not mean that UEFI cannot be used. Only that it is not visible to us. Very confusing, but is that not the purpose of UEFI??

dagwieers commented at 2013-06-21 14:17:

@gdha Agreed, but if the user decides that UEFI should not be visible, the intention is there to not use UEFI. What else is the purpose. Or to put it differently, if a system without UEFI has got the noefi keyword set, we don't want to assume the system does have UEFI, because we cannot tell. So my hunch is "if noefi, we don't do UEFI". No matter if the system has the capability.

@Florent38 Because I didn't know about the -w option to grep ;-) Thanks for that, something we could reuse in Relax-and-Recover, no doubt.

dagwieers commented at 2013-06-21 19:09:

@gdha Can we merge the original pull request ? And then decide what to do with noefi ?


[Export of Github issue for rear/rear.]