Step by Step Linux Boot Process
The stages involved in Linux Booting Process are:
This is the first thing which loads once you power on your machine.
When you press the power button of the machine, CPU looks out into ROM for further instruction.
The ROM contains JUMP function in the form of instrucion which tells the CPU to bring up the BIOS
BIOS determines all the list of bootable devices available in the system.
Prompts to select bootable device which can be Hard Disk, CD/DVD-ROM, Floppy Drive, USB Flash Memory Stick etc.
Operating System tries to boot from Hard Disk where the MBR contains primary boot loader.
To be very brief this phase includes loading of the boot loader (MBR and GRUB/LILO) into memory to bring up the kernel.
MBR (Master Boot Record)
It is the first sector of the Hard Disk with a size of 512 bytes.
The first 434 – 446 bytes are the primary boot loader, 64 bytes for partition table and 6 bytes for MBR validation timestamp.
NOTE: Now MBR directly cannot load the kernel as it is unaware of the filesystem concept and requires a boot loader with file system driver for each supported file systems, so that they can be understood and accessed by the boot loader itself.
To overcome this situation GRUB is used with the details of the filesystem in /boot/grub.conf and file system drivers
GRUB (GRand Unified Boot loader)
What is GRUB boot Loader ?
On a Red Hat Linux system, the boot loader’s function is to locate the Linux Kernel, and any other necessary files, and load them into memory. It then starts the kernel so that the kernel can run processes.
The boot loader also lets you to control how a system is booted. If you dual boot, a boot loader enables you to choose between operating systems at startup.
When a computer boots, the basic input/output system (BIOS) in read only memory usually loads the boot loader from the Master Boot Record (MBR) on the system’s primary hard drive.
What are the stages involved in loading GRUB?
Most boot loaders execute in two or more stages. GRUB loads itself into memory by
1. loading the stage 1 boot loader
First the BIOS reads the stage 1 or primary boot loader into memory from the MBR.
The primary boot loader takes up less than 512 bytes of disk space in the MBR – too small a space to contain the instructions necessary to load a complex operating system.
Instead the primary boot loader performs the function of loading either the stage 1.5 or stage 2 boot loader.
2. loading the stage 1.5 boot loader
Some hardware requires an intermediate step between the stage 1 and stage 2 boot loaders.
This can happen when the /boot partition is situated beyond the 1024 cylinder head of the hard drive, or when you are using LBA mode.
GRUB Stage 1.5 is located in the first 30 KB of Hard disk immediately after MBR and before the first partition.
This space is utilised to store file system drivers and modules.
This enabled stage 1.5 to load stage 2 to load from any known loaction on the file system i.e. /boot/grub
3. loading the stage 2 boot loader
The secondary boot loader is located somewhere on the disk – on the boot sector of the first partition.
For Example it displays the GRUB menu and command environment, which enables you to select which operating system or Linux kernel to boot.
You can also use it to pass arguments to the kernel.
4. loading the operating system or kernel
GRUB determines which operating system to start and loads the operating system or kernel and initrd into memory.
It then transfers control of the computer to the OS.
GRUB also supports Logical Block Addressing (LBA) mode which enables the computer to find the /boot files more easily, particularly if they are located beyond the 1024th cylinder of the hard drive.
This can be considered the heart of operating system responsible for handling all system processes.
Kernel is loaded in the following stages:
Kernel as soon as it is loaded configures hardware and memory allocated to the system.
Next it uncompresses the initrd image (compressed using zlib into zImage or bzImage formats) and mounts it and loads all the necessary drivers.
Loading and unloading of kernel modules is done with the help of programs like insmod, and rmmod present in the initrd image.
Unmounts initrd image and frees up all the memory occupied by the disk image.
Then kernel mounts the root partition as specified in grub.conf as read-only.
Next it runs the init process.
What is Linux Kernel?
It acts as an interpreter between Linux OS and its hardware. It is the fundamental component of Linux OS and contains hardware drivers for the devices installed on the system. The kernel is a part of the system which loads first and it stays on the memory.
Executes the system to boot into the run level as specified in /etc/inittab
A no. of runlevel scripts are defined inside /etc/rc.d/rcx.d
Based on the selected runlevel, the init process then executes startup scripts located in subdirectories of the /etc/rc.d directory.
Scripts used for runlevels 0 to 6 are located in subdirectories /etc/rc.d/rc0.d through /etc/rc.d/rc6.d, respectively.
Lastly, init runs whatever it finds in /etc/rc.d/rc.local (regardless of run level). rc.local is rather special in that it is executed every time that you change run levels.
Next if everything goes fine you should be able to see the Login Screen on your system.