Computer Boot Process

From Power Button to Login Screen

Boot Process Overview

1
Power-On → Power supply self-test, voltage stabilization (~1-2 seconds)
2
BIOS/UEFI → POST, hardware initialization, boot device selection (~5-10 seconds)
3
Bootloader → GRUB loads kernel into memory (~2-3 seconds)
4
Kernel → Initialize hardware, mount root filesystem (~3-5 seconds)
5
Init System → systemd starts services, brings system to target state (~5-15 seconds)
6
Login → Display manager (GUI) or getty (terminal) ready for user
Total Boot Time: Modern systems: 15-30 seconds (SSD) | Legacy systems: 60+ seconds (HDD)

Step 1: Power-On

What Happens When You Press the Power Button

1. Power Supply Unit (PSU) Activation

2. Motherboard Initialization

Reset Vector

CPU's first instruction address:

  • x86 systems: 0xFFFFFFF0 (16 bytes below 4GB boundary)
  • This address maps to BIOS/UEFI firmware
  • First instruction: Usually a jump to BIOS code
; First instruction at reset vector (x86)
jmp BIOS_ENTRY_POINT

; BIOS/UEFI code stored in ROM/Flash on motherboard

Step 2: BIOS/UEFI

BIOS vs UEFI

BIOS (Basic Input/Output System)

Legacy firmware (1970s)

  • 16-bit mode: Runs in real mode
  • 1 MB addressable memory
  • MBR partition scheme: Max 2TB drives, 4 primary partitions
  • Text-based interface
  • Slower boot: Initializes hardware sequentially
  • Limited security: No secure boot

UEFI (Unified Extensible Firmware Interface)

Modern firmware (2005+)

  • 32-bit or 64-bit mode: Protected mode
  • Full memory access
  • GPT partition scheme: 9.4 ZB drives, 128 partitions
  • Graphical interface: Mouse support
  • Faster boot: Parallel initialization
  • Secure Boot: Cryptographic verification
  • Network boot: PXE, HTTP boot
Most modern systems (2012+) use UEFI, but many support legacy BIOS mode (CSM - Compatibility Support Module) for older operating systems.

POST (Power-On Self-Test)

Diagnostic testing sequence to verify hardware is functioning correctly.

POST Sequence

  1. CPU check: Verify CPU registers and instruction execution
  2. BIOS/UEFI checksum: Verify firmware integrity
  3. CMOS/NVRAM check: Read saved settings (date/time, boot order)
  4. Timer initialization: System timers (PIT, RTC)
  5. Memory test: Quick RAM check (full test optional)
    • Write and read patterns to memory
    • Detect amount of RAM installed
    • Build memory map
  6. Keyboard controller: Initialize PS/2 or USB keyboard
  7. Video initialization: Initialize graphics card
    • BIOS displays POST screen
    • Shows manufacturer logo or POST codes
  8. Peripheral detection: PCI/PCIe devices
    • Enumerate devices on buses
    • Execute device option ROMs (e.g., RAID controller BIOS)
    • Assign resources (IRQs, memory addresses, I/O ports)
  9. Storage detection: SATA, NVMe, USB drives
    • Identify bootable devices
    • Read partition tables

POST Codes

Beep codes or displayed codes indicate status or errors:

Beeps Meaning (AMI BIOS)
1 short beep POST successful
2 short beeps POST error (see screen for details)
1 long, 2 short Video error (GPU problem)
1 long, 3 short Video error (no GPU detected)
Continuous beeps Memory error (RAM not detected/failed)

Modern systems: Show POST code on small LED display or in UEFI interface

Boot Device Selection

Boot Order

BIOS/UEFI checks devices in configured order:

  1. USB drive (if USB boot enabled)
  2. CD/DVD drive
  3. Hard drive / SSD
  4. Network (PXE boot)

How Boot Device is Identified

BIOS Mode (MBR):

MBR Structure (512 bytes):
+--------------------------------------------------+
| Bootstrap code (446 bytes)                       | <- Bootloader code
+--------------------------------------------------+
| Partition Table (64 bytes)                       | <- 4 partition entries
|  - Partition 1: bootable, type, start, size      |
|  - Partition 2: ...                              |
|  - Partition 3: ...                              |
|  - Partition 4: ...                              |
+--------------------------------------------------+
| Boot Signature: 0x55 0xAA (2 bytes)              | <- Valid boot sector
+--------------------------------------------------+

