Boot Process in Linux

Hello Geeks, Boot Process in Linux is very important topic and a Linux System administrator must know all the steps in the boot process to fix and troubleshoot boot issues.
From powering on the machine till the time we get the login prompt, it goes through several steps. Below info-graphic shows the high-level steps during the boot process.



High Level Steps of Boot Process in Linux 
Now let us see all the steps of boot process in detail

BIOS

Basic Input/Output System or simply BIOS is the first stage of the boot process. BIOS is stored in the ROM of the motherboard of the system and it is always executed regardless of the operating system installed. BIOS performs the POST – Power-on self-test to detect, initializes and test the connected hardware. POST ensures that all the connected hardware is working fine. Once done with the POST part, next task that BIOS does is to determine the bootable device like cd-rom, hard-disk, USB drive etc. Once BIOS finds a valid bootloader device, it gives control to the first sector of the bootable device or simply loads the master boot record (MBR).

Master Boot record: 

MBR is the first sector of bootable device and it is of 512 bytes. 512 bytes of MBR are divided into three parts.


446 bytes of bootloader that is knows as GRUB, 64 bytes contains the partition table info and 2 bytes for MBR Validation check used for error detection. MBR loads the GRUB2 boot loader into memory and transfers control to it.

GRUB2 bootloader

GRUB2 is default bootloader used from RHEL 7 onwards, replacing the legacy grub of earlier versions. GRUB stands for Grand Unified Boot Loader



Grub menu during boot process

Grub 2 configuration file is located at /boot/grub2/grub.cfg and it takes menu configuration settings from another file that is /etc/default/grub
/boot/grub2/grub.cfg  < Config file >
/etc/default/grub  < Menu Configuration settings >
GRUB2 searches for the compressed kernel image “vmlinuz” in the /boot directory and loads the “vmlinuz” content into memory and extracts the content of initramfs image into a temporary file system (tmpfs)

Kernel

The function of kernel is to handle and control all the Operating system processes and like memory management, input output devices, task scheduling. Kernel starts the first process that is systemd with pid of 1.
You can check using top command or ps -ef | grep systemd
   1 root      20   0   51788   3912   2496 S   0.0  0.0   5:06.62 systemd
Initrd or initial RAM disk is used to temporarily mount the root file system before the real root file system is mounted. initramfs (Initial RAM file system)  preloads the required block device modules like SCSI, RAID to load the actual file system. Once real file system is mounted, initrd is unmounted.

Systemd

Systemd  (d at the end refers to daemon – processes that runs in background ) reads from /etc/systemd/system/default.target to determine the target. Systemd replaces the init process found in the older versions 
Example of /etc/systemd/system/default.target
Description=Multi-User System
Documentation=man:systemd.special(7)
Requires=basic.target
Conflicts=rescue.service rescue.target
After=basic.target rescue.service rescue.target
AllowIsolate=yes
To find out current target of the system
[root@Master ~]# systemctl get-default
multi-user.target
To set the default target run below command
systemctl set-default type.target
multi-user.target:  refers to run level 3 
graphical.target: refers to run level 5

systemd targets

RunlevelTarget UnitsDescription
0runlevel0.target, poweroff.targetShut down and power off the machine
1runlevel1.target, rescue.targetSet up a rescue shell/mode
2runlevel2.target, multi-user.targetNon-graphical multi-user system.
3runlevel3.target, multi-user.target Non-graphical multi-user system.
4runlevel4.target, multi-user.targetNon-graphical multi-user system.
5runlevel5.target, graphical.targetGraphical multi-user system.
6runlevel6.target, reboot.targetReboot the system.
systemctl is used for all the service management like service start, stop, enable, disable tasks.
That’s all for the Linux Boot process, i hoped you have understood all the steps during the Linux boot process. Feel free to comment below your thoughts regarding this post.