Booting refers to the process of starting up your computer and can be initialized by pressing a hardware button or through a software command. You see, when the CPU is turned on, it doesn’t have access to any software in its main memory. The boot process loads the necessary software, so you’re computer can launch the operating system.
For this read, we will be going in-depth into understanding the Linux boot process and why it’s essential to know how it works.
Note: Depending on the operating system you use, the boot process will be slightly different. We will mention where you will find differences along the course of the article.
How Knowing The Linux Boot Process Can Help You?
Let’s say you sit with your PC, get ready to start work (or game), and hit the power button on the CPU. But what’s this? Your computer is not turning on, and it’s making some weird beeping noises.
Well, in this situation, you can either call a technician, which means you will need to wait at least a couple of hours to get the issue fixed, and it’s going to cost you money. Or you can fix it yourself – but to do this, you will need a thorough understanding of the boot process.
Here are some scenarios in which knowing the Linux boot process can help you out:
- You can’t power on your computer at all.
- Your computer is turning on, but you only see a blank screen.
- The computer is stuck in a boot loop – it’s powering on and turning off in a loop.
- The operating system is not loading up.
By understanding the Linux boot process, you can quickly diagnose and troubleshoot what is wrong with your system and then fix it.
Besides this, knowing the boot process will also let you customize it. This will help you to gain control over your PC at a much more fundamental level.
The Linux Boot Process
The Linux boot process, or any other boot process for that matter, is a sequence of events that eventually leads to loading up your PC so that you can access the operating system. Now, in Linux, there are six distinct stages to the boot process. These are as follows:
- Runlevel Programs
We will go over these six stages in detail to understand how your computer boots up.
Note: There are some exceptions to this 6 stage boot process. Some Linux distros prefer to offer their customized booting sequence. That being said, what we will be discussing here has been historically used with Linux and is still used by many major Linux distros.
BIOS is short for Basic Input Output System. When you boot up your computer, the BIOS gets called, and it runs some integrity checks to see if your HDD or SSD are working correctly.
After this, the BIOS will search for the boot loader program, load it to memory, and then execute it. The boot loader program is found inside the MBR – Master Boot Record.
Now, the MBR doesn’t necessarily need to be loaded inside the HDD or SSD. Sometimes it can be on a USB stick or CD-ROM, which is used during a live installation of Linux. After loading the boot loader program to memory, the BIOS will then hand over control to it, and we move on to the next step of the boot process.
As we just discussed above, MBR is short for Master Boot Record. It contains information about the GRUB or LILO in the case of very old systems.
The function of the MBR is to load and execute the GRUB boot loader to continue the boot process.
The MBR is located in the 1st sector of the bootable disk. You can typically find this under /dev/hda, or /dev/sda. This location is mostly hardware-dependent – whether you are booting from an HDD, SSD, Pendrive, or CD.
GRUB, often called the GNU GRUB (GNU Grand Unified Bootloader), is the primary boot loader for most modern Linux systems.
When powering on your PC, the first thing that you see is the GRUB splash screen. It stays on screen momentarily and displays a simple menu with a couple of options. In case you have multiple kernel images installed on your system, you will see them on this menu.
You can then use your keyboard (mouse not supported) to select the kernels you want your system to boot with.
The latest kernel will be selected by default. If no action (i.e., you don’t select any kernel with the keyboard), the system will automatically boot into the default kernel.
Depending on which Linux distro you are using, and how old it is, the location of the GRUB file can vary. You are most likely to find it under /boot/grub/grub.conf or /etc/grub.conf.
Here is a quick look at the sample content of a grub.conf file.
default=0 timeout=10 splashimage=(hd0,0)/grub/splash.xpm.gz # section to load Linux title Red Hat Enterprise Linux (2.4.21-1.ent) root (hd0,0) kernel /vmlinuz-2.4.21-1 ro root=/dev/sda2 initrd /initrd-2.4.21-1.img # section to load Windows title Windows rootnoverify (hd0,0) chainloader +1
Note: In case you are not able to find the location of the grub.conf file on your system, you can search the documentation of your Linux distro, or run a google search, and it should give you the file location.
To learn more about the functions of the grub.conf file, you can read this article.
After selecting the kernel with which you want to boot your system, we move onto the next stage.
In short, a kernel is the core of the Linux operating system (as well as other OSes) and has complete control over everything in the system.
Once the GRUB selects the kernel, it will mount the root file system that has been specified in the grub.conf file. After it has been mounted, the kernel will execute the /sbin/init program.
This is always the first program that is executed during system boot-up. You can confirm this by checking the process id (PID) for this program, which will always be set to 1.
Next, until the real file system is mounted, the kernel will create a temporary root file system by using Initial RAM Disk – initrd. This hardly takes a second or two.
The system is now ready to start executing the run level programs. It will first need to access the init file, usually located under this path – /etc/inittab. This file is necessary to decide the Linux run levels.
That being said, most of the modern Linux systems have moved to “systemd” to choose the run level instead. Here is a detailed article to help you understand “systemd.”
#6. Runlevel Programs
The run level programs change from one Linux distribution to another. As such, depending on the Linux distro you are using, you might see a completely different batch of run level programs getting started.
Each of the run levels has their directories, and the programs specific to the run levels lies under the corresponding directory. As such, run level programs correspond to an earlier directory will be executed first, followed by the rest in ascending order.
The following are the usual list of directories that correspond to the six different run levels:
- Run level 0 – /etc/rc0.d/
- Run level 1 – /etc/rc1.d/
- Run level 2 – /etc/rc2.d/
- Run level 3 – /etc/rc3.d/
- Run level 4 – /etc/rc4.d/
- Run level 5 – /etc/rc5.d/
- Run level 6 – /etc/rc6.d/
Note: Exact location of directories will vary depending on your Linux distro. If you cannot find the run-level directories, check with the OS documentation, or do a quick search on Google.
You can go through the different programs located under the run level directories and find that some of the programs start with a “K” or an “S.” Here the K signifies “Kill,” and S represents “Start.” The “Start” programs are executed during the system startup process, whereas the “Kill” programs are executed during system shutdown.
So this was a quick look at the Linux boot process. By now, you should have a rudimentary understanding of how your system goes through 6 different stages before you get access to your OS and the desktop.
We hope you found this helpful, and in case you have any issues, you can leave your questions down in the comments section, and we will get back to you as soon as possible.
Until then, if you are starting with Linux, we have tons of beginners guide, how-tos, and tutorials on Linux, to help you better understand the OS and start working more proficiently with it.