Linux Boot Process
In this blog we will discuss how a computer boots that is how a computer with Linux operating system boots. Understanding the boot process, will help you understand how the hardware and software is working together, and also give you the required information to begin troubleshooting a booting problem you have.
The Boot Process
Below are the basic stages of the boot process for an x86 system:
BIOS stand for Basic Input/Output System
Performs some system integrity checks
Searches,loads,and executes the boot loader program.
It looks for boot loader in floppy, cd-rom, or hard drive. You can press a key (typically F12 of F2, but it depends on your system) during the BIOS startup to change the boot sequence.
Once the boot loader program is detected and loaded into the memory, BIOS gives the control to it.So, in simple terms BIOS loads and executes the MBR boot loader.
MBR stands for Master Boot Record.
It is located in the 1st sector of the boot able disk.Typically/dev/hdaor/dev/sda
MBR is less than 512 bytes in size. This has three components:
- Primary boot loader information in 1st 446 bytes
- Partition table information in next 64 bytes
- MBR validation check in last 2 bytes.
- It contains information about GRUB (or LILO in old systems). So, in simple terms MBR loads and executes the GRUB boot loader.
GRUB stands for Grand Unified Bootloader.
If you have multiple kernel images installed on your system,you can choose which one to be executed.
GRUB displays a splash screen, waits for few seconds, 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 (the older Linux loader LILO didn‘t understand filesystem).
Grub configuration file is/boot/grub/grub.conf(/etc/grub.conf is a link to this).
The following is sample grub.conf of RHEL-OS.
title Red Hat Enterprise Linux (2.6.32-194.el6)
kernel /boot/vmlinuz-2.6.32-194.el6 ro root=LABEL=/
As you notice from the above info, it contains kernel and initrd image.So, in simple terms GRUB just loads and executes Kernel and initrd images.
Mounts the root file system as specified in the ―root=‖ in grub.conf
Kernel executes the/sbin/init program
Since init was the 1st program to be executed by Linux Kernel,it has the process id(PID) of 1.
initrd stands for Initial RAM Disk.
initrd is used by kernel as temporary root filesystem until kernel is booted and the real root file system is mounted. It also contains necessary drivers compiled inside, which helps it to access the hard drive partitions, and other hardware.
Init identifies the default init level from/etc/init tab and uses that to load all appropriate programs.
Execute ̳grep init default /etc/init tab‘ on your system to identify the default run level
Typically you would set the default run level to either 3 or 5.
Depending on your default init level setting,the system will execute the programs from that run level.
Under the /etc/rc.d/rc*.d/ directories, you would see programs that start with S and K
For example, S12syslog is to start the syslog deamon, which has the sequence number of 12.
S80sendmail is to start the send mail daemon, which has the sequence number of 80. So, syslog program will be started before send mail.