Understanding Linux Boot Process from BIOS to Init

Understanding the Linux boot process is fundamental for system administrators and advanced users. From the moment you power on your computer until you reach the login prompt, multiple stages execute in sequence, each critical to system initialization. This comprehensive guide explains the Linux boot process from hardware initialization through systemd, covering traditional BIOS and modern UEFI systems.

Boot Process Overview

The Linux boot process consists of several distinct stages:

  1. BIOS/UEFI: Hardware initialization and firmware
  2. Boot Loader: GRUB loads kernel
  3. Kernel: Linux kernel initialization
  4. Initramfs: Initial RAM filesystem
  5. Init System: systemd or other init system
  6. Runlevels/Targets: System services startup
  7. Login: User authentication

Each stage depends on successful completion of the previous stage.

Stage 1: BIOS/UEFI Firmware

BIOS (Basic Input/Output System)

BIOS is the traditional firmware interface for PCs.

BIOS Boot Process:

  1. Power-On Self Test (POST): Hardware diagnostics
  2. BIOS initialization: Initialize hardware devices
  3. Boot device selection: Identify boot device (hard drive, USB, network)
  4. MBR reading: Read first 512 bytes of boot device (Master Boot Record)
  5. Boot loader execution: Execute boot loader code from MBR

MBR Structure:

The first 512 bytes of the boot disk contain:

  • Boot code: First 446 bytes (stage 1 boot loader)
  • Partition table: Next 64 bytes (4 primary partitions)
  • Boot signature: Last 2 bytes (0x55AA)

Limitations:

  • Maximum 4 primary partitions
  • Maximum 2TB disk size
  • Limited to 16-bit real mode
  • No security features

UEFI (Unified Extensible Firmware Interface)

UEFI is the modern replacement for BIOS.

UEFI Boot Process:

  1. Platform initialization: Hardware initialization
  2. Boot manager: Read boot configuration from NVRAM
  3. EFI System Partition (ESP): Mount FAT32 partition containing boot loaders
  4. Boot loader execution: Execute EFI application (e.g., GRUB)

UEFI Advantages:

  • GPT partition support (no 2TB limit)
  • Unlimited partitions
  • Secure Boot capability
  • Faster boot times
  • Better hardware support
  • Network boot capabilities
  • 32-bit or 64-bit mode

EFI System Partition:

# View ESP
sudo parted /dev/sda print

## Mount ESP
sudo mount /dev/sda1 /boot/efi

## View EFI applications
ls -la /boot/efi/EFI/

Stage 2: Boot Loader (GRUB)

GRUB (GRand Unified Bootloader) is the most common Linux boot loader.

GRUB Legacy vs GRUB2

GRUB Legacy (version 0.97): Older, simpler configuration GRUB2: Current version, more features, modular design

Most modern distributions use GRUB2.

GRUB Boot Process

GRUB2 Stages:

  1. Stage 1: boot.img loaded from MBR (BIOS) or as EFI application (UEFI)
  2. Stage 1.5: core.img contains filesystem drivers
  3. Stage 2: GRUB menu and modules from /boot/grub

GRUB Configuration

Main configuration file: /boot/grub/grub.cfg

Note: Don’t edit grub.cfg directly—it’s auto-generated.

Configuration location: /etc/default/grub

Example /etc/default/grub:

GRUB_DEFAULT=0
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="Ubuntu"
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX=""
GRUB_TERMINAL=console

Common options:

  • GRUB_DEFAULT: Default menu entry (0 = first)
  • GRUB_TIMEOUT: Seconds to display menu
  • GRUB_CMDLINE_LINUX: Kernel parameters for all entries
  • GRUB_CMDLINE_LINUX_DEFAULT: Additional kernel parameters
  • GRUB_DISABLE_RECOVERY: Show/hide recovery entries

Update GRUB after changes:

## Debian/Ubuntu
sudo update-grub

## Fedora/RHEL
sudo grub2-mkconfig -o /boot/grub2/grub.cfg

## Arch Linux
sudo grub-mkconfig -o /boot/grub/grub.cfg

GRUB Menu Entries

Custom menu entries: /etc/grub.d/40_custom

Example custom entry:

menuentry 'Ubuntu Recovery' {
    set root='hd0,gpt2'
    linux /boot/vmlinuz-5.15.0-generic root=/dev/sda2 ro single
    initrd /boot/initrd.img-5.15.0-generic
}

GRUB Rescue

If GRUB is corrupted:

