top of page
  • Writer's pictureMahammad Rafi

Linux Boot Process

Updated: Jan 24, 2019




 

The Linux Boot Process (LBP)

54-Steps

 

Part I- “Power ON” to “Loading Kernel”


Overview of Part1:

Step 1- When we power on PC, BIOS (which is stored on Motherboard) loads into RAM. The purpose of BIOS is load OS or Kernel into RAM.


Step 2- BIOS search for Bootable Device. When bootable device found goes to next step


Step 3- When bootable device found it loads 1 stage Boot Loader i.e. MBR in RAM. Size of MBR is just 512 bytes. Just first sector of Hard disk.


Step 4- First stage boot loader loads Second stage boot loader i.e. GRUB or LILO.


Step 5- When second stage boot loader gets executed in RAM, Splash Screen gets displayed. Job of second stage boot loader is to load kernel in RAM.

Step 6- Stage 2 boot loader loads Kernel and optional initial Root File System into RAM. It passes control to Kernel and kernel get decompressed into RAM and get initialized. At this stage second stage boot loader checks Hardware and mount root device also loads necessary kernel modules. When it completes first User space program gets executed i.e. [init.] init is father of all processes.

-------------------------------------------------------------------------------------------------------------------------------

Detail Part-1 process:


Step 1- BIOS boots up

01. Power On

When we power on PC, BIOS (which is stored on Motherboard) loads into RAM.


02. ROM - BIOS loaded into RAM auto by the boot code at the start of ROM

[Bootstrap] Interrupt 0

Note: The purpose of BIOS is load OS or Kernel into RAM.

BIOS are made up of two parts: The POST code and Runtime services.

After the POST is complete, it is flushed from memory, but the BIOS runtime services remain and are available to the target operating system.


Step 2- BIOS boots up contd

03. POST (Power On Self-Test) - HW Inventory - Int 19H


04. CMOS - [Current bootable devices]

Here, to boot an operating system, the BIOS runtime searches for devices that are both active and bootable in the order of preference defined by the complementary metal oxide semiconductor (CMOS) settings.


05. BIOS loads/starts [boots] whatever it finds in the first Sector [Sect 1] of HDD into RAM i.e. [cylinder 0, head 0, sector 1 of a hard disk]

- This first Sector is aka the MBR [on Windows-based systems]

Note: There is only one MBR per HDD, obviously!!

[Remember! In fdisk -l, we had seen one sector is 512 bytes]


06. What is this MBR?

Int 13 fn 8 --> "Get drive parameters"

Int 13 fn 2 --> "Read sectors from drive"

0x228*

<=========x=================== 512 bytes ========================>

| |

<-----446 bytes ---->| <--PT -64 bytes-> | < Magic no 2 bytes--->

Boot Sector (BS) |Partition Table (PT) | Magic #

| |

<============================ 512 bytes ========================>

M B R

<------ BS ---------> [fdisk /mbr]

DNF: Backing up the MBR to floppy with dd

NOTE: Magic No. The magic number serves as a validation check of the MBR.


Step 3- MBR loads into RAM

* If the POST is successful, the BIOS calls INT 19H

  • INT 19H is to load the sector at head 0, cylinder 0, sector 1 i.e. MBR of Hard disk into memory at 0:7C00h and transfer control to it.

  • After MBR gets loaded into RAM, BIOS handover control to it.

  • It loads First Stage Boot Loader which resides in MBR

* ntldr + sda1 A [Active] ok [first slice]

CHS# of Win Kernel

[KRNL386.EXE]


Step 4- Stage 1 Boot Loader loads into RAM

Boot Loader (BL) for Linux kernel "1st stage BL" or IPL [Initial Program Loader] After installing Linux, 7 items are put in the boot sector of the MBR: 2 are binaries (denoted by a *) and 5 are CHS no’s pointing to files on the HDD.

B. /boot/grub/stage1*:

CHS# a. /boot/grub/splash.xpm.gz sda2 extended

b. /boot/grub/stage2 sda5 /boot

c. /boot/vmlinuz-2.6.18-194.el5 sda6 /home

d. /boot/initrd-2.6.18-194.el5.img sda7 swap

e. /boot/grub/grub.conf sda8 /

sda9 /tmp

sda10 /var

sda11 /usr


07. BIOS then loads/executes [boots/runs] this first stage BL - which is

stage1* [i.e. /boot/grub/stage1*] which is in the BS of the MBR and put There at install time this is called the 1st stage of boot loading – FSBL.


08. This first-stage BL has but one purpose in life:

To load the 2nd stage BL - SSBL - /boot/grub/stage2* How?

