Computer Boot Process#
ROM -> LOADER -> RUNTIME -> OS LOADER -> OS
- Loader: Common examples include BIOS and UEFI (the latter being the successor of the former). It is generally responsible for memory initialization and loading the Runtime and OS Loader programs.
- Runtime: Firmware programs that provide runtime services, serving as the most basic abstraction of hardware (providing a series of abstractions to the OS).
- OS Loader: Also known as
BootLoader
by many. It is responsible for tasks such as file system booting, network booting, operating system startup configuration settings, and operating system loading. Common OS Loaders include GRUB, U-Boot, LinuxBoot, etc.
How UEFI Finds and Starts the Loader#
UEFI is now more commonly used as the Loader instead of BIOS, with the term BIOS being retained out of habit. The UEFI firmware on the motherboard only recognizes files in the efi
format, so it cannot load elf
format kernels. This is where the OS Loader comes in. It plays a transitional role, wrapping itself in the efi
format in the UEFI environment and saving it in a specific location on the hard disk. When faced with a kernel
, it will parse the elf
format and load it.
This allows the computer to successfully find the Loader during the startup phase and further load and run the OS. The Loader is actually a program format. The specific location of the Loader is required to be in the FAT32
format partition of the boot device. In this root directory, a new efi
directory is created, and within the efi
directory, a new boot
directory is created. The computer firmware will then search for the Loader according to this fixed path, which contains the specifications that Bootx64.efi
must adhere to (if it is a 32-bit system, it cannot have 64).
This FAT32
partition is generally located at the beginning of the entire disk, with a size of approximately 100M (it can also be GB or even larger, depending on flexibility). The UEFI firmware treats disks with FAT32
format partitions as boot disks and adds them to the boot menu. Whether they can be booted or not is not considered at this stage. When selecting a specific target, if it has a UEFI prefix, it will search for the fixed path (/efi/boot
to find the Loader).
Similarly, the Loader searches for the kernel
file in the same way, placing the kernel
file in the same directory. When the Loader finds the kernel
file, it is parsed according to the elf
file format. If it is a runnable elf
file, it is read into memory and executed.
How Does the Kernel Read from the FAT32 Partition?#
This is where UEFI comes in. There is no need to consider which memory block or segmentation to load into. It provides a rich set of services for developers to use during the startup and runtime phases. The services provided during the startup phase are called boot-time services, which are only available during startup. The runtime services, on the other hand, can be used after the computer finishes booting and enters normal operation. All of these are provided through the UEFI interface.