Boot Process in Linux: A Comprehensive Guide

When you turn on your computer and press the Power button, the boot process in Linux starts. After a few moments, the Linux login prompt appears.

Ever wonder what goes on in the background between pressing the power button and displaying the Linux login prompt?

As a Linux system admin, developer or user, understand this process is very crucial for resolving problems and enhancing efficiency.

In this blog post we will breakdown the boot process in Linux into multiple stages and understand each stage in a simple manner.

Boot Process in Linux

Boot Process in Linux


1. Power-On Self Test (POST)

When your computer initially turns on, the firmware (BIOS or UEFI) starts the Power-On Self Test (POST). This process ensures that all hardware components are working as intended.


If the POST process is successful, the system then searches for a bootable device, such as a USB drive or hard drive to locate to locate the MBR.


Important Points:

  • POST examines the RAM, CPU, and other hardware.
  • It sets up the system's hardware.
  • You can notice error messages or hear beep signals if something goes wrong.


Read more on UEFI vs BIOS: Detailed Comparison

2. Bootloader Stage


Following a successful POST, the bootloader is loaded from the MBR. On most Linux systems, the default Bootloader is GRUB (GRand Unified Bootloader), which loads the Linux kernel into memory.


The MBR or Master Boot Record is an integral part of the boot process for computer systems. It acts as the boot sector and located at the very beginning of a storage device, such as a hard drive or SSD. It plays an important role in starting and partitioning drives.

The MBR is located in the first 512 bytes of the storage device. It is divided into three parts:

1. Boot Code (446 bytes)
2. Partition Table (64 bytes)
3. Boot Signature (2 bytes)


Bootloader Functions:

  • Display the boot menu (if multiple operating systems are installed).
  • Loads the kernel and initial RAM disk (initrd).
  • Hands over control to the kernel.

Configuration:

Bootloader settings can be edited in the ‘/etc/default/grub’ file location and lets you alter boot parameters.


3. Kernel Initialization


Once the kernel is loaded by the bootloader, the kernel initializes the system hardware and mounts the root filesystem.


Here, the Linux kernel carries out the below important functions, like:
  • Enabling memory management.
  • Identifying and setting up hardware components.
  • launching the init/ systemd procedure.

4. Init/ Systemd


Following kernel startup, the init process (or its more recent equivalents, such as systemd or upstart) is executed.

The init system is the first user-space program and is responsible for bringing the system to a usable state.

The process id for init/ systemd is always 1.

Functions of Init Process:

  • Reads the configuration file, /etc/inittab for traditional init or /etc/systemd/system/default.target for system
  • Launches essential services and processes, such as the graphical interface, network services, and user login prompts.

Common Init Systems:

  • SysVinit: This is the traditional init system that uses runlevels.
  • systemd: This is the modern init system that uses targets instead of runlevels and provides parallel service startup for faster boot times.



5. Runlevels/ Targets Initialization


The runlevel (in SysVinit) or target (in systemd) defines the state of the system. The system transitions to a specific runlevel or target, defining what services should be active.

Below are the common runlevels and their equivalent targets:

  • runlevel0.target -> poweroff.target
  • runlevel1.target -> rescue.target
  • runlevel2.target -> multi-user.target
  • runlevel3.target -> multi-user.target
  • runlevel4.target -> multi-user.target
  • runlevel5.target -> graphical.target
  • runlevel6.target -> reboot.target



6. User Space Initialization


After the init/ systemd has started the necessary services, the final stage of the boot process in Linux involves user space initialization.

At this point:

  • User login prompts are displayed.
  • The user can log in and start using the system.
  • User-specific processes and desktop environments are launched.

Conclusion

The boot process in linux is a carefully planned sequence of actions that turns your computer from powered off state to a fully functional system. Gaining knowledge of each phase, starting from POST to user space startup, can help you solve problems more effectively, efficiently and can personalize your Linux experience.

Understanding the boot process is essential for all Linux users, regardless of expertise level. If necessary, go further into particular areas, and don't be afraid to play about with configurations to have the best boot experience possible!


No comments

Powered by Blogger.