Boot Process Stages in Linux

Photo of author

By Vijay Singh Khatri

Starting up a Linux computer is as easy as turning a book’s page. One only presses the power button, and within a few moments, the system is turned on and ready to use. But have you ever wondered what occurs behind the scenes during the booting process? A user needs to know what happens during the booting process to prevent any booting errors in the future. In this article, we seek to inform you of what happens in the background during the boot process in Linux.

Stages of the Boot process in Linux

Typically, a boot process in Linux goes through the below six stages:

1. BIOS

The first stage is the BIOS. The term “BIOS” signifies “Basic Input/Output System.” First, the BIOS performs a few system integrity checks. Then, it looks for, loads, and executes the boot loader program. The BIOS searches for the boot loader on a hard drive, CD-ROM, or floppy disk. FYI, you can change the boot sequence while the BIOS startup is happening by simply pressing a key like F2 or F12 (it varies depending on the system you’re using). After BIOS has finished detecting and loading the boot loader programme into memory, it transfers control to that program.In other words, the Basic Input/Output System loads and implements the MBR boot loader.

2. MBR

Next, we have the MBR. The term “MBR” is an abbreviation of “Master Boot Record.” You can easily find it in the first sector of your bootable disk, that is, usually either /dev/sda or /dev/hda. The size of the Master Boot Record is less than 512 B. In case you didn’t know, MBR is made up of three components: the first 446 B contains the primary boot loader information, and the following 64 B and 2 B of space contain the partition table information and MBR validation check, respectively.MBR also contains information about GRUB (or LILO in older systems).Therefore, it is evident that MBR loads and implements the next boot loader, that is, GRUB.

3. GRUB

As you can see, MBR makes way for grub. “GRUB” is short for “Grand Unified Bootloader.” Now, if you have installed numerous kernel images on your system, you will be capable of picking the one you wish to execute. You will see a splash screen during this stage. The splash screen will stay for a few moments and proceed to load the default kernel image defined in the GRUB configuration file, that is, /boot/grub/grub.conf (it has a link called etc/grub.conf), in case you enter nothing. Plus, the Grand Unified Bootloader (GRUB) has a broad understanding of the filesystem. This places GRUB in direct contrast to LILO, the default Linux loader on older PCs, which didn’t quite know about the filesystem. Here, we will provide you with a sample of grub.conf as seen in CentOS:

#boot=/dev/sda

default=0

timeout=5

splashimage=(hd0,0)/boot/grub/splash.xpm.gz

hiddenmenu

title CentOS (2.6.18-194.el5PAE)

root (hd0,0)

kernel /boot/vmlinuz-2.6.18-194.el5PAE ro root=LABEL=/

initrd /boot/initrd-2.6.18-194.el5PAE.img

As you can see from the above instance, it comprises kernel and initrd images. So, it becomes clear that GRUB makes way for the upcoming kernel and initrd images as well as loads and executes them.

4. Kernel

Next, we have the kernel. As some of you might already know, the kernel is responsible for mounting the root file system according to what’s defined in “root” within grub.conf. It is also responsible for the execution of the /sbin/init program. Now, as the Linux kernel implements the programme called init first, it possesses 1 as the PID, or process ID. You can check this process ID by simply performing a ‘ps -ef | grep init.’ For your information, the term “initrd” means “Initial RAM Disk” and it is utilised by the kernel as an interim root file system during the mounting process of the actual root file system. It also comes equipped with numerous crucial drivers that aid it in accessing the hard drive partitions as well as various other pieces of hardware.

5. Init

After the kernel comes init. It is responsible for taking a look at the /etc/inittab file and determining which level to run Linux at. Below are the available levels that Linux can be run at:

  • 0 means halt.
  • 1 means single-user mode.
  • 2 means multiuser mode lacking the Network File Sharing protocol.
  • 3 means full multiuser mode
  • 4 means unused
  • 5 means X11
  • And finally, 6 stands for a reboot.

After it’s over, systemd will start implementing the runlevel programs.

6. Runlevel programs

Based on your installed Linux distribution, you will see various services start. As of now, there are six runlevels that have their own directories:

  • 0 – /etc/rc0.d/
  • 1 – /etc/rc1.d/
  • 2– /etc/rc2.d/
  • 3  – /etc/rc3.d/
  • 4 – /etc/rc4.d/
  • 5 – /etc/rc5.d/
  • 6 – /etc/rc6.d/

However, you have to remember that the actual location of these directories might vary based on your distribution. Also, remember that the programmes inside these directories beginning with an “S” mean “startup” and a “K” means “kill.” The former programmes are executed during system startup and the latter during shutdown.

Conclusion

As you can see, the boot process in Linux passes through six key stages before the system fully starts up. The first stage is BIOS, which executes the MBR boot loader. MBR then makes room for it, as well as loads and executes GRUB.GRUB does its thing perfectly, followed by loading and implementing the kernel and initrd images. After the kernel and init are done performing their duties, systemd begins executing the runlevel programs.

Depending on the Linux distribution that is installed on your PC, you may see disparate services getting started. And, with that, the boot process in Linux comes to an end, and the system starts up with the login screen. Once you provide your login credentials, it is ready to be used. As we mentioned at the beginning of the article, knowing about this entire booting procedure makes you capable of solving any booting errors with efficacy if they ever appear. If you are unaware of what’s happening behind the scenes when you turn your system on, you won’t be able to comprehend what went wrong.

Leave a Comment