A Basic Guide to Linux Boot Process

When you turn on your Linux computer, it goes through a series of steps before presenting you with a login screen that asks for your username and password. In a typical boot-up process, every Linux distribution goes through four distinct stages.

The various steps taken by the Linux OS from the time it is powered on to the time you log in will be highlighted in this guide. Please keep in mind that this guide only considers the GRUB2 bootloader and systemd init because they are used by the vast majority of modern Linux distributions.

A Basic Guide to Linux Boot Process

The Complete Linux Boot Process

The booting procedure is divided into four steps, which we will go over in more detail below:

  1. BIOS Integrity check (POST)
  2. Loading of the Boot loader (GRUB2)
  3. Kernel initialization
  4. Starting systemd, the parent of all processes

Step 1: BIOS Integrity Check (POST)

When a user presses the power button – if the PC was already turned off – or reboots the system using the GUI or the command line, the boot process is usually initiated.

The BIOS (Basic Input Output System) kicks in when the Linux system boots up and performs a Power On Self Test (POST). This is a diagnostic check that performs a variety of integrity checks.

The POST tests the hardware operability of components such as the hard disk drive (HDD), solid-state drive (SSD), keyboard, RAM, USB ports, and any other hardware. If a hardware device isn’t detected, or if one of the devices malfunctions, such as a corrupt HDD or SSD, an error message appears on the screen, requesting your intervention.

A beeping sound may be heard in some cases, particularly when a RAM module is missing. The booting process, on the other hand, moves on to the next stage if the expected hardware is present and working properly.

Step 2: The Bootloader (GRUB2)

The BIOS probes the MBR (Master Boot Record) for the bootloader and disk partitioning information once the POST is complete and the coast is clear.

The MBR is a 512-byte code found on the first sector of a hard drive, which is usually /dev/sda or /dev/hda depending on the hard drive architecture. It’s worth noting, however, that the MBR can sometimes be found on a Linux Live USB or DVD installation.

LILO, GRUB, and GRUB2 are the three main types of bootloaders in Linux. The GRUB2 bootloader is the most recent and primary bootloader in modern Linux distributions, which informs our decision to skip the other two, which have become obsolete over time.

The GRand Unified Bootloader version 2 is abbreviated as GRUB2. The BIOS executes and loads the grub2 bootloader onto the main memory once it has been found (RAM).

A Basic Guide to Linux Boot Process

You can do a few things with the grub2 menu. It enables you to choose which Linux kernel version you want to use. If you’ve upgraded your system a few times, you might notice that different kernel versions are listed. It also allows you to change some kernel parameters by pressing a combination of keys on your keyboard.

The grub menu also allows you to choose which OS to boot into in a dual-boot setup with multiple OS installations. /boot/grub2/grub2.cfg is the GRUB2 configuration file. The main goal of GRUB is to load the Linux kernel into the main memory.

Step 3: Kernel Initialization

The process ID or PID of 1 is assigned to Init, which is always the first program to be executed. The init process is responsible for spawning various daemons and mounting all partitions specified in the /etc/fstab file.

A Basic Guide to Linux Boot Process

After that, the kernel mounts the initial RAM disk (initrd), which serves as a temporary root filesystem until the real root filesystem is mounted. All kernels, as well as the initial RAM disk image, are stored in the /boot directory.

Step 4: Starting Systemd

Systemd, which replaces the old SysV init, is finally loaded by the kernel. Systemd is the mother of all Linux processes, and it is responsible for a variety of tasks such as mounting file systems, starting and stopping services, and so on.

The /etc/systemd/system/default.target file is used by Systemd to determine which state or target the Linux system should boot into.

The default target value for a desktop workstation (with a GUI) is 5, which is the same as run level 5 in the old SystemV init.

The default target for a server is multi-user.target which corresponds to run level 3 in SysV init.

Here’s a simple breakdown of the 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.

Further, to check out the current target on your system, run the command:

$ systemctl get-default

By typing the following command into the terminal, you can switch from one target to another:

$ init runlevel-value

Init 3 sets the system to a non-graphical state, for example.

The init 6 command restarts your computer, while init 0 turns it off. When switching between these two targets, make sure to use the sudo command.

Once systemd has loaded all of the daemons and set the target or run level value, the booting process is complete. You’ll be prompted for your username and password at this point, and you’ll gain access to your Linux system.

Posted by
Make Tech Quick

Make Tech Quick is your trusted source for the latest insights in tech and gaming. We deliver quick, reliable updates and expert tips to keep you informed and ahead of the curve.

Leave a Reply

Your email address will not be published. Required fields are marked *