🐧 Basic guide to the Linux boot process

Every time you turn on your Linux computer, it goes through a series of steps before finally displaying a login screen that asks for your username or password.

There are 4 different stages that each Linux distribution goes through in its typical boot process.

🐧 Basic guide to the Linux boot process

In this guide, we’ll highlight the various steps that Linux takes from power on to login.

Note that this guide only takes into account the GRUB2 boot loader and systemd init, as they are currently used by the vast majority of modern Linux distributions.

The download process consists of the following 4 steps, which we will discuss in more detail:

  • BIOS Integrity Check (POST)
  • Loading the bootloader (GRUB2)
  • Kernel initialization
  • Starting systemd, the parent of all processes

1. BIOS Integrity Check (POST)

The boot process is usually initiated when the user presses the power button – if the computer has already been turned off – or reboots the system using a graphical interface or command line.

When Linux is powered on, BIOS (Basic Input / Output System) powers up and performs a power-on self test – Power on self test (POST).

It is an integrity check that performs a variety of diagnostic checks.

POST checks the health of hardware components such as hard or solid state drive, keyboards, RAM, USB ports and any other hardware.

If a hardware device is not found, or if any of the devices is malfunctioning, such as a damaged hard drive or solid state drive, an error message appears on the screen prompting you to intervene.

In some cases, a beep sounds, especially if there is no RAM module.

However, if the expected hardware is present and functioning as expected, the boot process continues to the next step.

2. Boot loader (GRUB2)

After POST completes, the system checks the MBR (Master Boot Record) for bootloader and disk partition information.

MBR is a 512-byte code located in the first sector of a hard drive, usually / dev / sda or / dev / hda depending on your hard drive architecture.

Please note, however, that sometimes the MBR may be on a Live USB or Linux DVD.

There are 3 main types of boot loaders in Linux: LILO, GRUB, and GRUB2.

The GRUB2 boot loader is the latest and main boot loader in modern Linux distributions.

GRUB2 stands for GRand Unified Bootloader version 2.

As soon as the BIOS detects the grub2 bootloader, it starts up and loads it into main memory (RAM).

The grub2 menu allows you to do several things.

It allows you to select the Linux kernel version you want to use.

If you have updated your system several times, you may see different kernel versions listed.

In addition, it gives you the ability to edit some kernel parameters by pressing the keyboard shortcut.

🐧 Basic guide to the Linux boot process

Also, on dual-boot systems, when you have multiple OSes installed, the grub menu allows you to choose which OS to boot into. The grub2 config file is a file /boot/grub2/grub2.cfg.

The main purpose of GRUB is to load the Linux kernel into main memory.

3. Kernel initialization

Kernel is the core of any Linux system.

It connects PC hardware to basic processes.

The kernel controls all processes on your Linux system.

Once the selected Linux kernel is loaded by the bootloader, it must self-extract from the compressed version before performing any task.

After self-extracting, the kernel of choice mounts the root filesystem and initializes the / sbin / init program, usually called init.

🐧 Basic guide to the Linux boot process

Init is always executed by the first program and assigned a process ID or PID 1.

This is an init process that spawns various daemons and mounts all partitions specified in / etc / fstab.

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

All kernels are located in the / boot directory along with the initial RAM disk image.

4.starting Systemd

Finally, the kernel loads Systemd, replacing the old SysV init.

Systemd is the mother of all Linux processes and manages, among other things, mounting filesystems, starting and stopping services, just to name a few of its responsibilities.

Systemd uses the /etc/systemd/system/default.target file to determine the state or level at which the Linux system should boot.

  • For a desktop workstation (with a graphical user interface), the default target is 5, which is equivalent to runlevel 5 for the old SystemV init.
  • For the server, the default is multi-user.target, which corresponds to runlevel 3 in SysV init.

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

$ systemctl get-default

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

$ init runlevel-value

For example, init 3 puts the system in a non-graphical state.

Init 6 reboots your system, and init 0 shuts down your system.

Be sure to use the sudo command when you want to switch to these two levels.

The boot process ends when systemd has loaded all daemons and set the target or runlevel value.

It is at this point that you will be prompted for a username and password, after which you will be able to access your Linux system.

Sidebar