## Boot from live USB
## Mount root partition
sudo mount /dev/sda2 /mnt

## Mount ESP (UEFI)
sudo mount /dev/sda1 /mnt/boot/efi

## Chroot into system
sudo chroot /mnt

## Reinstall GRUB
## BIOS
sudo grub-install /dev/sda

## UEFI
sudo grub-install --target=x86_64-efi --efi-directory=/boot/efi

## Update GRUB config
sudo update-grub

## Exit chroot
exit

## Reboot
sudo reboot

Kernel Parameters

Kernel parameters passed via GRUB:

Common parameters:

  • root=/dev/sda2: Root filesystem device
  • ro: Mount root as read-only initially
  • quiet: Suppress most boot messages
  • splash: Show graphical splash screen
  • single or 1: Boot to single-user mode
  • init=/bin/bash: Specify alternative init
  • nomodeset: Disable kernel mode setting (graphics issues)
  • acpi=off: Disable ACPI
  • mem=4G: Limit RAM usage

Edit kernel parameters temporarily:

  1. At GRUB menu, press e
  2. Navigate to line starting with linux
  3. Add/modify parameters
  4. Press Ctrl+X or F10 to boot

Stage 3: Linux Kernel

The kernel is the core of the operating system.

Kernel Loading

GRUB loads two files:

  1. Kernel image: /boot/vmlinuz-* (compressed kernel)
  2. Initial RAM disk: /boot/initrd.img-* or /boot/initramfs-*

Kernel Initialization

Kernel boot sequence:

  1. Decompress kernel: Extract compressed kernel to memory
  2. Initialize hardware: Detect and configure hardware
  3. Mount root filesystem: Mount initial RAM disk as root
  4. Execute init: Start init process (PID 1)

Kernel ring buffer:

View kernel messages:

## View kernel messages
dmesg

## Follow kernel messages
dmesg -w

## Human-readable timestamps
dmesg -T

## Filter by facility
dmesg -f kern
dmesg -l err

## Clear ring buffer
sudo dmesg -C

Kernel Modules

View loaded modules:

lsmod

Module information:

modinfo module_name

Load module:

sudo modprobe module_name

Remove module:

sudo modprobe -r module_name

Permanent module loading: /etc/modules-load.d/

## Create module config
echo "module_name" | sudo tee /etc/modules-load.d/module.conf

Stage 4: Initramfs/Initrd

What is Initramfs?

Initial RAM Filesystem is a temporary root filesystem loaded into memory during boot.

Purpose:

  • Load essential drivers
  • Mount real root filesystem
  • Handle encrypted drives
  • Support network boot
  • Prepare system for full init

Initramfs vs Initrd

Initrd (Initial RAM Disk): Older, block device-based Initramfs (Initial RAM Filesystem): Modern, cpio archive

Most systems use initramfs.

Managing Initramfs

View initramfs contents:

## Create directory
mkdir /tmp/initramfs
cd /tmp/initramfs

## Extract initramfs
zcat /boot/initrd.img-$(uname -r) | cpio -idmv

## or with lsinitramfs
lsinitramfs /boot/initrd.img-$(uname -r)

Rebuild initramfs:

## Debian/Ubuntu
sudo update-initramfs -u

## Specific kernel version
sudo update-initramfs -u -k 5.15.0-52-generic

## Fedora/RHEL
sudo dracut --force

## Arch Linux
sudo mkinitcpio -P

When to rebuild:

  • After kernel module changes
  • After modifying initramfs scripts
  • When adding encrypted drives
  • After hardware changes

Stage 5: Init System (systemd)

Init is the first process started by the kernel (PID 1).

systemd Overview

systemd is the modern init system for most Linux distributions.

systemd responsibilities:

Boot Targets

Targets are systemd’s equivalent of runlevels.

Common targets:

## View current target
systemctl get-default

## Available targets
systemctl list-units --type=target

## Change default target
sudo systemctl set-default multi-user.target

Standard targets:

  • poweroff.target: Shutdown
  • rescue.target: Single-user rescue mode
  • multi-user.target: Multi-user text mode
  • graphical.target: Multi-user with GUI
  • reboot.target: Reboot

Target relationships:

## View target dependencies
systemctl list-dependencies graphical.target

Boot Process with systemd

  1. systemd starts: Kernel executes /sbin/init (symlink to systemd)
  2. default.target: systemd reads default target
  3. Dependencies: Activate required units
  4. Services: Start enabled services
  5. Target reached: System ready

Boot analysis:

## Boot time
systemd-analyze

