DEV Community

Nur Ilyas
Nur Ilyas

Posted on

UEFI & GPT

DISCLAIMER: This post is written by a complete novice. Information stated may be inaccurate and if so, feel free to correct any mistakes.
RESEARCH TOPIC: UEFI & GPT.

WHAT PROMPTED THIS RESEARCH?: After fiddling with the BIOS screen and GRUB menu, I started wondering what they are...

BIOS & MBR

Before we begin, you might want to take a look at this excellent article on legacy BIOS/MBR to have a bit of context: MBR BOOT PROCESS.

UEFI

EFI diagram

Picture courtesy of UEFI on Wikipedia

  • “The Unified Extensible Firmware Interface (UEFI) is a specification that defines a software interface between an operating system and platform firmware, replacing the legacy Basic Input/Output System (BIOS) firmware interface.”

  • There’s embedded software in your computer also known as firmware. This platform firmware checks and ensures the hardwares (cpu, memory, input-output devices etc) are initialized and ready to be used. The UEFI specification only requires the firmware to create the standardized interfaces and does not state how the underlying interfaces should be implemented so it is up to the vendor to execute that bit. There is an open source firmware implementation of UEFI called TianaCore.

    You may still come across the ‘BIOS’ setup utility screen, which is essentially the firmware settings. The term ‘BIOS’ is still used although your firmware is built for UEFI. Is this because BIOS is recognized amongst consumers for access to firmware settings that it became a noun? Can anyone clarify.

UEFI conceptual overview

Diagram from UEFI Forum

uefi boot manager NVRAM entries

‘efibootmanger -v’ command output showing the NVMRAM entries

  • The platform firmware is responsible for setting up the UEFI protocols and services before starting what is called the UEFI boot manager. The UEFI boot manager will attempt to load the OS boot loaders in order according to globally defined NVRAM variables. You can view the boot order sequence variables in your ‘BIOS setup utility settings’ or using ‘efibootmanger -v’ on linux.

  • The OS loader is a special type of UEFI application (e.g. grubx64.efi) that utilizes the protocols and services provided by the UEFI layer to boot the chosen operating system. Once the OS loader has successfully launched the OS, it will call EFI_BOOT_SERVICES.ExitBootServices(), which will terminate all boot services in the system, including memory management, and the UEFI OS loader is responsible for the continued operation of the system. After control is passed to the operating system, only the runtime services will remain as part of the UEFI layer.

uefi runtime services part 1uefi runtime services part 2

List of UEFI runtime services from UEFI Forum

GPT

  • Like MBR, GUID Partition Table (GPT) is a partitioning scheme which describes how partitions are laid out on a storage device. GPT is now the preferred way to partition a storage device and is used mainly for the UEFI boot, instead of MBR.
  • Let’s first take a look at the layout of a storage device using the GPT scheme.

    GPT Scheme

GPT on Wikipedia

Logical Block Addressing (LBA)

If you would like to know a bit about LBA and how it relates to data being represented in the media, you may want to check these out.

GPT Header Format

gpt header format

0x50 indicates the maximum number of possible partitions. Although this can be unlimited, it’s usually set at 128 partitions.

GPT Partition Entry Format

gpt partition entry format

The partition type ID is globally unique. You may view the list of types here.

UEFI and GPT

  • For UEFI to work, it looks for a special partition known as the ‘EFI System Partition’ which must be formatted based on the FAT filesystem (MacOS is an exception). The EFI Boot Manager can interpret FAT filesystem and it is this partition where the EFI Boot Manager searches for EFI boot loaders. Here is an example of the contents in an 'EFI System Partition'.

efi partition contents

/EFI/boot/bootx64.efi is the fallback path for the boot manager if there are no NVRAM entries saved for that storage media. This is particularly useful say if you want to create a bootable UBUNTU flash drive. You can partition the usb drive according to GPT, create the ‘EFI system partition’ and format it based on FAT32 and then insert grubx64.efi into the ‘EFI/boot/’ folder and rename it to ‘bootx64.efi’. That way when you insert the usb stick into your computer, the EFI boot manager will launch grub under the disguise of bootx64.efi.

Extras

Top comments (0)