LINUX BOOT PROCESS- HOW IT EXECUTES
Linux Boot Process
Basically “Boot Process” A CPU gets its instructions from memory. The CPU reads instruction from the BIOS and searches for the hard disks, CD drives and other hardware. The BIOS program looks at the first sector for boot code.
The boot process for Linux goes through several stages. Different systems follows different stage here in Linux have 6 stages of Boot.
- BIOS ( Basic Input/Output System )
- MBR ( Master boot Record )
- GRUB ( Grand Unified Boot Loader )
- run level ( init 0 — init 6 )
BIOS : The term BIOS stands for “Basic I/O System”, It looks for boot loader in CD Rom, hdd, or other boot-able media. Once the boot loader is detected and loaded into memory, BIOS gives the control to it.
So in simple terms we can say that “BIOS loads and executes the MBR boot loader “
MBR : The term MBR stands for “Master boot records” it is located in the first sector of the boo-table disks like /dev/hda or /dev/sda , And it has three component and MBR is less than or equal to 512 Bytes in size
- Primary boot loader info in 1st 446 bytes
- Partition table info in next 64 bytes.
- MBR validation check in last 2 bytes.
so, we can say that, MBR loads(Boot info) and execute the GRUB boot loader.
GRUB : As mention above the term GRUB stands for “Grand unified boot loader” , if we have multiple images installed on our system we can choose one to be execute, GRUB display a splash screen, waits for few seconds, if you don’t enter or press anything, it loads the default Kernel image as specified in the GRUB Configuration file,
/boot/grub/grub.com "it is link with" /etc/grub.conf
- in Red Hat Linux
/boot/grub/grub.cfg "it is link with" /etc/default/grub
- in ubuntuB loads.
So, GRUB loads, it configuration file ( for BIOS system /boot/grub/grub.conf, for UEFI System /boot/efi/EFI/redhat/grub ) and Kernel into System memory. As we will in configuration file, it contains Kernel & initrd image. So in simple terms GRUB just loads and execute Kernel & initrd images.
Kernel : The term Kernel is the core of an operating system which provides access to services and hardware. So the boot loader loads one or multiple “initramfs images” into system memory. [ initramfrs: initial RAM Disk], The kernel use “initramfs”to read drivers and needed modules for booting the system. And it mount the “root file system” as specified in the ‘root=(GRUB configuration file).
So we can say that, After the kernel & initramfs image are loaded, control of the boot process goes through kernel. The kernel now initializes and configure memory and contacted hardware and kernel execute the the /sbin/init program ## since ‘init’ was the 1st program to be executed by linux kernel. It has the process id (PID) of 1 , we can check through command “ ps -ef | grep init “.
init : During this process, the system locates the root partition and file system. Both are checked and mounted then the system start the init process. Which runs the initialization scripts invoking different scripts in the “/etc/rc*.d “ directory. so we can say that init execute run level program.
so init execute the Run level program (init 0- init 6) depend on the default init level settings, system will execute. Look at the /etc/init tab following are the available run level “/etc/init.d/rc.*d”
- init 0 “Halt” /etc/rc.d/rc0.d
- init 1 “Single user mode” /etc/rc.d/rc1.d
- init 2 “Multi user mode without NFS” /etc/rc.d/rc2.d
- init 3 “Multi user mode with NFS” /etc/rc.d/rc3.d
- init 4 “unused” /etc/rc.d/rc4.d
- init 5 “X11- GUI mode” /etc/rc.d/rc5.d
- init 6 “Reboot” /etc/rc.d/rc6.d
Typically we would set the default run level to either init 3 or init 5
Run level : When the Linux System booting up, Those are the run level programs execute from the run level directory or defined by your run level directory.
Under the /etc/rc.d/rc*.d / directories, you would see program that start with S & K.
Program start with S are used during startup S for startup, K for kill.
…….I would love to hear your own experiences in the comments below. Please share your Valuable feedback.
This post are published here. @linux_point