## Service startup times
systemd-analyze blame

## Critical chain
systemd-analyze critical-chain

## Plot boot process
systemd-analyze plot > boot.svg

Service Management

Service control:

## Start service
sudo systemctl start service_name

## Stop service
sudo systemctl stop service_name

## Restart service
sudo systemctl restart service_name

## Reload configuration
sudo systemctl reload service_name

## Enable at boot
sudo systemctl enable service_name

## Disable at boot
sudo systemctl disable service_name

## Check status
systemctl status service_name

View service logs:

## Service logs
journalctl -u service_name

## Follow logs
journalctl -u service_name -f

## Since boot
journalctl -u service_name -b

Traditional SysV Init

Some older systems use SysV init instead of systemd.

Runlevels

SysV init uses runlevels:

  • 0: Halt
  • 1: Single-user mode
  • 2: Multi-user (Debian/Ubuntu)
  • 3: Multi-user with networking (RHEL/Fedora)
  • 4: Unused
  • 5: Multi-user with GUI
  • 6: Reboot

View runlevel:

runlevel

Change runlevel:

sudo init 3
sudo telinit 3

Init Scripts

Init scripts located in /etc/init.d/

Service control:

## Start service
sudo /etc/init.d/service_name start

## Stop service
sudo /etc/init.d/service_name stop

## Status
sudo /etc/init.d/service_name status

Enable at boot:

sudo update-rc.d service_name defaults

Troubleshooting Boot Issues

Recovery Mode

Access recovery mode:

  1. At GRUB menu, select “Advanced options”
  2. Select recovery mode kernel
  3. Choose recovery option

Recovery options:

  • Resume normal boot
  • Clean temporary files
  • Repair broken packages
  • Fix filesystem
  • Drop to root shell

Single-User Mode

Boot to single-user mode for maintenance:

At GRUB:

  1. Press e to edit
  2. Find line starting with linux
  3. Add single or 1 or init=/bin/bash
  4. Press Ctrl+X to boot

In single-user mode:

## Remount root read-write
mount -o remount,rw /

## Fix issues
## ...

## Reboot
reboot -f

Common Boot Problems

GRUB not showing:

## Reinstall GRUB from live USB
sudo grub-install /dev/sda
sudo update-grub

Kernel panic:

  • Boot older kernel from GRUB menu
  • Check hardware
  • Review kernel logs

Cannot mount root filesystem:

  • Check /etc/fstab
  • Verify UUIDs: blkid
  • Boot from live USB and fix

Black screen after boot:

  • Add nomodeset to kernel parameters
  • Check graphics drivers
  • Try text mode: add text to kernel parameters

Viewing Boot Logs

systemd journal:

## Current boot
journalctl -b

## Previous boot
journalctl -b -1

## All boots
journalctl --list-boots

## Kernel messages
journalctl -k

Traditional logs:

## Boot log
cat /var/log/boot.log

## System log
cat /var/log/syslog

## Messages
cat /var/log/messages

Best Practices

Boot Configuration Management

  1. Backup GRUB config: Before modifications
  2. Test changes: Boot and verify
  3. Keep old kernels: Maintain fallback options
  4. Document changes: Record custom parameters
  5. Regular updates: Keep boot loader updated

Security Considerations

  1. GRUB password: Protect boot parameters
  2. Secure Boot: Enable on UEFI systems
  3. Encrypt boot partition: For full disk encryption
  4. Restrict physical access: Prevent boot device changes
  5. Monitor boot logs: Detect anomalies

Performance Optimization

  1. Reduce timeout: Faster boot
  2. Disable unnecessary services: Use systemctl disable
  3. Parallel startup: systemd does this by default
  4. Optimize initramfs: Include only necessary modules
  5. Fast boot options: UEFI Fast Boot, kernel fast boot

Conclusion

Understanding the Linux boot process from BIOS/UEFI through systemd provides crucial insights for system administration and troubleshooting. Each stage—firmware initialization, boot loader execution, kernel loading, initramfs setup, and init system startup—plays a vital role in bringing the system to a fully operational state.

Whether troubleshooting boot failures, optimizing startup time, or customizing system behavior, knowledge of the boot process is invaluable. From GRUB configuration to systemd target management, mastering these concepts enables effective system administration and rapid problem resolution.

The boot process represents the foundation of system operation—understanding it thoroughly empowers administrators to maintain reliable, secure, and efficient Linux systems.


References

Thank you for reading! If you have any feedback or comments, please send them to [email protected].