Stage2* is in /boot/grub/stage2*, which is a drive AND a partition, so how can it access stage2* from the partition when it does not have the driver (all in /dev) to access the /boot partition?

-->>It needs the /boot partition driver - but all drivers are in /dev so it will have to go to /dev dir to get /boot's driver.

But /dev dir, where all the drivers are, is in / partition, So it will need the driver of the / partition, to access stage2*.

But to get into the / partition, it will need the driver of the / partition, which is in /dev.

How can it go into the / partition when the driver of the / partition is in / itself!!! And to get to the /dev dir it will need the driver of the / partition which it does not have.


Hence, we have a Hen and Egg situation.

“No Egg no Hen, no Hen no Egg.”

So how do we access files on the disk when we have no drivers???

-->> By taking the help of Papa, Of Course!!! That is the BIOS!


09. Makes BIOS calls - Int 13 fn 8 --> "Get drive parameters" and -

Int 13 fn 2 --> "Read sectors from drive" -


10. The FSBL then requests the BIOS for an Int 13 fn 2, gives it the CHS # of the SSBL - /boot/grub/stage2* Isn't BIOS working like a driver - (which actually /dev/sda? of

/boot/grub/stage2* should be doing??


11. BIOS loads this 2nd stage BL - from the CHS no. supplied by the 1st stage into the RAM, executes it and hands over control to it. BIOS now retreats into high RAM, away from the action, leaving the stage (pun sorry)and audience to stage2*.



Step 5- Stage 2 Boot Loader & Kernel

12. The 2nd-stage BL now loads the contents of the balance of the BS

Into the RAM

And what is that?

c. CHS # of the file /boot/vmlinuz-2.6.18-194.el5 and

d. CHS # of the file /boot/initrd-2.6.18-194.el5

Which were in the BS of the MBR - put there by anaconda at Install time?


13. -The 2nd stage BL now examines this binary-format-BS which contains "grub.conf" and follows the instructions given there!!

-It requests BIOS for an Int 13h and gives it the CHS # of the /boot/grub/splash.xpm.gz file which BIOS promptly fetches and the 2nd stage BL executes - This is the splash screen Isn't BIOS working like a driver once again!


14. The 2nd stage BL then executes the instructions it got from the BS after the 1st stage had loaded it, and executes those instructions.

  • # grub.conf generated by anaconda

  • #

  • # Note that you do not have to rerun grub after making changes to this file

  • # NOTICE: You have a /boot partition. This means that

  • # all kernel and initrd paths are relative to /boot/, eg.

  • # root (hd0,1)

  • # kernel /vmlinuz-version ro root=/dev/sda6

  • # initrd /initrd-version.img

  • #boot=/dev/sda

default=0

timeout=30

splashimage=(hd0,1)/grub/splash.xpm.gz

hiddenmenu

title RHEL 5.5 Server (2.6.18-194.el5)

root (hd0,1)

kernel /vmlinuz-2.6.18-194.el5 ro root=LABEL=/ rhgb quiet

initrd /initrd-2.6.18-194.el5.img

title WinXP SP2

rootnoverify (hd0,0)

chainloader +1


15. After timing out AND IF the default image is the Linux kernel, and IT IS in the case above, the 2nd stage boot loader - /boot/grub/stage2* - loads the Linux kernel in RAM.


16. Now what is a Boot Loader?

-->Boot Loader load "kernel images" into memory and hand control of the CPU over to the newly loaded kernel [/boot/vmlinuz-2.6.18-194.el5].

To make your new kernel work, you must tell the BL about the kernel.


17. Now the 2nd-stage wishes to load the kernel, as instructed by the binary-format grub.conf, which is in the BS of the MBR, after timing out or whatever the user chooses.


18 The 2nd stage BL now needs to give the CHS# of the Linux Kernel for the BIOS to fetch.

"After all that's where the big BOSS is - The Linux Kernel [/boot/vmlinuz-2.6.18-194.el5]! "


19. The 2nd stage BL once again requests BIOS - Int 13h fn 2 - and hands it the CHS # of the kernel - /boot/vmlinuz-2.6.18-194.el5 file, which BIOS fetches and loads.


20. The 2nd stage BL uncomptars this file and fills the memory with kernel memory structures which can be seen in the /proc virtual file system.

"The Engine Of The Car Is Ready And Running!! "

The Linux OS is ready and running!! Kernel Land is ready!!

BUT WE FORGOT TO MAKE THE CAR PROPER ITSELF!! No User land!!

How do we drive this car if there is no seat, steering wheel Nothing Just an engine?

25 views0 comments
bottom of page