UEFI Mode (GPT):

GPT Disk Structure:
+--------------------------------------------------+
| Protective MBR (for backward compatibility)      |
+--------------------------------------------------+
| Primary GPT Header                               |
|  - Disk GUID                                     |
|  - Partition table location                      |
|  - CRC32 checksums                               |
+--------------------------------------------------+
| Partition Table (up to 128 entries)              |
|  Entry 1: EFI System Partition (ESP)             | <- FAT32, bootloaders
|  Entry 2: Linux root partition                   |
|  Entry 3: Linux swap                             |
|  ...                                             |
+--------------------------------------------------+
| Partitions (actual data)                         |
+--------------------------------------------------+
| Backup Partition Table                           |
+--------------------------------------------------+
| Backup GPT Header                                |
+--------------------------------------------------+

EFI System Partition (ESP) Contents:

/EFI/
+-- BOOT/
|   +-- BOOTX64.EFI          # Default bootloader (fallback)
+-- ubuntu/
|   +-- grubx64.efi          # Ubuntu GRUB bootloader
+-- Microsoft/
|   +-- Boot/
|       +-- bootmgfw.efi     # Windows Boot Manager
+-- refind/
    +-- refind_x64.efi       # rEFInd boot manager

Step 3: Bootloader (GRUB)

What is a Bootloader?

A small program that loads the operating system kernel into memory. Bridge between firmware (BIOS/UEFI) and OS kernel.

Common Bootloaders

Bootloader Used By Notes
GRUB 2 Linux (Ubuntu, Fedora, etc.) Most common, powerful, scriptable
systemd-boot Linux (Arch, some UEFI systems) Simple, UEFI-only
Windows Boot Manager Windows bootmgfw.efi (UEFI) or bootmgr (BIOS)
rEFInd Multi-boot systems Graphical, auto-detects OSes

GRUB Boot Process

BIOS Mode (GRUB Legacy Stages)

  1. Stage 1: MBR bootstrap code (446 bytes)
    • Loaded by BIOS from MBR
    • Too small to do much
    • Loads Stage 1.5 or Stage 2
  2. Stage 1.5: Filesystem driver (optional)
    • Located in first 30KB after MBR (unused space)
    • Contains filesystem driver (ext4, NTFS, etc.)
    • Allows Stage 2 to be read from filesystem
  3. Stage 2: Full GRUB
    • Located in /boot/grub
    • Displays boot menu
    • Loads kernel and initramfs

UEFI Mode (GRUB 2)

GRUB Configuration (/boot/grub/grub.cfg)

menuentry 'Ubuntu' {
    set root='hd0,gpt2'                    # Partition with /boot
    linux /vmlinuz-5.15.0-generic \        # Kernel image
          root=UUID=abc-123 ro quiet       # Kernel parameters
    initrd /initrd.img-5.15.0-generic      # Initial RAM disk
}

menuentry 'Ubuntu (recovery mode)' {
    set root='hd0,gpt2'
    linux /vmlinuz-5.15.0-generic \
          root=UUID=abc-123 ro single      # Single-user mode
    initrd /initrd.img-5.15.0-generic
}

menuentry 'Windows Boot Manager' {
    chainloader /EFI/Microsoft/Boot/bootmgfw.efi
}

Key kernel parameters:

  • root=UUID=... - Root filesystem to mount
  • ro - Mount root as read-only initially
  • quiet - Suppress verbose boot messages
  • splash - Show graphical boot splash
  • single - Boot to single-user mode (recovery)
  • init=/bin/bash - Override init system (emergency)

What GRUB Does

  1. Display boot menu: Show available kernels and OSes (timeout: 5-10 seconds)
  2. User selection: Wait for user input or use default
  3. Load kernel: Read kernel image from /boot/vmlinuz-* into memory
  4. Load initramfs: Read /boot/initrd.img-* into memory
  5. Pass control to kernel: Jump to kernel entry point with parameters

Step 4: Kernel Initialization

Kernel Boot Process

1. Kernel Decompression

Kernel image (vmlinuz) is compressed:

2. Kernel Initialization (start_kernel)

