Friday 10 January 2014

Short description of Linux Boot Process

I am describing in short about Linux boot process.

Linux boot process steps.

1.  After running POST, BIOS executes code in first sector i.e. 512 bytes of hard disk. Note that BIOS drivers are used to access hard disk. This sector is known as boot sector. Out of these 448 bytes are used by actual boot loader code and remaining 64 bytes are reserved for partition table. Note that each partition table entry corresponds to  16 bytes of memory. So that's why we can have only 4 primary partitions on hard disk.

2.  Boot loader code can be saved in ROM and some embedded systems do this but in typical Linux box it is on hard disk.

3.  Job of this 448 bytes of boot sector code is to handle basic functionality of boot loader and pass control to actual boot loader code. This activity is normally termed as second stage of boot loader. Please note every partition has boot sector at its beginning.

4. Now this code is responsible to actually display boot loading options to user and load kernel. I multiple OS are installed on machine then this code might defer us to different active partition depending on choice made to load OS in boot loader GUI. Then boot loader of other OS is loaded. This process is knows as chain loading.

5. Note that vmlinuz and initrd needs to loaded in order to proceed. Addresses of these files are hard coded and they are always under /boot directory. All contents of /boot are saved contiguous to boot loader on hard disk.

6. Now which one is used first...?  vmlinuz is first uncompressed and init command is executed. It then mounts initrd image as initial root file system which contains basic set of modules needed to mount actual root file system.

7. Then again control is taken by init process and linuxrc is executed in the end.