Linux Boot Process Step-by-Step Explained
Table of Contents
When we click the power button of our system, several processes are executing in the background. It’s very important to understand the booting process to learn the working of an operating system. It’s a must to understand how the Linux kernel boots to resolve the booting error. It is a very curious topic to know, so let’s begin with the basics.
Understanding the Boot Process
What is Booting Process in Linux?
The boot process is a fundamental aspect of any operating system. It is the process by which the operating system loads into the computer’s memory, initializes its components, and prepares to execute user applications.
The Linux boot process consists of several stages that are critical to the functionality of the operating system. Let us go through the various stages of the booting process in Linux.
Stages of Linux Boot Process
BIOS
The BIOS (Basic Input/Output System) is the firmware responsible for initiating the computer’s hardware components. The BIOS is the first step in any operating system’s boot process and is independent of the operating system that is to be loaded. The BIOS runs from the ROM of the computer and handles a number of important tasks such as POST or the Power On Self Test. During this stage, the firmware checks the system hardware components such as the memory, CPU, and storage devices.
The primary function of BIOS is to check the hardware components and ensure that they are functioning correctly before passing control to the boot loader. Then, BIOS checks its list of devices for the MBR, and once found, it attempts to boot the operating system.
MBR
The MBR or Master Boot Record is a boot sector that is located in the very first sector of the drive and only occupies 512 bytes. It contains the partition table and the boot loader code, which is responsible for loading the operating system into memory and starting its execution. The MBR is an essential component of the boot process, as it provides the necessary information for the boot loader to locate and load the operating system.
Bootloader
The bootloader is a small piece of software responsible for loading the kernel into memory. The bootloader’s primary function is to provide the user with a choice of operating systems to boot into.
There are two main boot loaders used in Linux systems, GRUB (Grand Unified Bootloader) and LILO (Linux Loader). The configuration file for GRUB is located in the /boot/grub directory and is named grub.cfg. The configuration file for LILO is located in the /etc/lilo.conf directory. Both configuration files contain instructions on how to boot the kernel, such as the location of the kernel, the root file system, and the kernel parameters.
LILO can only be used to boot Linux-based operating systems though GRUB can be used to boot multiple operating systems such as Linux or Windows. Most modern devices these days use GRUB or GRUB 2, which is a more modern implementation of GRUB.
Kernel Initialization
The kernel is the core component of the Linux operating system. Its primary function is to manage system resources such as memory, CPU, and I/O devices. After the boot loader loads the kernel into memory, the kernel begins the process of initializing the system. During this stage, the kernel identifies and loads the necessary drivers and modules required for the system to function.
The kernel also mounts the root file system, which contains the essential files needed to start the system. Another critical aspect of kernel initialization is the initiation of the initial RAM disk (initrd) or initial RAM file system (initramfs). The initrd or initramfs contains a minimal file system and necessary kernel modules that are loaded into memory before the root file system is mounted. The initrd or initramfs allows the kernel to have access to the necessary files and drivers to mount the root file system.
Init System
After the kernel completes its initialization process, it passes control to the Initialization system or Init system. A crucial step in the Linux boot process, the Init system initializes and starts all the system functions and processes necessary for the operating system to run. The Init procedure begins by deciding which run level should be used to start the system, which determines the system services and processes that are to be started. Then all the system services required for run level are initialized, such as the network stack, logging, and authentication. The user environment is then set up, and all daemon processes necessary for the selected run level are then initiated.
There are three primary initialization systems in Linux. These are SysVinit, Upstart, and Systemd. These init systems are responsible for controlling the startup and shutdown of the system.
Runlevel Programs
The Linux operating system has different run levels that determine which system services and processes are started during booting. Runlevels are numbered from 0 to 6, and each run level corresponds to a specific set of system services and processes.
For example, runlevel 0 is the shutdown state, while runlevel 6 is the reboot state. Runlevel 1 is also known as the single-user mode, which is a minimal state where only essential services are started. Runlevel 5 is typically the default runlevel for graphical user interface (GUI) login.