How to check if Ubuntu has booted in UEFI mode?

16,242

Solution 1

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.

Solution 2

The easiest way to find out if you are running UEFI or BIOS is to look for a folder /sys/firmware/efi.

The folder will be missing if your system is using BIOS.

Execute:

$ ls /sys/firmware/efi

Example of UEFI boot output :enter image description here

Share:
16,242
Nagabhushan S N
Author by

Nagabhushan S N

Updated on September 18, 2022

Comments

  • Nagabhushan S N
    Nagabhushan S N over 1 year

    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?

  • Nagabhushan S N
    Nagabhushan S N over 5 years
    This directory is not present. But fstab file has boot/efi mount-point. Ambiguous right?
  • Carlos Dagorret
    Carlos Dagorret over 5 years
    You boot in BIOS mode
  • Nagabhushan S N
    Nagabhushan S N over 5 years
    Yes. Both answers are almost same. This one is easier for newbies. Since that was the first answer, I accepted that. Also, both of the answers didn't answer my question completely. What is the difference between the two methods and why they give different outputs?
  • sudodus
    sudodus over 5 years
    @NagabhushanSN, /boot/efi is a persistent directory (that survives shutdown and reboot), while /sys/firmware/efi, actually the content of /sys file system is created every time the computer is booted. -- The existence of /boot/efi, 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.
  • Nagabhushan S N
    Nagabhushan S N over 5 years
    Great! This was what I was looking for. Please update your answer, I'll accept it :)