Welcome! You are about to start on a journey to learn about booting process in different operating systems. For your reference, below is a list of the articles in this series:
- Part 1a: Linux - BIOS and Master Boot Record (this article)
- Part 1b: Linux - The Bootloader
- Part 1c: Linux - The Kernel and Initial Ramdisk
- Part 1d: Linux - Init Process
We will first examine the Linux system. Linux booting process can generally be divided into 4 major steps:
- BIOS loads the bootloader
- The bootloader finds and loads the kernel
- Kernel loads drivers to configure hardware, mounts root filesystem and sets up init process
- Init process executes startup scripts and starts daemon processes
In this first post of this series, we will start off with the BIOS whose responsibility is to find and load the boot loader.
BIOS and Master Boot Record
When you powered on a physical Linux machine, usually a particular component, i.e. the power supply, will supply power to other hardware components, i.e. motherboard, CPU, hard disks, SSD, graphics processors, etc.
A firmware on motherboard that held in a nonvolatile flash RAM called BIOS performs Power-on-self-test (POST) to discover a limited number of devices, i.e. Ethernet and storage (USB, hard disk) that required to boot.
BIOS can only communicate to a few devices used for booting because it does not contain many drivers discover all devices. It starts out by scanning the PCIs and PCI buses to detect all the devices attached to them. If the devices present are different from when the system was last booted, the new devices are configured.
The BIOS then determines the boot device from list of devices stored in the CMOS memory. Let’s assume that the boot device is a hard drive. The very first sector (the boot sector or Master Boot Record) of the disk is read into a fixed memory location and executed. This sector is the first 512 bytes on a hard drive (with zero as its offset) in which 446 bytes are a standalone program called stage-1 boot (boot.img).
The end of MBR contains partition table describing the partitions of a storage device. The organization of the partition table in the MBR limits the maximum addressable storage space of a partitioned disk to 2 TB. You might have also seen modern boot sector with the size of 4096 bytes instead of 512.
Up to this stage, the machine does not access any mass storage media. Therefore, information on the date, time, and important peripherals are loaded from the CMOS - a battery-backed chip inside computer that stores information.
A more formalized and modern standard, UEFI was developed to replace BIOS. UEFI support almost all new PC hardware these days, but plenty of BIOS systems remain in the field. Moreover, virtualized environments often adopt BIOS as their underlying boot mechanism. Booting is different on UEFI systems: rather than executable boot code residing outside of a filesystem, there is a special filesystem called the EFI System Partition (ESP), which contains a directory named efi. Each boot loader has its own identifier and a corresponding subdirectory, such as efi/microsoft, efi/apple, or efi/grub. A boot loader file has an .efi extension and resides in one of these subdirectories, along with other supporting files. UEFI is also more secure as it requires boot loaders to be digitally signed by a trusted authority.
From here onward, the bootloader will take over the process.