Boot process of Linux in brief.
Today we will look at the Linux Boot process in brief.
A. Boot Process in Short
Hardware power ON --> BIOS --> POST --> Hard Drive First 512 Bytes --> MBR GRUB --> Initramfs ---> Kernel --> Init/Systemd --> Runlevel/Targets
B. Boot Process in Brief: From GRUB Onwards
Explanation
1. When we press the power button on our CPU or ATX board, the system first detects the BIOS(i.e. Basic Input Output system) which runs POST(Power On Self Test).
2. POST checks/scans all hardware attached to system and transfers the control to first boot device in its settings.
3. If hard drive is selected as First Boot Device, then system will look for its Sector 0 i.e. first sector.
4. Sector 0 contains MBR or Master Boot Record which contains stage 1 of GRUB i.e. Grand Unified Boot Loader.
5. Stage 1 has boot.img file of 512 bytes which is first loaded and stage 2 is loaded on 63 sectors(range 1-62) which is responsible to load stage 2 i.e. /boot/grub files.
6. Once GRUB is loaded, then INITRD or INITRAMFS is loaded on system memory which is responsible to load system kernel.
7. System kernel then loads on INITRD i.e. on initial RAM Disk and then detects the system hardware, and loads the OS services.
8. Once OS is loaded in system RAM, the filesystem is mounted on hard drive by dracut(also called switching root).
9. Once root is switched, kernel starts the first process of the system i.e. init or systemd.
10. Init or systemd is responsible to load runlevel scripts/milestone scripts to start system services in order.