Last Updated:

Linux boot process

Have you ever been interested in the different stages of booting an operating system? What happens when you turn on your computer?

The stages of the Linux boot process can be divided into:

  •  Boot BIOS (POST).
  •  The first stage of the download (MBR or GPT).
  •  The second boot phase (GRUB2).
  •  Initialize the kernel.
  •  Initialize the main process (init or systemd).
  •  Runlevels.

Now we will consider them.

BOOT BIOS (POST)

 

A BIOS (short for "Basic Input/Output System") is low-level software (firmware) stored on a small memory chip on your computer's motherboard. It facilitates the process of starting the computer, and also controls the flow of data between it and other devices connected to the computer, such as: mouse, printer, monitor, etc. When you press the power button, the BIOS is first initialized, which begins to search for a boot device to start the operating system.

If the BIOS initialization process and the boot device search are successful, the computer emits one beep and then another when the system is ready to boot the operating system. This stage is called POST (short for "Power-O n Self-T est" - self-testing at power-on). POST checks the health of the system hardware and finds the boot sector that contains the software needed to continue the boot process. POST is performed by programs included in the BIOS.

You can use the function keys (F1-F12) in BIOS mode to set the boot priority of devices, adjust computer hardware settings, or restore default computer settings. In the BIOS menu, you will find the BIOS version number, the name of the BIOS vendor, your processor type, and other detailed system information.

Linux boot

The boot menu in the BIOS (Boot Manager) is a list from which you can select the operating system to boot. If you have multiple Linux or other operating system distributions installed on your computer, you can add them to the boot menu. The last installed OS will be shown at the top of the Boot Manager.

In the following picture, you can see that Ubuntu and Windows are installed on my computer. I can select any operating system (from the available ones) to download.

Boot Manager

First stage of download (MBR or GPT)

 

 

 

The loaders of the first stage include MBR (abbreviated from "Master Boot Record") and GPT (abbreviated from "Guided Partition Table"). The MBR contains a partition table of the disk and is located in the first sector of the boot disk, usually /dev/hda or /dev/sda, depending on your hardware. The main task of the MBR is to "move" to the partition of the disk from which you need to execute further code to boot the operating system.

As soon as the MBR detects the boot loader of the second stage, it transfers control to it.

Note: It is worth noting that now more and more often instead of MBR more modern technology is used - GPT.

Second Boot Phase (GRUB2)

The task of the boot loader of the second stage is to find the kernel of the system and load it into memory.

Most Linux distributions use GRUB (short for "GRand Unified Bootloader") or GRUB2 (as a more modern one) as a boot loader. Since GRUB2 is a newer version of GRUB, this is the version you will see in most cases when you boot your computer. This bootloader has a simple menu where you can select the boot options. If you have several different cores installed, you can use the keyboard to choose exactly the kernel you want to boot your system with:

The configuration files for the GRUB boot loader are usually /boot/grub/grub.conf or /etc/grub.conf. As soon as the boot loader finds the kernel, it loads it into RAM and gives it further control.

Note: Previously, Linux distributions used primarily the LILO boot loader (short for "LInux LOader"). But to date, it has been completely supplanted by the more modern GRUB.

 

Kernel Initialization

 

 

 

Most new Linux users believe that Linux is an operating system. But Linux is really the kernel. The kernel is often referred to as the heart of the operating system. It plays a very important role in the Linux boot process. The Linux kernel is located in the /boot directory and is responsible for the interaction between the main components of the computer and the operating system.

Since the kernel is compressed to save hard disk space, the first thing it will do as soon as it gains control is to perform its "self-unpacking". Then mount the image of the root file system specified in the grub.cfg file and start the system initialization process.

Linux kernel files

Initialize the main process (init or systemd)

The kernel, immediately after its boot, starts the main initialization process, which leads to the launch of all necessary services and programs. These services will continue to work after initialization and will manage the main system processes, such as: registering various system messages, tracking devices and ensuring synchronization of the file system with system memory.

init system

Note: In the SysV init system, the main process is the init process, and in the systemd init system, the systemd process is the (eponymous) systemd process.

 

Runlevels

 

 

 

The runlevel is the immediate state of the operating system (for example, when Linux has completed the boot process and is ready to use) in which you can control power settings, user mode, and the entire environment. When the system moves to the appropriate execution level, messages from the main initialization process will continue to appear on the screen. The standard Linux kernel supports seven different levels of execution:

   Runlevel 0 - Shuts down the system.

   Runlevel 1 is a single-user mode. It is most commonly used for maintenance and other administrative purposes. This level can also be called Runlevel S (from the English "Single-user"). If you've ever had to reset a password on Linux, you've probably already used this mode.

   Runlevel 2 is a multi-user mode with no support for network services.

   Runlevel 3 is a multiplayer mode with network support, but without a graphical interface. Most often, server versions of Linux run at this level of execution.

   Runlevel 4 - Not used. The user can customize this level based on their goals.

   Runlevel 5 is similar to Mode 3, but this is where the GUI starts. Desktop versions of Linux work in this mode.

   Runlevel 6 - Reboots the system.

NoteOn Debian family systems, the execution levels are slightly different. For example, Ubuntu in command line mode starts with run-level 5.

During the Linux boot process, the execution-level state is represented by alphanumeric code. If you look at the screenshot below, you'll see that my current execution level is ; this means that my computer has already completed the boot process, and is running in multi-user mode with a graphical interface.N 5

You can find out the current run-level mode by using the following command:

sudo runlevel

 

If for any reason you need to change the execution level, you can do so with the following command:

sudo telinit [номер_уровня]

Conclusion

This tutorial is only a general overview of the Linux boot process, however, for beginners it should already make an understanding of what happens to the Linux system when you press the power button on the computer.