172

How do I determine whether a particular running Ubuntu system was booted using EFI/UEFI, or BIOS?

Braiam
  • 67,791
  • 32
  • 179
  • 269

3 Answers3

193

The easiest way is to check to see if /sys/firmware/efi exists. It does not appear if you booted using traditional BIOS.

#!/bin/bash
[ -d /sys/firmware/efi ] && echo UEFI || echo BIOS
22

Deprecated

The answer below is a method that may not always work.
Instead use Colin's answer based on /sys/firmware/efi.


It's very easy to tell if a system was booted in EFI (or not, in which case it must be BIOS):

Just use dmesg | grep "EFI v"

  • This will return a line like this, if the system was booted off of EFI:

    [ 0.000000] EFI v2.00 by American Megatrends
  • Or return nothing if it was not, in which case it was booted off of BIOS

Example of bash script usage based on grep's exit code:

...
dmesg | grep -q "EFI v"    # -q tell grep to output nothing
if [ $? -eq 0 ]      # check exit code; if 0 EFI, else BIOS
then
    echo "You are using EFI boot."
  else
    echo "You are using BIOS boot"
fi
...

Source: For how to determine if an EFI system is using legacy-BIOS emulation or not, as well as more information on testing for EFI and EFI compatibility, along with the strings for a number of EFI vendors/versions, please see this page from the Ubuntu Developer Summit for Precise.

ish
  • 139,926
  • 2
    I'd simplify that to if dmesg | grep -Fq "EFI v"; then .... No point in running the [ command in addition, just to test for success/failure. $? is mainly useful for checking for specific errors. – geirha Jul 12 '12 at 10:50
  • 3
    This is brittle, as there is no guarantee that the string searched for is generated by the desired feature. – Thorbjørn Ravn Andersen Jul 13 '12 at 01:28
  • @ThorbjørnRavnAndersen: The Ubuntu Developer Summit folks seem to think it's part of the specification...can you provide a source or reference for your contention? – ish Jul 13 '12 at 01:30
  • 2
    @izx, any script can happen to write "EFI v" as part of something else. If that happens on a BIOS machine, this would be a false positive. – Thorbjørn Ravn Andersen Jul 13 '12 at 01:37
  • 2
    Best not to grep for text in the kernel log, it is subject to change. Best to look at /sys/firmware/efi – Colin Ian King Jul 27 '12 at 18:24
  • 2
    I'd like to mention however that this is a great way to get the EFI version! – Alexander Trauzzi Sep 03 '12 at 02:01
  • Go figure ... ls: cannot access '/etc/firmware': No such file or directory however [0.000000] efi: EFI v2.60 by American Megatrends. This is on an Arch. – Vorac Sep 28 '20 at 01:21
  • 1
    @Vorac, I believe the accepted approach is to look in /sys/firmware/efi, not /etc/firmware. Did you check to see if the former exists? – tgm1024--Monica was mistreated Feb 12 '21 at 14:58
-1

Python code to check if system is booted with UEFI or ROM BIOS:

import os,sys
def main():
    if(os.path.exists("/sys/firmware/efi")):
        print"\n\n System is booted with uefi!"
    else:
        print"\n\n System is booted with rom bios"
main()
sys.exit(0)
karel
  • 114,770