The Boot Process#

Prerequisite — Firmware: Every computer has firmware, low-level software stored on a chip on the motherboard. It initializes hardware and hands control to the operating system. There are two types: BIOS (legacy, from the 1980s) and UEFI (modern replacement, supports larger disks, secure boot, faster startup). Most systems sold after 2012 use UEFI.

Concepts#

Boot Sequence Overview#

Power on
  │
  ▼
Firmware (BIOS/UEFI)       ← initializes hardware, finds bootloader
  │
  ▼
Bootloader (GRUB)           ← loads the kernel
  │
  ▼
Linux Kernel                ← takes control, detects hardware
  │
  ▼
initramfs                   ← temporary root filesystem (loads drivers)
  │
  ▼
systemd (PID 1)             ← init system, starts services
  │
  ▼
Login prompt / Desktop      ← system ready

Stage 1: Firmware (BIOS/UEFI)#

The firmware runs a POST (Power-On Self-Test), initializes hardware (CPU, RAM, display), and looks for a bootable device.

BIOS UEFI
Partition table MBR (max 2TB disks, 4 primary partitions) GPT (no practical limits)
Boot method Reads first 512 bytes of disk (MBR) Reads EFI System Partition (ESP)
ESP None FAT32 partition mounted at /boot/efi
Secure Boot No Yes (verifies bootloader signature)

On UEFI systems, the boot files live in the EFI System Partition:

ls /boot/efi/EFI/
# ubuntu/  debian/  (bootloader files)

Stage 2: GRUB (Bootloader)#

GRUB (GRand Unified Bootloader) is the default bootloader on Ubuntu and Debian. It:

  • Displays a boot menu (choose OS or kernel version)
  • Loads the Linux kernel and initramfs into memory
  • Passes boot parameters to the kernel

GRUB Configuration#

# Main config (auto-generated — do not edit directly)
cat /boot/grub/grub.cfg

# Edit settings here instead:
sudo nano /etc/default/grub

# Key settings:
# GRUB_TIMEOUT=5                  # seconds to show menu (0 = skip)
# GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"   # kernel parameters
# GRUB_CMDLINE_LINUX=""           # additional kernel parameters

# After editing, regenerate grub.cfg:
sudo update-grub

Ubuntu: update-grub is available as a convenience script. Debian: Also available, but you can also use sudo grub-mkconfig -o /boot/grub/grub.cfg.

Useful GRUB Operations#

# View installed kernels
ls /boot/vmlinuz-*

# View GRUB menu entries
grep menuentry /boot/grub/grub.cfg

# Boot into recovery mode: at GRUB menu, select "Advanced options" → recovery mode

Stage 3: The Linux Kernel#

Once GRUB loads the kernel (vmlinuz-*) into memory, the kernel:

  1. Decompresses itself
  2. Initializes core hardware (CPU, memory manager)
  3. Mounts the initramfs as a temporary root filesystem

Stage 4: initramfs#

The initramfs (initial RAM filesystem) is a small, temporary root filesystem loaded into RAM. It contains:

  • Essential drivers (disk, filesystem, LVM, RAID)
  • Scripts to find and mount the real root filesystem

Once the real root filesystem is mounted, initramfs hands control to the init system.

# View initramfs files
ls /boot/initrd.img-*

# Rebuild initramfs (after driver or module changes)
sudo update-initramfs -u

Stage 5: systemd (PID 1)#

systemd is the first process the kernel starts (PID 1). It:

  1. Reads its configuration and target (like a runlevel)
  2. Starts services in parallel based on dependencies
  3. Mounts filesystems from /etc/fstab
  4. Sets up networking, logging, and user sessions

systemd Targets (Runlevels)#

Targets define what state the system boots into:

Target Old Runlevel Description
poweroff.target 0 Shutdown
rescue.target 1 Single-user, minimal services
multi-user.target 3 Full system, no GUI
graphical.target 5 Full system with GUI
reboot.target 6 Reboot
# Check current target
systemctl get-default

# Change default target
sudo systemctl set-default multi-user.target    # boot to terminal
sudo systemctl set-default graphical.target     # boot to desktop

# Switch target right now (without rebooting)
sudo systemctl isolate multi-user.target

Viewing Boot Information#

# Boot log (current boot)
journalctl -b

# Previous boot
journalctl -b -1

# Boot time breakdown
systemd-analyze

# Service startup times
systemd-analyze blame | head -15

# Visual boot chart (generates SVG)
systemd-analyze plot > /tmp/boot.svg

# Kernel messages
dmesg | head -30
dmesg | tail -20

Troubleshooting Boot Problems#

# Boot into recovery mode:
# 1. At GRUB menu, select "Advanced options" → recovery mode
# 2. This boots to rescue.target (single-user)

# If GRUB is broken, boot from a live USB and:
sudo mount /dev/sda2 /mnt
sudo mount /dev/sda1 /mnt/boot/efi      # UEFI systems
sudo grub-install --root-directory=/mnt /dev/sda
sudo chroot /mnt update-grub

# Check why a service failed to start during boot
systemctl --failed
journalctl -b -p err

Lab#

Exercise 1: Examine Your Boot Setup#

# Check firmware type
[ -d /sys/firmware/efi ] && echo "UEFI" || echo "BIOS/Legacy"

# Check EFI partition (UEFI only)
ls /boot/efi/EFI/ 2>/dev/null

# List installed kernels
ls /boot/vmlinuz-*

# Current kernel
uname -r

Exercise 2: Explore GRUB#

# View GRUB settings
cat /etc/default/grub

# List menu entries
grep -E "^menuentry" /boot/grub/grub.cfg 2>/dev/null | head -5

Exercise 3: Boot Analysis#

# How long did boot take?
systemd-analyze

# Slowest services
systemd-analyze blame | head -10

# Current target
systemctl get-default

Exercise 4: Boot Logs#

# Kernel messages from this boot
dmesg | head -30

# systemd boot log
journalctl -b --no-pager | head -30

# Any boot errors?
journalctl -b -p err --no-pager

# Failed services
systemctl --failed

Review#

1. What is the boot sequence on a Linux system?

Firmware (BIOS/UEFI) → Bootloader (GRUB) → Kernel → initramfs → systemd → Login. Each stage hands control to the next.

2. What is GRUB?

The bootloader. It displays a menu for choosing the OS or kernel version, loads the selected kernel and initramfs into memory, and passes boot parameters to the kernel.

3. What is initramfs?

A small temporary root filesystem loaded into RAM. It contains essential drivers and scripts needed to find and mount the real root filesystem. After mounting root, it hands control to systemd.

4. What is PID 1?

The first process started by the kernel — on Ubuntu and Debian, this is systemd. It is the parent of all other processes and is responsible for starting services, mounting filesystems, and managing the system.

5. How do you check how long your system took to boot?

systemd-analyze shows total boot time. systemd-analyze blame shows which services were slowest.


Previous: Scheduling with cron and at | Next: The Kernel