Linux boot process and Grub2 Fundas

Highlevel boot stages:-

  1. The machine’s BIOS or boot firmware loads and runs a boot loader.
  2. The boot loader finds the kernel image on disk, loads kernel into memory and starts it. 
  3. The kernel initializes the devices and its drivers. 
  4. The kernel mounts the root filesystem.
  5. The kernel starts a program called init with a process ID of 1. This point is the user space start.
  6. init sets the rest of the system processes in motion. 
  7. init starts a process allowing you to log in, usually at the end or near the end of the boot sequence.

Running journalctl -k displays the messages from the current boot, but you can view previous boots with the -b

grub2 supports various filesystems like Linux ext2/ext3/ext4, LVM ,btrfs, zfs etc.(reference) with the help of its own drivers. GRUB2 disk drivers are essential for the boot loader's functionality. They allow GRUB2 to access configuration files, such as the grub.cfg file, which contains important boot configuration parameters. Additionally, the disk drivers enable GRUB2 to locate and load the kernel image, initial RAM disk (initrd), and any other necessary boot files.

To determine if your system uses a BIOS or UEFI, run command efibootmgr. If you get a list of boot targets, your system has UEFI otherwise its bios.

GRUB2 uses its own set of drivers to enable communication with various hardware components during the boot process. These drivers are specifically designed for GRUB and are responsible for tasks such as reading the filesystem, accessing storage devices, and interacting with input/output devices. GRUB2 drivers are typically lightweight and have limited functionality compared to the drivers used by the kernel.

  1. Power-On: When the power button is pressed, the system's power supply is activated, and the firmware (UEFI or BIOS) initializes the hardware components.
  2. Firmware Initialization: The firmware performs a Power-On Self-Test (POST) to check the hardware components' functionality, such as the CPU, memory, storage devices, and peripherals. It also initializes system buses and interfaces.
  3. Boot Firmware: If the system uses UEFI firmware, the UEFI firmware takes control. It loads UEFI drivers, initializes hardware, and prepares the system for the boot process. If the system uses legacy BIOS, the BIOS performs similar tasks.
  4. Bootloader: The bootloader, usually GRUB2 (Grand Unified Bootloader), is loaded. GRUB2 presents a boot menu to the user if multiple operating systems are installed. The user can select the desired entry, or the default entry is automatically booted.
  5. Kernel Loading: The bootloader locates and loads the Linux kernel (vmlinuz) into memory. The kernel is the core of the operating system that manages hardware resources, provides system services, and initializes essential components.
  6. Initial RAM Disk (initrd): The bootloader also loads an initial RAM disk (initrd or initramfs) into memory. The initrd contains essential modules, drivers, and scripts required for early system initialization. It allows the kernel to access necessary drivers and file systems to mount the root file system.
  7. Kernel Initialization: The kernel is decompressed and starts executing. It initializes the system by setting up various components, such as the memory manager, CPU scheduler, device drivers,  and file systems.
  8. udev: The kernel starts udev (userspace device manager), which detects and configures hardware devices in the system. udev assigns device names (like /dev/sda for storage devices) and loads the necessary device drivers.
  9. Mounting the Root File System: The kernel mounts the root file system, which contains the main Ubuntu installation. The root file system can be on a variety of storage devices, such as hard drives, solid-state drives, or network-mounted storage.
  10. Init System: The init system is started, which is responsible for initializing user-space processes and managing system services. In modern distro, the default init system is systemd. The init system executes a series of startup scripts and starts essential system services.
  11. User Space Initialization: Once the init system completes its tasks, user-space processes are started, including essential system daemons and services. These processes provide various functionalities, such as networking, logging, time synchronization, and graphical interface management (if a desktop environment is installed).
  12. Login Prompt or Graphical Display Manager: Finally, the system is ready to present a login prompt in the console or a graphical login screen through a display manager

No comments:

Post a Comment