Table of Contents
1.1.2 Linux Boot Process Explained (BIOS vs. UEFI, GRUB2, and Commands) #
The Linux boot process is a structured sequence that loads the operating system into memory. Below is a detailed breakdown of the key components, including BIOS/UEFI, GRUB2, boot files, and essential commands.
1. Firmware Initialization: BIOS vs. UEFI #
1) Basic Input/Output System (BIOS)
- Legacy firmware (older systems).
- Process:
- POST (Power-On Self-Test) → Checks hardware.
- Loads MBR (Master Boot Record) → First 512 bytes of the boot disk.
- Starts the bootloader (e.g., GRUB2).
- Limitations:
- No secure boot.
- Limited to MBR partitioning (max 2TB disks).
2) Unified Extensible Firmware Interface (UEFI)
- Modern replacement for BIOS.
- Process:
- Runs POST.
- Looks for an EFI System Partition (ESP) (
/boot/efi
). - Loads bootloader (e.g., GRUB2) from ESP.
- Advantages:
- Supports Secure Boot (prevents malware).
- GPT partitioning (>2TB disks).
- Faster boot times.
2. Bootloader: GRUB2 (Grand Unified Bootloader 2) #
- Default bootloader for most Linux distros.
- Config File:
/boot/grub2/grub.cfg
(auto-generated). - Key Files:
vmlinuz
→ Compressed Linux kernel.initrd.img
orinitramfs
→ Temporary root filesystem (loads drivers before real root is mounted).
GRUB2 Commands #
Command | Purpose |
---|---|
grub2-install | Installs GRUB2 to a disk (/dev/sda ). |
grub2-mkconfig | Generates a new grub.cfg file. |
grub2-update | Updates GRUB2 (some distros alias this to update-grub ). |
mkinitrd | Creates an initrd (initial RAM disk). |
dracut | Modern alternative to mkinitrd (used in RHEL/Fedora). |
3. Kernel & Initramfs Loading #
- GRUB2 loads
vmlinuz
(Linux kernel). initrd.img
orinitramfs
is loaded → Contains drivers/modules needed to mount the real root (/
).- Kernel initializes hardware and switches to the real root filesystem.
4. Boot Sources #
a) Preboot eXecution Environment (PXE) #
- Network booting (used in servers/data centers).
- Requires:
- DHCP server (assigns IP).
- TFTP server (serves boot files).
b) Booting from USB #
- Requires a bootable USB (created with
dd
or tools likeRufus
). - Example:bashCopyDownloaddd if=ubuntu.iso of=/dev/sdX bs=4M status=progress
c) Booting from ISO (Directly Mounted) #
- Some UEFI systems allow booting directly from ISO files (without USB).
5. System Initialization (systemd / SysVinit) #
After the kernel loads:
systemd
(modern init system, PID 1) takes over.- Targets (runlevels) determine what services start:
multi-user.target
→ CLI mode.graphical.target
→ GUI mode.
Summary: Linux Boot Process Flow #
- Firmware (BIOS/UEFI) → POST → Finds boot device.
- Bootloader (GRUB2) → Loads
vmlinuz
+initramfs
. - Kernel → Initializes hardware, mounts root (
/
). - Init system (systemd) → Starts services, reaches target.
Key Troubleshooting Commands #
- Fix GRUB2:bashCopyDownloadgrub2-install /dev/sdX # Reinstall GRUB grub2-mkconfig -o /boot/grub2/grub.cfg # Regenerate config
- Rebuild
initramfs
:bashCopyDownloaddracut -fv # For RHEL/Fedora mkinitrd # For Debian/Ubuntu (older)
Final Notes #
- UEFI + GPT is the modern standard (faster, more secure).
- GRUB2 is highly configurable (edit
/etc/default/grub
before runninggrub2-mkconfig
). initramfs
is critical for loading drivers (e.g., encrypted LVM, RAID).