Main kernel initialization function: start_kernel() in init/main.c

  1. Setup architecture-specific code:
    • Initialize CPU (interrupts, memory management, etc.)
    • Setup memory zones (DMA, Normal, HighMem)
    • Parse kernel command line parameters
  2. Initialize memory management:
    • Setup page tables
    • Initialize memory allocators (buddy system, slab)
    • Create kernel page tables
  3. Initialize scheduler:
    • Setup process scheduler
    • Create idle task (PID 0)
  4. Initialize interrupts:
    • Setup Interrupt Descriptor Table (IDT)
    • Initialize interrupt controllers (APIC, PIC)
    • Enable interrupts
  5. Initialize timers:
    • Setup system timers (TSC, HPET, PIT)
    • Initialize timekeeping
  6. Initialize console:
    • Setup kernel console output
    • Display kernel version and boot messages
  7. Initialize devices:
    • Enumerate and initialize hardware devices
    • Load built-in device drivers
    • Setup PCI/PCIe bus

Kernel Boot Messages (dmesg)

[    0.000000] Linux version 5.15.0-generic (gcc version 11.2.0)
[    0.000000] Command line: root=UUID=abc-123 ro quiet splash
[    0.000000] KERNEL supported cpus: Intel GenuineIntel
[    0.000000] x86/fpu: x87 FPU will use FXSAVE
[    0.001234] Memory: 16384MB RAM
[    0.005678] Zone ranges: DMA [0-16MB], Normal [16MB-16GB]
[    0.012345] ACPI: Core revision 20210730
[    0.023456] PCI: Using configuration type 1 for base access
[    0.034567] clocksource: tsc: mask: 0xffffffff max_cycles: 0x3b...
[    0.045678] Console: colour VGA+ 80x25
[    0.056789] Calibrating delay loop... 4788.00 BogoMIPS

3. Mount initramfs

initramfs (Initial RAM Filesystem): Temporary root filesystem in memory

Why is initramfs needed?

initramfs contents:
  • Kernel modules (drivers): filesystem, RAID, LVM, encryption (LUKS), network
  • Essential binaries: mount, modprobe, lvm, cryptsetup
  • Init script: /init (runs in initramfs)

4. Execute /init (in initramfs)

Kernel runs /init script from initramfs:

  1. Load necessary modules:
    • Filesystem drivers (ext4, xfs, btrfs)
    • Block device drivers (SATA, NVMe, USB)
    • RAID/LVM modules if needed
    • Encryption modules (dm-crypt) if needed
  2. Setup devices:
    • Create device nodes in /dev
    • Scan for LVM volumes, RAID arrays
    • Prompt for encryption password if root is encrypted
  3. Mount real root filesystem:
    • Mount partition specified by root= kernel parameter
    • Typically mounted at /root within initramfs
  4. Switch to real root:
    • switch_root - Change root to real filesystem
    • Free initramfs memory
    • Execute /sbin/init on real root filesystem
# Simplified /init script (in initramfs)
#!/bin/sh

# Mount pseudo-filesystems
mount -t proc proc /proc
mount -t sysfs sysfs /sys
mount -t devtmpfs devtmpfs /dev

# Load modules
modprobe ext4
modprobe nvme

# Setup LVM if present
lvm vgscan
lvm vgchange -ay

# Mount real root filesystem
mount -o ro /dev/nvme0n1p2 /root

# Switch to real root and run /sbin/init
exec switch_root /root /sbin/init

Step 5: Init System (systemd)

Init System: PID 1

First user-space process started by kernel. Parent of all other processes.

Init Systems

Init System Used By Characteristics
systemd Modern Linux (Ubuntu 15.04+, Fedora, Arch, Debian) Parallel startup, dependencies, targets
SysV init Legacy Linux, BSD Sequential scripts, runlevels
Upstart Ubuntu 6.10-14.10 (deprecated) Event-based
OpenRC Gentoo, Alpine Linux Dependency-based, lightweight

systemd Boot Process

1. systemd Started by Kernel

# Kernel executes (PID 1):
/sbin/init → symlink to /lib/systemd/systemd

2. Determine Boot Target

systemd uses targets instead of runlevels:

Target SysV Runlevel Description
poweroff.target 0 Shutdown
rescue.target 1, s Single-user mode (maintenance)
multi-user.target 2, 3, 4 Multi-user, text mode
graphical.target 5 Multi-user, GUI
reboot.target 6 Reboot

Default target: /etc/systemd/system/default.target (symlink)

$ ls -l /etc/systemd/system/default.target
lrwxrwxrwx 1 root root 36 Oct 15 10:23 \
    /etc/systemd/system/default.target -> /lib/systemd/system/graphical.target

3. Start Units in Dependency Order

systemd reads unit files and starts services based on dependencies:

Unit Types:
  • .service - Service (daemon)
  • .target - Group of units (like runlevels)
  • .mount - Mount point
  • .socket - Socket activation
  • .timer - Cron-like scheduling
  • .device - Hardware device

Example: graphical.target Dependencies

graphical.target
+-- multi-user.target
|   +-- basic.target
|   |   +-- sysinit.target
|   |   |   +-- local-fs.target (mount filesystems)
|   |   |   +-- swap.target (enable swap)
|   |   |   +-- cryptsetup.target (decrypt volumes)
|   |   +-- sockets.target
|   |   +-- timers.target
|   +-- sshd.service
|   +-- networking.service
|   +-- cron.service
+-- display-manager.service (GDM, LightDM, SDDM)

4. Parallel Service Startup

systemd starts services in parallel when dependencies allow:

# Traditional sequential (SysV):
Start networking... [done]
Start database...   [done]
Start web server... [done]
Total: 15 seconds

# systemd parallel:
Start networking, database, logging simultaneously
Wait only for actual dependencies
Total: 6 seconds
Service ordering in systemd:
  • After= - Start after these units (but doesn't wait for them to finish)
  • Before= - Start before these units
  • Requires= - Hard dependency (fail if dependency fails)
  • Wants= - Soft dependency (continue even if dependency fails)

5. Start Login Manager

Final step: Start login interface

Text mode (multi-user.target):

GUI mode (graphical.target):

Complete Boot Timeline Example

Time    | Component        | Action
--------|------------------|------------------------------------------
0.0s    | PSU              | Power Good signal sent
0.1s    | Motherboard      | Clock started, CPU reset released
0.2s    | CPU              | Fetch first instruction from 0xFFFFFFF0
0.2s    | UEFI             | POST begins
0.5s    | UEFI POST        | CPU check OK
1.0s    | UEFI POST        | Memory: 16GB detected, quick test OK
2.0s    | UEFI POST        | PCIe devices enumerated
3.0s    | UEFI POST        | NVMe SSD detected
4.0s    | UEFI             | Read ESP, find GRUB
5.0s    | GRUB             | Display boot menu
10.0s   | GRUB             | Timeout, load default kernel
10.5s   | GRUB             | Load vmlinuz into memory
11.0s   | GRUB             | Load initrd into memory
11.5s   | GRUB             | Jump to kernel entry point
11.6s   | Kernel           | Decompress kernel
12.0s   | Kernel           | start_kernel() - CPU init
12.5s   | Kernel           | Memory management init
13.0s   | Kernel           | Scheduler init
13.5s   | Kernel           | Device drivers init
14.0s   | Kernel           | Mount initramfs, execute /init
14.5s   | initramfs        | Load ext4, nvme modules
15.0s   | initramfs        | Mount /dev/nvme0n1p2 as root
15.5s   | initramfs        | switch_root, exec /sbin/init
16.0s   | systemd (PID 1)  | Start, determine target: graphical.target
16.5s   | systemd          | Mount /home, /var, /tmp
17.0s   | systemd          | Start networking, logging (parallel)
18.0s   | systemd          | Start database, web server (parallel)
20.0s   | systemd          | Start GDM (display manager)
22.0s   | GDM              | Login screen displayed
--------|------------------|------------------------------------------
Total: 22 seconds (modern UEFI system with NVMe SSD)

Troubleshooting Boot Issues

Common Boot Problems

1. "No bootable device" or "Operating System not found"

Causes:

Fix:

2. Kernel Panic

Causes:

Fix:

3. Stuck at GRUB Prompt

Manual boot from GRUB:

grub> ls                                    # List partitions
(hd0) (hd0,gpt1) (hd0,gpt2)

grub> set root=(hd0,gpt2)                   # Set root partition
grub> linux /vmlinuz root=/dev/sda2 ro      # Load kernel
grub> initrd /initrd.img                    # Load initramfs
grub> boot                                  # Boot

4. Emergency/Rescue Mode

Boot to rescue mode:

Key Interview Points