OPERATING SYSTEMS / 2. BIOS, UEFI & BOOT PROCESS
BIOS, UEFI & The Boot Process
What happens in the first seconds after you press the power button
EXPLANATION
When you press the power button, your OS isn't running yet. There is no software loaded. The CPU starts executing from a hardwired address in ROM. This is where BIOS/UEFI lives — the firmware. BIOS (Basic Input/Output System) — the original firmware: • Stored in a small non-volatile ROM/Flash chip on the motherboard • The CPU's first instruction after power-on points here (memory address 0xFFFF0 in x86) • Written in assembly/C, incredibly compact (256 KB – 2 MB) • Legacy (16-bit), limited to 1 MB addressable memory, MBR partition style UEFI (Unified Extensible Firmware Interface) — the modern replacement: • 32/64-bit, can address all RAM, has its own mini-OS, network stack, GUI • Supports GPT partitions (drives up to 9.4 ZB, up to 128 partitions) • Secure Boot — UEFI only boots bootloaders signed by trusted keys (prevents rootkits) • Faster boot (no need to go through legacy emulation) • Stored in SPI Flash chip (NOR Flash) on the motherboard The complete boot sequence (press power → login prompt): 1. Power Good signal: PSU stabilizes voltage → sends "Power Good" to motherboard → clock starts 2. CPU Reset Vector: CPU starts executing from a fixed address (0xFFFFFFF0 in x86-64). This is the UEFI/BIOS entry point. 3. POST (Power-On Self-Test): • CPU tests itself (registers, ALU) • Initializes the memory controller → tests RAM (this is why faulty RAM causes boot failure) • Discovers and initializes PCI devices (GPU, NIC, storage) • If POST fails → beep codes (speaker), LED codes, or error screen 4. UEFI/BIOS initializes hardware: • Sets up interrupt vector table • Configures chipset registers • Enumerates devices (USB, SATA, PCIe) 5. Boot Manager (UEFI has a built-in one): • Reads NVRAM for boot order preferences • Locates the EFI System Partition (ESP) — a FAT32 partition with bootloaders • Loads the bootloader (e.g., GRUB2 for Linux, Windows Boot Manager) 6. Bootloader (GRUB2): • Presents the OS selection menu (if multiple OS) • Loads the kernel image (vmlinuz) into RAM • Loads the initial RAM disk (initramfs) — a tiny filesystem the kernel uses to mount the real root • Passes kernel parameters (command line) • Jumps to kernel entry point 7. Kernel initialization: • Decompresses itself (kernel is stored compressed) • Sets up page tables (virtual memory) • Initializes scheduler, memory manager, interrupt handlers • Mounts real root filesystem • Starts PID 1 (systemd or init) 8. Init system (systemd): • Starts all system services in dependency order (networking, logging, display manager) • Eventually presents the login prompt
DIAGRAM
BOOT SEQUENCE TIMELINE:
Power Button
↓ ~0ms
PSU: Power Good signal
↓ ~50ms
CPU: Reset Vector → UEFI firmware
↓ ~200ms
POST: Test CPU → init RAM → scan devices
↓ ~500ms
UEFI: Full hardware initialization
↓ ~1000ms
UEFI Boot Manager: find EFI partition
↓ ~1100ms
Bootloader (GRUB): load kernel + initramfs
↓ ~1500ms
Kernel: decompress → setup VM → init drivers
↓ ~2000ms
PID 1 (systemd): start services
↓ ~5000ms
Display Manager: login screen
STORAGE LAYOUT (GPT + UEFI):
┌─────────────────────────────────────────┐
│ GPT Header │
├─────────────────────────────────────────┤
│ EFI System Partition (FAT32, ~100 MB) │
│ /EFI/ubuntu/grubx64.efi │
│ /EFI/Microsoft/Boot/bootmgfw.efi │
├─────────────────────────────────────────┤
│ Linux root / (ext4) │
├─────────────────────────────────────────┤
│ Swap partition │
├─────────────────────────────────────────┤
│ GPT Backup │
└─────────────────────────────────────────┘CODE