Hasty Briefsbeta

Bilingual

Understanding the Linux Kernel: The Linux Kernel Startup

4 hours ago
  • #operating-systems
  • #linux-kernel
  • #boot-process
  • The article explains the Linux kernel boot process in six phases: from pressing the power button to launching the init process.
  • Phase 1 (Assembly): The kernel is decompressed, KASLR randomizes its base, the CPU enters 64-bit Long Mode, CPU features are verified, and page tables are fixed for address mismatch before jumping to C.
  • Phase 2 (Early C): The BSS section is cleared, safety stubs like KASAN placeholder and a minimal IDT are set up, boot parameters are saved, and CPU microcode is patched.
  • Phase 3 (Hardware Discovery): setup_arch() detects CPU features, parses the firmware memory map, identifies the machine (UEFI/hypervisor/ACPI), builds the direct memory map, and finalizes KASAN.
  • Phase 4 (Core Subsystems): start_kernel() initializes memory (via mm_core_init()), the scheduler, RCU, timekeeping, interrupts, the console, CPU self-patching, and slab caches for subsystems.
  • Phase 5 (Multitasking): rest_init() spawns PID 1 (kernel_init, future init) and PID 2 (kthreadd), with the boot thread becoming the idle task, marking the transition to multitasking.
  • Phase 6 (User Space): kernel_init() wakes other CPUs, runs initcalls (drivers/filesystems), mounts the root filesystem, frees init memory, locks down security, and exec()s the userspace init program.