Wise people learn when they can; fools learn when they must - Arthur Wellesley

Sunday, 3 March 2019

RHEL6-46– BOOT PROCESS



                            RHEL6-46– BOOT PROCESS  
RHEL 6:

Have you ever thought what happen in between you switch on the power button and prompted for username/password?  


The tasks ran behind are collectively termed as BOOT PROCESS,

It starts after pressing power button,


Once you press the power button, power goes to SMPS (Switching Mode Power Supply), here SMPS converts the AC power to DC power and sends the required voltage to all components.
Then the CPU searches for BIOS (Basic Input Output System) in ROM (Read only Memory).

Now BIOS is BOSS, it runs POST (power on self-test). POST is device integrity check where all the attached hardware functionality is checked. If BIOS found POST run is OK, then only it will proceed for next step. [in case any issue with any device BIOS will alarm us by beep codes via system speaker (different beep count having different meaning, can be obtained from OEM device manuals).

Let’s assume everything is fine and POST run is confirmed OK, now BIOS will search for BOOTLOADER, by looking in to the boot device setting. Which is generally HDD, when we have to do installation or some troubleshooting then we change the boot order and make CD/DVD as primary, and say we altered BIOS setting!!!

Right?

Exactly as expected… ☹☹ WRONG…

We did not altered BIOS (because bios can only be flashed by manufacturer),
so, what we did?
We change the setting of CMOS (complementary metal-oxide-semiconductor)

CMOS is sometimes referred to as Real-Time Clock (RTC), CMOS RAM, Non-Volatile RAM (NVRAM), Non-Volatile BIOS memory, or complementary-symmetry metal-oxide-semiconductor (COS-MOS).

For better understanding of CMOS, please refer following link.

(Thanks to Tim for valuable share)

Hence correcting the sentence, BIOS will look to CMOS for primary boot device (it can be CD/HDD/FLOPPY/USB). Let’s consider its HDD.
Now Primary boot disk is identified; hence BIOS will travel to first sector (also called Boot sector) of HDD (512 bytes) to find BOOTLOADER which is MBR (Master Boot Record).

MBR is first part of boot loader (The first 446 bytes are reserved for program code. The next 64 for a partition table for up to four partitions. The last two bytes must contain a special magic number (AA55). An MBR containing a different number would be considered invalid by the BIOS and any PC operating system.)

Once MBR detected, BIOS will load it to RAM and say bye to all. Now MBR which is first part boot loader will scan partition table [which partition is configured as bootable] to find default stage 2 boot loader which is GRUB (Grand Unified Boot Loader).
*some part of grub is in MBR

Now GRUB is loaded into RAM with help of primary boot loader, GRUB loads the file system drivers. Once file system drivers are loaded, it will read the /boot/grub/grub.conf to find the details about kernel path and initrd/initramfs (Initial RAM disk) path.

it presents the user with a graphical screen showing the different operating systems or kernels it has been configured to boot.

Kernel is small in size and purpose of kernel is to prepare an environment for all programs to run, but due to its smaller size it could not even contain necessary drivers. So, to overcome this issue a temporary root file system is provided to kernel called initrd. initrd is used by kernel to load several modules before actual root FS is mounted.

**initramfs is successor of initrd and serve the same purpose as initrd.

Now the Kernel (vmlinuz version, an executable bzImage file) & initrd/initramfs are loaded in to memory.

Kernel decompresses in memory and swapper or process 0 is started and the page tables are initialized and memory paging is enabled. The type of CPU is also detected.

During boot of kernel, initrd helps kernel to boot with full potential without mounting any physical partition means all drivers are loaded in to memory and now kernel is booted.
Now root FS is mounted as RO and kernel starts the first process PID1 called init, also called parent of all processes.

init process reads /etc/inittab to confirm the default run level and loads all necessary daemons depending upon the run level, lets say its 5 then init will go to /etc/rc.d/rc5.d/ and start/kill services depending upon the notation (S/K) on that. And mounts all FS listed under /etc/fstab, here RO root partition is remounted as RW according to direction in fstab.


Let’s summarize the Boot Process…


           Power On
           ||
Power goes to SMPS- which further distributed required voltage to   all attached components.
||
Now BIOS activated itself from ROM, it (BIOS) runs POST and searches for primary boot device info in CMOS (assume it is HDD)
||
Now BIOS will travel to sector 1 (512 Bytes) of HDD to find 1st part bootloader i.e. MBR. [446=bootloader, 64=Partition info,6=Magic no]
||
MBR is loaded in to memory by BIOS and it was last performance of BIOS. MBR reads partition table for any bootable flag to find stage 2 bootloader which is GRUB
||
Now GRUB is loaded in to memory and it loads file system drivers to read /boot/grub/grub.conf which contains info about kernel and initrd.
||
Both are loaded in to memory
||
Kernel decompresses itself and start booting (meanwhile swapper process PID 0 is started)
||
During boot of kernel, initrd helps kernel with various required drivers. Now all required drivers are loaded along with required kernel modules and kernel is booted in full potential.

||
Now kernel mounts root file system (RO) and starts process 1 i.e. init

||
init reads /etc/inittab for default run level and loads all necessary daemons depending upon the run level defined in inittab and mounts all file systems as per /etc/fstab.    

2 comments: