Understand step by step how RHEL6 system boots. Walk through of RHEL6 boot process which lists all the tasks, activities happens during boot.
Anyone starting to learn Linux must know boot process of Linux. Here is this post I will be explaining boot process of Red Hat Enterprise Linux 6 i.e. RHEL6. In brief RHEL6 boot process can be summarized as below :
- Powered on system loads boot loader once it completes POST. Boot loader in turns load GRUB.
- GRUB loads kernel into memory which further loads necessary modules and mount root partition as read only.
- Kernel invokes /sbin/init program and hand it over boot process.
- Init program loads all services as per run level and mount mount points
- User is presented with login screen.
Lets see each point in detail to understand RHEL6 boot process properly.
1. Power on and boot loaders:
Whenever system turned on, it runs POST (Power on self test) to check all hardware and its operating state. Once POST is cleared, system runs BIOS. BIOS is basic input output system which is lowest level interface for hardware. BIOS gets loaded in memory and checks system, connected peripherals, boot device path. Lastly, BIOS will load first sector of bootable disk in memory which is MBR master boot record. Once MBR loaded, BIOS hand over boot control to it.
MBR is small machine code which has first stage boot loader. First stage or stage-1 boot loader exist to locate second stage boot loader and load it in memory only. Second stage or stage-2 boot loader is GRUB. Now boot control is with GRUB.
In UEFI based systems, BIOS is replaced by UEFI. Its much powerful than BIOS. It has its own architecture, cpu, device drivers. It can mount and read file systems. Such systems has EFI partitions which has EFI’s own boot loaders which can loads operating systems or stage-2 boot loaders.
GRUB displays list of available kernels to user in graphical interface (like below). Its configuration file is /boot/grub/grub.conf (for BIOS) or /boot/efi/EFI/redhat/grub.conf (for UEFI). Here user can select its kernel to boot using arrow keys and press enter. If not then it will boot default selected kernel when selection time pass out. We can even reset forgotten root password in this screen.
Once GRUB destined to load kernel, it search kernel binary of it under /boot partition. The boot loader then places one or more appropriate initramfs (Initial RAM file system) images into memory (as seen in above screenshot). The initramfs is used by the kernel to load drivers and modules necessary to boot the system. Once kernel and initramfs is loaded into memory, boot control is taken by kernel.
Once kernel gets boot control, it quickly run though below tasks:
- Initialize and configure memory, hardware and attached peripherals.
- Decompress initramfs into /sysroot and loads necessary drivers from it
- Loads virtual devices related to file system like LVM etc.
- Free up memory by removing initramfs image
- Create root device, mount root partition (readonly)
Now, kernel is fully loaded and operational. But no services loaded in system yet so system is not usable for humans. To load rest of the services kernel calls /sbin/init program and hand it over boot process to him.
4. Init program :
/sbin/init i.e. init process spaws very first in system with PID 1 and it will be parent process for many system processes or zombie/defunct processes all the time. Init executes and calls various scripts as below :
- Runs /etc/rc.d/rc.sysinit to start swap, set environment, FS checks and some system initialization steps.
- Process jobs in /etc/event.d directory which has run level specific settings
- Set function library /etc/rc.d/init.d/functions
- Runs background processes from their respective rc directories. Default specified in /etc/inittab. e.g. for run level 3 it will executes /etc/rc.d/rc3.d/ . Mostly rc directories are having symbolic links of start/stop services.
- Once all processes started in specified run level, init finishes and spaws login screen.
5. Login screen:
Once init completes loading RC directories, it forks Upstart which in turns call /sbin/mingetty. mingetty will be forked for each virtual console. Run level 1 i.e. single user mode has 1 while run level 2 to 5 has 6 virtual consoles. /sbin/mingetty starts communication with tty devices, sets terminal modes, prints login screen (with messages if any) and prompt username to user!
This completes RHEL6 boot process from power up to login prompt!