Kernel Internals & OS Construction

the boot sequence

When you press the power button, the computer cannot just start running your operating system — nothing is loaded yet, the memory is empty, and the CPU only knows how to fetch one instruction from a fixed place. The boot sequence is the carefully staged relay race that takes the machine from cold silicon to a fully running OS with a login screen. Think of waking up a large factory in the morning: first one trusted person unlocks the front door, that person turns on the lights and checks the machines work, then they start a small crew, the small crew starts the bigger crew, and only then does the whole factory hum. Each stage knows just enough to wake the next, bigger stage.

Concretely the stages go like this. (1) The CPU starts executing firmware (BIOS on older PCs, UEFI on modern ones) baked into a chip on the motherboard; it runs the power-on self-test (POST) to check RAM and devices. (2) The firmware finds a boot device and hands control to a bootloader (such as GRUB), a small program whose only job is to find and load the OS. (3) The bootloader loads the kernel image into memory, decompresses it if needed, and jumps into it. (4) The kernel sets up the bare essentials — its own memory map, the interrupt tables, the CPU's protected mode — then mounts a temporary root file system from an initramfs so it has drivers to reach the real disk. (5) Finally the kernel starts the very first user process (init or systemd), which then launches every other service and brings you to a usable system.

It matters because almost everything else assumes a running kernel already exists — boot is the one part where that is not yet true, so it is full of chicken-and-egg problems (you need a driver to read the disk, but the driver is on the disk). A common misconception is that the bootloader and the kernel are the same thing; they are separate programs with a handoff, which is exactly why you can have a boot menu (GRUB) that offers several different kernels or operating systems before any of them actually runs.

On a Linux laptop the chain reads almost like a sentence: UEFI firmware -> POST -> GRUB shows a menu -> GRUB loads vmlinuz (the kernel) and the initramfs -> the kernel decompresses, brings up the CPU and memory, mounts initramfs, loads the disk driver, mounts the real root file system -> the kernel executes /sbin/init (systemd) as process 1 -> systemd starts the display manager and you see a login.

Each stage loads and trusts the next, larger stage — firmware, bootloader, kernel, init.

Boot is one place where ordinary OS protections do not yet apply, which is why it is a security battleground: malware that infects the bootloader (a bootkit) runs before the kernel and can hide from it — the motivation for secure boot, which checks each stage's signature before running it.

Also called
boot processstartup sequence開機流程