It is important to understand the linux boot process to troubleshoot boot problems. The post describes the high level steps in the boot process. Below flow chart describes basic boot stages and what happens during each boot stage.
1. BIOS (or firmware phase)
– The BIOS (Basic Input/Output System), performs the POST (power on self test) to detect, test and initialize system hardware components.
– Loads the MBR (Master boot record).
2. Master boot record (MBR)
– Master Boot Record (MBR) is the first 512 bytes of the boot drive that is read into memory by the BIOS.
– The next 64 bytes contain the partition table for the disk. The last two bytes are the “Magic Number” which is used for error detection.
– MBR discovers the bootable device and loads the GRUB2 boot loader into memory and transfers control over to it.
3. GRUB2 Bootloader
– The default bootloader program used on RHEL 7 is GRUB 2. GRUB stands for GRand Unified Bootloader. GRUB 2 replaces the older GRUB bootloader also called as legacy GRUB.
– The GRUB 2 configuration file is located at /boot/grub2/grub.cfg (Do not edit this file directly).
– GRUB 2 menu-configuration settings are taken from /etc/default/grub when generating grub.cfg.
– Sample /etc/default/grub file :
# cat /etc/default/grub GRUB_TIMEOUT=5 GRUB_DEFAULT=saved GRUB_DISABLE_SUBMENU=true GRUB_TERMINAL_OUTPUT="console" GRUB_CMDLINE_LINUX="rd.lvm.lv=rhel/swap crashkernel=auto rd.lvm.lv=rhel/root rhgb quiet net.ifnames=0" GRUB_DISABLE_RECOVERY="true"
– If changes are made to any of these parameters, you need to run grub2-mkconfig to re-generate the /boot/grub2/grub.cfg file.
# grub2-mkconfig –o /boot/grub2/grub.cfg
– GRUB2 searches the compressed kernel image file also called as vmlinuz in the /boot directory.
– GRUB2 loads the vmlinuz kernel image file into memory and extracts the contents of the initramfs image file into a temporary, memory-based file system (tmpfs).
– The initial RAM disk (initrd) is an initial root file system that is mounted before the real root file system.
– The job of the initial RAM file system is to preload the block device modules, such as for IDE, SCSI, or RAID, so that the root file system, on which those modules normally reside, can then be accessed and mounted.
– The initramfs is bound to the kernel and the kernel mounts this initramfs as part of a two-stage boot process.
– The dracut utility creates initramfs whenever a new kernel is installed.
– Use the lsinitrd command to view the contents of the image created by dracut:
# lsinitrd | less
– The kernel starts the systemd process with a process ID of 1 (PID 1).
root 1 0 0 02:10 ? 00:00:02 /usr/lib/systemd/systemd --switched-root --system --deserialize 23
– systemd is the ancestor of all processes on a system.
– systemd reads the file linked by /etc/systemd/system/default.target (for example, /usr/lib/systemd/system/multi-user.target) to determine the default system target (equivalent to run level). The system target file defines the services that systemd starts.
systemd brings the system to the state defined by the system target, performing system initialization tasks such as:
1. Setting the host name
2. Initializing the network
3. Initializing SELinux based on its configuration
4. Printing a welcome banner
5. Initializing the system hardware based on kernel boot arguments
6. Mounting the file systems, including virtual file systems such as the /proc file system
7. Cleaning up directories in /var
8. Starting swapping
CentOS / RHEL 7 : Begginners guide to systemd targets (replacement of SysV init run levels)