OS Boot Process & Kernel Quick Notes

Boot Sequence Overview

  • Power-on ➝ BIOS/UEFI runs POST, initialises HW
  • Firmware locates boot device, loads first stage code:
    • Legacy: BIOS reads 512\,\text{B} MBR at \text{CHS }(0,0,1)
    • UEFI: looks for EFI System Partition (ESP) (FAT32, ≥100\,\text{MB})
  • Bootloader executed ➝ loads OS kernel ➝ kernel mounts root FS & starts /sbin/init (PID 1)

Partitioning & Formatting

  • Disk must be divided into partitions before FS creation
  • Formatting writes FS structures (e.g. NTFS, FAT32, ext4, APFS)
  • Cluster (logical block) = group of sectors; allocation unit for files
    • Max file size = \text{cluster size} \times (2^{32}-1)

MBR Scheme

  • Located in first 512\,\text{B} sector; contains:
    • Bootstrap code • Partition table (4 entries) • Disk signature 55\text{AA}
  • Limits:
    • Max disk 2^{32}\times512=2\,\text{TiB} (512-B sectors)
    • Only 4 primary partitions (use extended+logical as workaround)
    • Single copy → corruption = data loss

GPT Scheme

  • Uses 64-bit LBAs ⇒ max size 2^{64} sectors (e.g. 8 ZiB @512 B)
  • Layout: Protective MBR, Primary GPT header (LBA 1), partition table, Backup GPT at disk end
  • Up to 128 primary partitions by default
  • Redundant headers + CRC32 → self-healing; stores GUIDs per disk/partition
  • Requires UEFI to boot Windows, but data disks usable under BIOS too

BIOS vs UEFI Boot

  • BIOS: 16-bit, MBR, boot limit 2.1\,\text{TB}, 4 primaries
  • UEFI: 32/64-bit mini-OS, GPT, theoretical 9.4\,\text{ZB}, GUI, faster boot
  • Compatibility: UEFI can run in “CSM/Legacy” mode to emulate BIOS

Secure Boot

  • UEFI feature; firmware verifies signatures of bootloaders/kernels
  • Blocks code signed with black-listed keys → mitigates bootkits

Bootloaders (examples)

  • GRUB2 (Linux), Windows Boot Manager, LILO, Syslinux
  • Task: understand FS, locate kernel/initrd, pass control with cmd-line args

Kernel Fundamentals

  • First component loaded; remains resident in protected memory
  • Operates in kernel mode; user apps run in user mode
  • Responsibilities: process mgmt, memory mgmt, HW abstraction, IPC, interrupt handling

Kernel Types Comparison

  • Monolithic: all core services + drivers in kernel space • Fast IPC • Large, harder to maintain (Linux, Unix)
  • Microkernel: minimal core (sched, IPC, MM); services/drivers in user space • Easier maintenance & fault isolation • More context switches → slower (QNX, Minix)
  • Hybrid: microkernel base + some drivers in kernel for speed (Windows NT, macOS XNU)
  • Exokernel: minimal allocation/ protection; abstractions in libOS within user space (research)
  • Multikernel: treats each CPU core as node; message-passing instead of shared memory (Barrelfish)

Modules (Linux)

  • Loadable Kernel Modules (LKMs) add/remove functionality at runtime via \texttt{modprobe}
  • Advantages: smaller base kernel, no recompilation, faster driver development

Linux Run Levels (SysV init)

  • 0: Halt • 1: Single-user • 2: Multi-user (no NFS) • 3: Multi-user + networking • 4: Unused/custom • 5: 3 + GUI • 6: Reboot
  • systemd replaces run levels with “targets” on modern distros