How a Computer Boots: Step-by-Step Guide


The booting process in a Linux-based system involves six steps: BIOS, MBR, GRUB, Kernel, Init, and Runlevel programs. It begins with the BIOS performing a power-on self-test and proceeds to load the Master Boot Record (MBR), which is responsible for loading the bootloader like GRUB. GRUB manages kernel selection before the Kernel takes over, mounting the root filesystem and executing the /sbin/init program. The system then executes Init to determine run levels using systemd, followed by the execution of runlevel programs applicable to the system's configuration. These programs manage various system services, starting and stopping them based on the runlevel.
The process that starts right after we power on a computer or laptop and continues until we reach the user interface (where we can interact with the system) is called the booting process in a Linux-based system.
Although it seems simple and quick task, it involves altogether 6 steps as follows:
BIOS
Basic Input- Output system .This is first step when in power on the system. This step involves POST which is nothing but power on self test where system checks the proper functioning of it’s peripheral parts like HDD or SSD.
Once it is done, BIOS goes ahead for searching , loading and executing MBR (Master Boot Record). It is generally present on USB stick or CD ROM [like we do live installation of Linux]
Once boot loader is detected , it gets loaded into main memory and all control is passed over that.
MBR
This whole thing is almost about 512 bytes in which 1) primary boot loader info in 1st 446 bytes 2) partition table info in next 64 bytes 3)validation check in last 2 bytes.
MBR is only responsible for loading and executing boot loader like GRUB or LILO(the older Linux loader LILO didn’t understand filesystem).
MBR is mainly present as first part of any bootable disk which is typically /dev/hda
, or /dev/sda
, depending on your hardware.
GRUB
Grand Unified Bootloader is used in most modern linux systems. If system has more than one os / flavors of linux [kernel images] then GRUB splash screen is first screen that we are able to view in our system, which basically ask to select the one you want your system to boot with. By default, the latest kernel image is selected.
This screen wait for you to select option up to default set time. (The waiting period of this splash screen can be managed through runconfig followed by boot section )
So, in simple terms GRUB just loads and executes Kernel and initrd images.
KERNEL
It is core of any OS, including Linux . It has complete control over everything in your system.
In this stage of the boot process, the kernel that was selected by GRUB first mounts the root file system that's specified in the grub.conf
file. Then it executes the /sbin/init
program, which is always the first program to be executed. [We can confirm this with its process id (PID), which should always be 1]
The kernel then establishes a temporary ( It also contains necessary drivers compiled inside, which helps it to access the hard drive partitions, and other hardware) root file system using initrd (Initial RAM Disk)until the real file system is mounted.
INIT
At this point, your system executes runlevel programs. At one point it would look for an init file, usually found at /etc/inittab
to decide the Linux run level.
Modern Linux systems use systemd to choose a run level instead. Different run levels available out their are as follows :
Run level 0 is matched by poweroff.target (and runlevel0.target is a symbolic link to poweroff.target*).*
Run level 1 is matched by rescue.target (and runlevel1.target is a symbolic link to rescue.target*).*
Run level 3 is emulated by multi-user.target (and runlevel3.target is a symbolic link to multi-user.target*).*
Run level 5 is emulated by graphical.target (and runlevel5.target is a symbolic link to graphical.target*).*
Run level 6 is emulated by reboot.target (and runlevel6.target is a symbolic link to reboot.target*).*
Emergency is matched by emergency.target*.*
systemd will then begin executing runlevel programs.
6. Runlevel programs
Depending on which Linux distribution you have installed, you may be able to see different services getting started. For example, you might catch starting sendmail …. OK
.
These are known as runlevel programs, and are executed from different directories depending on your run level. Each of the 6 runlevels described above has its own directory:
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 that the exact location of these directories varies from distribution to distribution.
If you look in the different run level directories, you'll find programs that start with either an "S" or "K" for startup and kill, respectively. Startup programs are executed during system startup, and kill programs during shutdown.
There are numbers right next to S and K in the program names. Those are the sequence number in which the programs should be started or killed.
For example, S12syslog is to start the syslog deamon, which has the sequence number of 12. S80sendmail is to start the sendmail daemon, which has the sequence number of 80. So, syslog program will be started before sendmail.
Subscribe to my newsletter
Read articles from Anushka Bhujang Pawar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
