jspωiki
Linux Boot Process

The Linux boot process consists of several stages each represented by a different component. The following list briefly summarizes the boot process and features all the major components involved. This discussion focus is on the Intel/PC platform to try to keep it simple.

System Startup#

The system startup stage depends on the hardware that Linux is being booted on. On an embedded platform, a bootstrap environment is used when the system is powered on, or reset. Examples include U-Boot, RedBoot, and MicroMonitor from Lucent. Embedded platforms are commonly shipped with a boot monitor. These programs reside in special region of flash memory on the target hardware and provide the means to download a Linux kernel image into flash memory and subsequently execute it. In addition to having the ability to store and boot a Linux image, these boot monitors perform some level of system test and hardware initialization. In an embedded target, these boot monitors commonly cover both the first- and second-stage boot loaders.

BIOS #

For the PC platform, after the computer has been turned on, the BIOS initializes the screen and keyboard and tests the main memory. Up to this stage, the machine does not access any mass storage media. Subsequently, the information about the current date, time, and the most important peripherals are loaded from the CMOS values. When the first hard disk and its geometry are recognized, the system control passes from the BIOS to the boot loader. If the BIOS supports network booting, it is also possible to configure a boot server that provides the boot loader. On x86 systems, PXE boot is needed. Other architectures commonly use the BOOTP protocol to get the boot loader.

Boot loader#

The primary and secondary boot loaders combined are called Linux Loader (LILO) or GRand Unified Bootloader (GRUB) in the x86 PC environment.

Primary Boot Loader#

The primary boot loader that resides in the MBR is a 512-byte image containing both program code and a small partition table. The first 446 bytes are the primary boot loader, which contains both executable code and error message text. The next sixty-four bytes are the partition table, which contains a record for each of four partitions (sixteen bytes each). The MBR ends with two bytes that are defined as the magic number (0xAA55). The magic number serves as a validation check of the MBR.

The first physical 512-byte data sector of the first hard disk is loaded into the main memory and the boot loader that resides at the beginning of the first physical 512-byte data sector of the first hard disk takes over. The commands executed by the boot loader determine the remaining part of the boot process. Therefore, the first 512 bytes on the first hard disk are referred to as the Master Boot Record (MBR). The boot loader then passes control to the actual operating system, in this case, the Linux kernel. More information about GRUB, the Linux boot loader. For a network boot, the BIOS acts as the boot loader. It gets the image to start from the boot server then starts the system. This is completely independent of local hard disks.

Secondary Boot Loader#

The secondary, or second-stage, boot loader could be more aptly called the kernel loader. The task at this stage is to load the Linux kernel and optional initial RAM disk.

With stage 2 loaded, GRUB can, upon request, display a list of available kernels (defined in /etc/grub.conf, with soft links from /etc/grub/menu.lst and /etc/grub.conf). You can select a kernel and even amend it with additional kernel parameters. Optionally, you can use a command-line shell for greater manual control over the boot process.

With the secondary boot loader in memory, the file system is consulted, and the default kernel image and initrd image are loaded into memory. With the images ready, the secondary boot loader invokes the default or selected kernel image.

Kernel and initramfs #

To pass system control, the boot loader loads both the kernel and an initial RAM–based file system (initramfs) into memory. The contents of the initramfs can be used by the kernel directly. initramfs contains a small executable called init that handles the mounting of the real root file system. If special hardware drivers are needed before the mass storage can be accessed, they must be in initramfs.

If the system does not have a local hard disk, the initramfs must provide the root file system to the kernel. This can be done with the help of a network block device like iSCSI or SAN, but it is also possible to use NFS as the root device.

init on initramfs #

This program performs all actions needed to mount the proper root file system, like providing kernel functionality for the needed file system and device drivers for mass storage controllers with udev. After the root file system has been found, it is checked for errors and mounted. If this has been successful, the initramfs is cleaned and the init program on the root file system is executed. For more information about init, refer to Section 7.1.2, “init on initramfs” (page 63). Find more information about udev in Chapter 11, Dynamic Kernel Device Management with udev (page 131).

init #

init handles the actual booting of the system through several different levels providing different functionality. init is described in Section 7.2, “The init Process” (page 65).

Master Boot Record#

The structure of the MBR is defined by an operating system–independent convention. The first 446 bytes are reserved for the program code. They typically hold part of a boot loader program or an operating system selector. The next 64 bytes provide space for a partition table of up to four entries. The partition table contains information about the partitioning of the hard disk and the file system types. The operating system needs this table for handling the hard disk. With conventional generic code in the MBR, exactly one partition must be marked active. The last two bytes of the MBR must contain a static "magic number" (AA55). An MBR containing a different value is regarded as invalid by some BIOSes, and is not considered for booting.

Boot Sectors#

Boot sectors are the first sectors of each hard disk partitions with the exception of the extended partition, which merely serves as a "container" for other partitions. These boot sectors have 512 bytes of space for code used to boot an operating system installed in the respective partition.
  • Microsoft Type OSs - boot sectors of formatted DOS, Windows, and OS/2 partitions, which also contain some basic important data of the file system.
  • Linux - the boot sectors of Linux partitions are initially empty after setting up a file system other than XFS. Therefore, a Linux partition is not bootable by itself, even if it contains a kernel and a valid root file system. A boot sector with valid code for booting the system has the same magic number as the MBR in its last two bytes (AA55).

Booting with GRUB#

GRUB (Grand Unified Bootloader) comprises two stages.