Linux Tutorial

Linux File/Directory Management

Linux Packaging And Compression

Vim Text Editor

Linux Text Processing

Linux Software Installation

Linux User/User Group Management

Linux Permission Management

Linux Filesystem Management

Linux Advanced Filesystem Management

Linux System Management

Linux Backup and Recovery

Linux System Service Management

Linux System Log Management

Linux Boot Management

LAMP/LNMP Environment

SELinux Management

Linux Bootloader (GRUB) Loads The Kernel

In this tutorial, we'll explain how the GRUB bootloader loads the Linux kernel during the boot process. The boot process is a critical phase in starting up a Linux system, and understanding it can help you troubleshoot issues or customize the boot process.

  • BIOS/UEFI Initialization

When you power on your computer, the BIOS (Basic Input/Output System) or UEFI (Unified Extensible Firmware Interface) initializes the hardware, including the CPU, memory, and storage devices. It then searches for a bootloader in the configured boot device.

  • Loading the GRUB Bootloader

Once the BIOS/UEFI finds the bootloader (GRUB in this case), it loads the first stage of GRUB into memory. GRUB then locates and loads the second stage, which contains the GRUB menu and additional modules.

  • GRUB Menu and Configuration

The GRUB menu is generated based on the configuration file, usually located at /boot/grub/grub.cfg. This file contains a list of available kernels, initramfs (initial RAM filesystem) images, and their respective locations on the filesystem. It also contains settings such as timeout, default boot entry, and theme.

  • Loading the Linux Kernel and Initramfs

When you select a Linux kernel from the GRUB menu (or the default kernel is automatically selected), GRUB loads the kernel and the associated initramfs image into memory. The initramfs is a small, self-contained filesystem containing essential drivers and scripts required for mounting the actual root filesystem.

  • Kernel Initialization

Once the kernel and initramfs are loaded into memory, the kernel starts executing and initializes the system hardware, memory management, and various kernel subsystems. It then extracts the initramfs into a temporary RAM-based filesystem (tmpfs) and executes the /init script inside the initramfs.

  • Mounting the Root Filesystem

The /init script in the initramfs is responsible for mounting the actual root filesystem. If the filesystem is encrypted or requires specific drivers, the initramfs will take care of unlocking the encryption or loading the necessary drivers.

  • Switching to the Root Filesystem

After mounting the root filesystem, the initramfs hands over control to the actual root filesystem by performing a "pivot_root" operation. This switches the currently active root filesystem from the initramfs to the real root filesystem.

  • Executing Init Process

Finally, the kernel starts the first userspace process, which is usually the init process (e.g., systemd, SysVinit, or Upstart). The init process takes care of initializing the rest of the system, including starting services, mounting additional filesystems, and configuring devices.

In summary, the GRUB bootloader plays a crucial role in the Linux boot process by loading the kernel and initramfs into memory and starting the kernel initialization process. Understanding this process can help you diagnose boot issues, customize your system's boot behavior, or work with different kernel versions.