How to check if GRUB is in EFI or BIOS mode?

7,965

Solution 1

As of GRUB 2.00, assuming GRUB is working well enough to get into normal mode rather than rescue mode, echo $grub_platform from the GRUB shell will show pc in BIOS mode and efi in UEFI mode.

The BIOS build corresponds to the grub-pc package, and the UEFI build corresponds to the grub-efi-amd64 (or, less commonly, grub-efi-ia32) package.

Solution 2

Grub2 implements shell-like syntax. This will work:

if test "${grub_platform}" = "pc"; then
  menuentry 'XYZ' {
    linux ${linux_params}
    initrd ${initrd_params}
  }
else
  menuentry 'XYZ' {
    linuxefi ${linux_params}
    initrdefi ${initrd_params}
  }
fi

# as well as
if [ "${grub_platform}" = "pc" ] ; then
fi

# or
if [ "${grub_platform}" = "pc" ]
then
fi
Share:
7,965

Related videos on Youtube

NoahR
Author by

NoahR

Updated on September 18, 2022

Comments

  • NoahR
    NoahR over 1 year

    Is there a command at the grub shell that would indicate if the machine is presenting EFI or BIOS firmware?

    I'm using GRUB 2.00 on a 2010 Mac Pro. This computer has EFI firmware of course. But I have been trying for a couple of days to get it to boot Ubuntu in BIOS-emulation mode for want of NVIDIA display drivers. My understanding is that by the time GRUB is running, the decision to use EFI or BIOS emulation has already been made. So how can I check from GRUB?

  • NoahR
    NoahR over 10 years
    Thank you. I just tried it out straight from the Live CD (on USB) and got "efi". This is a good diagnostic because my understanding is that Ubuntu is not going to be loaded in BIOS mode following this indication. Now to figure out how to get "pc"... There may be a little wiggle room here. I see the documentation for grub_platform says it indicates the platform for which GRUB was built. It seems likely the ideas are equivalent to me, but I'm not an expert here. I don't think the "efi" build of GRUB would even run in BIOS mode, right?
  • Asifa.K
    Asifa.K almost 9 years
    How can I use an if statement with this? I have tried if [ ${$grub_platform} == "pc" ] { ... }, but it didn't work - it always evaluated to true.
  • Colin Watson
    Colin Watson over 8 years
    That syntax is wrong in a couple of ways. if [ ${grub_platform} == "pc" ]; then ...; fi is more likely to work.