Ubuntu – How to check if Ubuntu has booted in UEFI mode

18.04bootdual-bootuefi

I have installed Ubuntu 18.04 (Bionic Beaver) on my PC in dual boot with Windows 10. I need to check if Ubuntu is booting in UEFI mode or legacy mode. I found a few sources online to check this, but I'm getting ambiguous results.

To be specific, this page, section "Identifying if an Ubuntu has been installed in UEFI mode" gives three ways to check this.

  1. Its /etc/fstab file contains an UEFI partition (mount point: /boot/efi)
  2. It uses the grub-efi bootloader (not grub-pc)
  3. From the installed Ubuntu, open a terminal (Ctrl+Alt+T) then type the following command:
    [ -d /sys/firmware/efi ] && echo "Installed in UEFI mode" || echo "Installed in Legacy mode"

I tried the 1st and 3rd ways.

My fstab file contains the below entry:

UUID=xxx    /boot/efi    ntfs    defaults    0   1

So, that means Ubuntu has booted in UEFI mode.

But running the command given in the third method

[ -d /sys/firmware/efi ] && echo "Installed in UEFI mode" || echo "Installed in Legacy mode"

prints Installed in Legacy mode.

Which is correct? Which is a reliable method for Ubuntu 18.04?

Best Answer

You can use the following command line,

test -d /sys/firmware/efi && echo efi || echo bios

or longer but easier to understand

if test -d /sys/firmware/efi;then echo efi;else echo bios;fi

See the following link,

help.ubuntu.com/community/Installation/FromUSBStick#Test_if_running_in_UEFI_mode


Edit: Comment about /boot/efi

/boot/efi is a persistent directory (that survives shutdown and reboot), while /sys/firmware/efi, actually the content of the /sys file system is created every time the computer is booted.

The existence of /boot/efi, a directory in an EFI system partition, can make it possible to boot in UEFI mode, but it does not make it impossible to boot in BIOS mode. So it does not tell you in which mode the computer is booted. It is possible to have installed Ubuntu and other linux systems that can boot both in UEFI and BIOS mode.

Related Question