A Quick Start Guide to UEFI Firmware for Linux Users
Today let’s take a loot at the firmware of our computer. Specifically, we will focus on BIOS and UEFI.
UEFI BIOS or just UEFI?
You will see online that many people refer it as UEFI BIOS. BIOS is not a generic term for firmware. BIOS is just a specific firmware for IBM compatible PC. So we should call it just UEFI.
Why do we need BIOS?
BIOS stands for Basic Input/Output System. It’s responsible for
- initialize CPU and RAM.
- POST (Power On Self Test)
- initialize the LAN, PCIe.
- Start the boot loader from hard drive, USB stick or LAN.
Once it finishes it’s work, BIOS pass the control to the operating system.
What does Legacy BIOS Mean?
BIOS is 30 years old. It’s was invented in 1985. Legacy refers to old interfaces or mechanisms such as PS/2 keyboards, floppy disk. Today, very few people use these old stuff but the code which deals with these old stuff is still in the Legacy BIOS.
What is UEFI?
UEFI cames from EFI which stands for extensible firmware interface. It’s started by Intel in the late 90s. Intel was developing a 64 bit processor back then. The legacy BIOS run only in 16 bit mode and can’t use all the capabilities of the new processor. So they want to get rid of the old BIOS mechanism. They released the first version of EFI in 2002. In 2005, UEFI Forum was born. UEFI stands for unified extensible firmware interface.
UEFI is a firmware specification, not a firmware implementation. Everyone can take the UEFI specification and write his own UEFI compatible firmware.
Differences Between BIOS and UEFI
BIOS is programed using assembly language whereas UEFI firmware is 99% C language code. C language is much easier to read, maintain and add new functions for programmers. And also it’s very easy to remove old functions.
OptionROMs vs Drivers
OptionROM comes with BIOS. optionROMs has a size limitation of 64KB. It can not be loaded on hard disk, USB drive. In addition, OptionROMs has to be fit to every hardware. So if you change your hardware, you must also change the code of OptionROMs.
With UEFI firmware, you don’t have optionROMs any more. Instead, programmers write drivers. Drivers do not have the limitations of optionROMs mentioned above.
MBR vs. GPT
With BIOS, the hard disk utilize a partition style called MBR which stands for Master Boot Record. You couldn’t access hard disk that is more than 2TB with MBR partition style. MBR also don’t allow more then 4 primary partitions.
With UEFI firmware, the hard disk uses the GPT partition style which stands for GUID Partition Tables. GPT allows up to 128 primary partitions and can access hard disk of more than 2TB.
BIOS still provide some service after it has finished initializing the hardware and POST. UEFI is pre-boot and boot time only. After initilizing the hardware, UEFI BIOS pass the control completely to the operating system.
UEFI shell looks like a Linux terminal window or DOS window, it gives you to ability to run some UEFI applications. It has its own syntax.
Some UEFI firmware has a compatibility support module (CSM). CSM allows the system to fallback to legacy BIOS. A system like this has three different boot modes.
- BIOS mode
- BIOS and UEFI hybrid mode
- UEFI native mode
Note that hybrid mode is not native UEFI mode. If you really want to use UEFI, then you must enable UEFI only and do not enable BIOS. Computers have faster boot time in native UEFI mode because the BIOS does not need to be loaded.
Microsoft Windows only support UEFI with GPT hard disk. Linux can boot in UEFI with GPT and MBR hard disk. Mac’s EFI implementation is a mix a EFI 1.x and UEFI 2.x. This kind of firmware is not a standard UEFI firmware.
UEFI Firmware Processor Architecture
Most Intel platforms support both 32 bit and 64 bit architecuture, as well as 8086/80286 16 bit code. So UEFI firmware on these platforms can be compiled in either 32 or 64 bit mode.
UEFI specification requires the boot loader architecture matches the firmware architecture to reduce problems. In other words, 32 bit UEFI can only run 32 bit boot loader and 64 bit UEFI can only run 64 bit boot loader. However, you can run 64 bit OS with 32 bit UEFI and 32 bit OS with 64 bit UEFI.
How do I know my computer has 32 bit or 64 bit UEFI firmware?
On Linux run the following command.
As you can see, my computer has 64 bit UEFI firmware. Most new PCs come with 64 bit UEFI firmware.
How do I know if Linux is installed in UEFI mode?
If your Linux is installed in UEFI mode, then it comes with grub-efi instead of grub-pc
grub-efi is for UEFI firmware whereas grub-pc is for BIOS.
Run this command in the terminal:
[ -d /sys/firmware/efi ] && echo "Installed in UEFI mode" || echo "Installed in Legacy mode"
How do you know if your computer is booted in UEFI mode
For one thing, you can disable legacy BIOS in your firmware and set it to be UEFI native mode to ensure your computer is booted in UEFI mode.
If you are using Linux, then you can check if your system has a /sys/firmware/efi directory. If this directory exist, then your computer is booted in UEFI mode.
UEFI boot requires the hard disk have a ESP partition. ESP stands for EFI System Partition. It’s formated with FAT32 or FAT16 file system and it’s recommend to keep at least 512MB space for ESP. It’s a storage place for UEFI bootloaders. ESP partition must be mounted at /boot/efi on Linux. It has a boot and esp flag in Gparted. It does not have to be the first partition.
Secure Boot is a extension to UEFI. Some Linux distributions such as Ubuntu, Fedora, OpenSUSE support secure boot, while some other like Debian does not.