Building and booting an OS
Step through power-on → firmware → boot loader → kernel → systemd.
Building and booting an operating system
From source code to a running kernel, and from power-on to the login prompt.
Part 1 — Building (system generation)
An OS is usually generic: it must be configured for the machine it runs on. The process of configuring and producing the kernel is called system generation (SYSGEN). For Linux it looks like this:
Write the OS from scratch, or download existing source (e.g. from kernel.org).
make menuconfig asks which CPU, drivers, file systems and features to include, and whether each should be built into the kernel or as a module. Answers are saved in .config.
make -j$(nproc) compiles thousands of C and assembly files and links them into a compressed kernel image (bzImage / vmlinuz) plus .ko module files.
make modules_install copies modules to /lib/modules/<version>; make install copies the kernel to /boot, builds an initramfs and adds a GRUB entry.
Reboot, pick the new entry in GRUB, and confirm with uname -r.
- Fully tailored: recompile for the exact hardware — smallest and fastest, least general.
- Table-driven: one precompiled kernel chooses code from tables at boot.
- Modular: generic kernel; hardware-specific modules loaded at boot or run time — what most distributions do.
Part 2 — Booting
The CPU resets and begins executing at a fixed address mapped to firmware stored in ROM/flash on the motherboard. RAM contents are undefined.
BIOS (legacy) or UEFI runs the POST (power-on self-test), initialises the chipset, memory and basic devices, and walks the configured boot order.
BIOS: reads sector 0 of the boot disk (512 bytes, the MBR) to physical address 0x7C00, checks bytes 510–511 for 0x55 0xAA, and jumps there in 16-bit real mode. The MBR also holds the partition table.
UEFI: reads the FAT-formatted EFI System Partition and runs a boot application such as grubx64.efi; Secure Boot can verify its signature first.
GRUB shows a menu, reads its configuration, loads the kernel image and the initramfs into memory, passes the kernel command line (e.g. root=UUID=… ro quiet) and jumps to the kernel entry point.
The kernel decompresses itself, switches the CPU into its full operating mode, sets up page tables and the interrupt vector, initialises the scheduler, probes devices, uses the initramfs to load storage drivers and mounts the real root file system.
The kernel starts the first user-space process, /sbin/init — on most distributions systemd with PID 1. It starts services (networking, logging, display manager) in parallel. Every other process is a descendant of PID 1.
A login prompt or desktop appears. The kernel now runs only when an interrupt, a system call or an exception occurs — the event-driven loop from Session 1.4.
Legacy BIOS vs UEFI
| Legacy BIOS | UEFI | |
|---|---|---|
| Boot code location | First 512-byte sector (MBR) | Files on the EFI System Partition (FAT) |
| CPU mode at hand-off | 16-bit real mode | 32/64-bit mode |
| Disk partitioning | MBR, max 2 TiB, 4 primary partitions | GPT, very large disks, 128+ partitions |
| Security | None | Secure Boot verifies signed loaders |
offset 0x000 ... 0x1BD boot code + data (446 bytes) <- your program runs here, loaded at 0x7C00
offset 0x1BE ... 0x1FD partition table (4 x 16 bytes)
offset 0x1FE 0x55 \ boot signature
offset 0x1FF 0xAA / (BIOS refuses the sector without it)At which physical address does a legacy BIOS place the boot sector?
Which component loads the kernel image and initramfs?
What is the process ID of systemd on a typical Linux system?
Why is an initramfs needed?