Linux Boot Process

Linux Boot Process


Every time you power on your Linux PC, it goes through a series of stages before finally displaying a login screen that prompts for your username or password. There are 4 distinct stages that every Linux distribution goes through in a typical boot-up process.


  1. BIOS integrity check(POST)

  2. MBR

  3. Loading the bootloader(GRUB2)

  4. Kernel initialization

  5. Starting systemd




1. The BIOS Integrity Check (POST)


When the Linux system powers up, the BIOS (Basic Input Output System) performs a Power On Self Test (POST). 


  • If some hardware device is not detected, or if there’s a malfunction in any of the devices such as a corrupt HDD or SSD, an error message is splashed on the screen prompting your intervention.


  • In some cases, a beeping sound will go off especially in the event of a missing RAM module. However, if the expected hardware is present and functioning as expected, the booting process proceeds to the next stage.



2. MBR

  • MBR stands for Master Boot Record.

  • It is located in the 1st sector of the bootable disk. Typically /dev/hda, or /dev/sda

  • MBR is less than 512 bytes in size. This has three components 1) primary boot loader info in 1st 446 bytes 2) partition table info in next 64 bytes 3) mbr validation check in last 2 bytes.

  • It contains information about GRUB (or LILO in old systems).

  • So, in simple terms MBR loads and executes the GRUB boot loader.


3. The Bootloader (GRUB2)

  • There are 3 main types of bootloaders in Linux: LILO, GRUB, and GRUB2. The GRUB2 bootloader is the latest and primary bootloader in modern Linux distributions and informs our decision to leave out the other two which have become antiquated with the passage of time.

  • GRUB2 stands for GRand Unified Bootloader version 2. Once the BIOS locates the grub2 bootloader, it executes and loads it onto the main memory (RAM).

  • The grub2 menu allows you to do a couple of things. It allows you to select the Linux kernel version that you’d want to use. If you have been upgrading your system a couple of times, you might see different kernel versions listed. Additionally, it gives you the ability to edit some kernel parameters by pressing a combination of keyboard keys.

  • The grub2 configuration file is the /boot/grub2/grub2.cfg file. 

  • GRUB’s main objective is to load the Linux kernel onto the main memory.

4. Kernel Initialization

  • The kernel is the core of any Linux system. It interfaces the PC’s hardware with the underlying processes. The kernel controls all the processes on your Linux system.

  • The selected kernel mounts the root file system and initializes the /sbin/init program commonly referred to as init.

  • Init is always the first program to be executed and is assigned the process ID or PID of 1

  • The kernel then mounts the initial RAM disk (initrd) which is a temporary root filesystem until the real root filesystem is mounted. 

5.Starting Systemd

  • The kernel finally loads Systemd, which is the replacement of the old SysV init. Systemd is the mother of all Linux processes and manages among other things mounting of file systems, starting and stopping services to mention just a few.

  • Systemd uses the /etc/systemd/system/default.target file to determine the state or target that the Linux system should boot into.

  1.  For a desktop workstation (with a GUI) the default target value is 5 which is the equivalent of run level 5 for the old SystemV init.

  2. For a server, the default target is multi-user.target which corresponds to run level 3 in SysV init.

Systemd targets

  • poweroff.target (runlevel 0): Poweroff or Shutdown the system.

  • rescue.target (runlevel 1): launches a rescue shell session.

  • multi-user.target (runlevel 2,3,4): Configures the system to a non-graphical (console) multi-user system.

  • graphical.target (runlevel 5): Set the system to use a graphical multi-user interface with network services.

  • reboot.target (runlevel 6): reboots the system.

To check the current target on your system, run the command:

      systemctl get-default

  • You can switch from one target to another by running the following command on the terminal:

             # init runlevel-value


Comments