As a user, when you press the power button of system, you get the login screen on your monitor and after login starts working.
Have you ever think what is going between you press power button and login screen appear?
There is a boot process for any operating system which executed one-by-one, and finally, you get the Operating system’s login screen.
Here we go through the Linux boot process stage-by-stage.
There are six high-level stages for Linux boot process:
• 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 stands for Basic Input/Output System. BIOS responsibilities are to search boot loader (GRUB, LILO) program to load and execute it.
BIOS search boot loader into a floppy, CD-rom, or hard drive. You can change the boot sequence from BIOS setup during BIOS startup.
When the boot loader program found and loaded into the memory, BIOS gives the control it. So, BIOS use to loads and execute the MBR boot loader.
Stage 2: MBR
MBR stands for Master Boot Record.
MBR located into the 1st sector of the bootable drive. Generally, /dev/had, or /dev/sda.
MBR stores in 512 bytes in size, there are three components of MBR.
• Primary boot loader information stored in 1st 446 bytes
• Partition table information stored in the next 64 bytes
• MBR validation check stored in the last 2 bytes.
MBR stored information about any boot loader; in our case, it is having information about GRUB boot loader.
In short MBR loads and executes the GRUB boot loader.
Stage 3: GRUB
GRUB stands for Grand Unified Bootloader.
It stores all information about operating system image to load and execute.
If you have more than one operating system, all entry will be in this GRUB file, and you can choose to make the default one.
GRUB display splash screen on system boot and wait for few seconds to get user input to choose the operating system, if you don’t enter anything, it loads the default kernel image as specified in the grub configuration file.
Grub has the knowledge of the filesystem in your operating system.
You can find the GRUB configuration file at “/boot/grub/grub.conf,” the sample of file grub.conf is shown below:
As you can see in the file, it has information of kernel and initrd image.
In simple term GRUB loads and executes Kernel and initrd images.
Stage 4: Kernel
When kernel loads, it mount the root file system and execute /sbin/init program. As init was the first program run by the Linux kernel, it has one(1) as process id (PID), which you can check by using below command:
The initrd stands for Initial RAM Disk.
Stage 5: Init
It checks file “/etc/inittab” to decide the Linux run level.
There are seven(7) run levels available with the Linux operating system:
• 0 – halt
• 1 – single-user mode
• 2 – Multiuser, without NFS
• 3 – Full multiuser mode
• 4 – unused
• 5 – X11
• 6 – reboot
Init will check and identifies the default initlevel from file “/etc/inittab” to load all appropriate program required for the run level.
You can check your system’s configured default run level by executing below command:
Stage 6: Runlevel
One default run level identified; it will execute all required program for that run level.
The system will check and execute run level programs from the following directories:
• 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/
There is symbolic linked directory also available in “/etc” directory, /etc/rc0.d is linked to /etc/rc.d/rc0.d and so on.
You can check all program under the directory /etc/rc.d/rc*.d/ which is starting with S and K.
The program which starts with S used during startup. S stands for the startup.
The program which starts with K used during shutdown. K stands for Kill.
You can see a number in the name after S or K which are the sequence number in which programs should be started or killed.
These are the 6 stages which are happening behind the screen when you power on the system.