Abhinav Jha
Abhinav's Blog


Abhinav's Blog


The Linux Booting Process Explained 🐧

Abhinav Jha's photo
Abhinav Jha
Β·Sep 13, 2022Β·

5 min read

The Linux Booting Process Explained 🐧
Play this article

Table of contents

  • The Linux boot process is divided into six high-level stages:
  • Stage 1: BIOS
  • Stage 2: MBR
  • Stage 3: GRUB
  • Stage 4: Kernel
  • Stage 5: Init
  • Stage 6: Runlevel

When you press the system's power button, you will see the login screen on your screen and the system will begin working.

Have you ever wondered what happens between pressing the power button and seeing the login screen show up?

For any operating system, there is a boot process that is executed one by one until you reach the operating system's login screen.

In this blog, we'll go through the Linux boot process step by step.

The Linux boot process is divided into six high-level stages:

β€’ BIOS – Basic Input / Output System executes MBR

β€’ MBR – Master Boot Record execute GRUB

β€’ GRUB – Grand Unified Bootloader executes Kernel

β€’ Kernel – Kernel executes /sbin/init

β€’ Init – Init executes runlevel programs

β€’ Runlevel – Runlevel programs are executed from /etc/rc.d/rc*.d/

Stage 1: BIOS

BIOS is an abbreviation for Basic Input/Output System. In layman's terms, the BIOS's responsibilities are to locate and execute a boot loader (GRUB, LILO) program.

When you initially power on your computer, the BIOS examines the HDD or SSD for integrity.

The BIOS then searches for, loads, and runs the boot loader program stored in the Master Boot Record (MBR). The MBR is sometimes kept on a USB stick or CD-ROM, such as during a live Linux installation.

When the boot loader program is detected, it is loaded into memory and the BIOS gives it control of the computer.

Stage 2: MBR

MBR is an abbreviation for Master Boot Record. It's responsibility is to load and run the GRUB boot loader.

MBR is found in the first sector of the bootable drive. In most cases, /dev/had or /dev/sda.

MBR is 512 bytes in size and consists of three components. The primary boot loader information is stored in the first 446 bytes. The next 64 bytes include partition table information. The last two bytes contain an MBR validation check.

In older systems, the MBR also stores information about GRUB, or LILO.

Stage 3: GRUB

GRUB is an abbreviation for Grand Unified Bootloader.

It contains all information about the operating system image that will be loaded and executed.

If you have more than one operating system, all of them will be listed in this GRUB file, and you can choose which one to use as the default.

On system boot, GRUB displays a splash screen and waits for user input to select an operating system; if you do not type anything, it loads the default kernel image supplied in the grub configuration file.

Grub is familiar with your operating system's filesystem.

The GRUB configuration file can be found in "/boot/grub/grub.conf

Stage 4: Kernel

The kernel is frequently referred to as the heart of every operating system, including Linux. It has complete control over your entire system.

During this stage of the boot process, the GRUB-selected kernel initially mounts the root file system defined in the grub.conf file. Then it runs the /sbin/init program, which is always the first one to run. This is confirmed by its process id (PID), which should always be 1.

The kernel then uses Initial RAM Disk (initrd) to create a temporary root file system until the real file system is mounted.

Stage 5: Init

At this moment, your system executes runlevel applications. To determine the Linux run level, it would look for an init file, normally found at /etc/inittab.

Instead, modern Linux systems use systemd to select a run level. The Linux operating system includes seven (7) different run levels.

β€’ 0 – halt

β€’ 1 – single-user mode

β€’ 2 – Multiuser, without NFS

β€’ 3 – Full multiuser mode

β€’ 4 – unused

β€’ 5 – X11

β€’ 6 – reboot

Init will examine and identify the default initlevel from the file "/etc/inittab" in order to load all appropriate programs for the run level.

You may determine your system's default run level by running the following command:

$ grep initdefault /etc/inittab

Stage 6: Runlevel

There is only one default run level; it will execute all essential programs for that run level.

The system will examine and execute run-level programs from the folders listed below:

β€’ Run level 0 – /etc/rc.d/rc0.d/

β€’ Run level 1 – /etc/rc.d/rc1.d/

β€’ Run level 2 – /etc/rc.d/rc2.d/

β€’ Run level 3 – /etc/rc.d/rc3.d/

β€’ Run level 4 – /etc/rc.d/rc4.d/

β€’ Run level 5 – /etc/rc.d/rc5.d/

β€’ Run level 6 – /etc/rc.d/rc6.d/

It should be noted that the actual location of these directories vary from distribution to distribution.

You'll find programs that begin with a "S" or "K" for startup or kill in the various run level directories.

Startup programs are run during system startup, and kill programs on system shutdown.

This information should be sufficient to help you understand the Linux booting process.

That's all! Thank you for getting this far. I hope you find this thread useful.

Thank you for readingπŸ€— If you have come this far, don't forget to follow & react to this blog.

If you ❀️ My Content! Connect with me on Twitter (akj0712)

Show your support by buying me a coffee

Buy Me A Coffee

My other digital presence:

More Content at akj07.hashnode.dev

Your feedback are more than welcome

Did you find this article valuable?

Support Abhinav Jha by becoming a sponsor. Any amount is appreciated!

See recent sponsors |Β Learn more about Hashnode Sponsors
Share this