When you switch a computer on, memory is empty. There is no kernel in it, no file system, no programs. The kernel is just a file sitting on a disk, and reading a file needs… a kernel.
So how does anything start? The answer is a relay race. Each runner is small and simple, and its only job is to load the next, bigger runner and hand over control.
The relay
Step through a typical Linux PC starting up. The fields on the right show who is in control, what mode the CPU is in, and what memory holds.
Booting a Linux PC
-
Power on
You press the power button. The CPU starts running instructions from a fixed address, and that address is in the firmware chip on the motherboard, not on the disk.
- In control
- firmware
- CPU mode
- 16-bit start-up mode
- Memory holds
- nothing useful yet
-
The firmware checks the machine
The UEFI firmware switches the CPU to 64-bit mode, sets up memory, and finds the disks, keyboard and screen.
- In control
- firmware
- CPU mode
- 64-bit, full privilege
- Memory holds
- firmware data
-
Find something to boot
The firmware reads its boot settings and loads a bootloader file from a small partition on the disk set aside for this, the EFI system partition.
- In control
- firmware
- CPU mode
- 64-bit, full privilege
- Memory holds
- firmware, bootloader
-
The bootloader loads the kernel
The bootloader (GRUB or systemd-boot, for example) can show a menu of systems. It loads the kernel file and a small starter file system, the initramfs, into memory, then jumps to the kernel.
- In control
- bootloader
- CPU mode
- 64-bit, full privilege
- Memory holds
- kernel, initramfs
-
The kernel takes charge
The kernel sets up its memory management, its interrupt handlers, its system call table and the timer. From now on, only the kernel touches the hardware directly.
- In control
- kernel
- CPU mode
- kernel mode
- Memory holds
- kernel, initramfs
-
Drivers and the root file system
The kernel starts drivers for the devices it finds, with help from the initramfs, then mounts the real root file system from the disk.
- In control
- kernel
- CPU mode
- kernel mode
- Memory holds
- kernel, drivers, file system cache
-
The first process
No process exists yet, so no process can start one. The kernel builds the first process itself and runs /sbin/init in it, in user mode. On most Linux systems that program is systemd. It gets process ID 1, and every later process descends from it.
- In control
- systemd (PID 1)
- CPU mode
- user mode for PID 1
- Memory holds
- kernel, PID 1
-
Services start
systemd starts the system's services: logging, networking, the login screen and more, many of them at the same time.
- In control
- systemd and services
- CPU mode
- user mode for programs
- Memory holds
- kernel, many processes
-
Log in
A login screen or prompt appears. It checks your password and starts a session that runs as your user, with your permissions.
- In control
- login program
- CPU mode
- user mode for programs
- Memory holds
- kernel, many processes
-
Your shell is ready
Your shell (or desktop) starts. From here on, every program you run is started by a process that already exists, and the kernel is in the background, called when needed.
- In control
- your shell
- CPU mode
- user mode for programs
- Memory holds
- kernel, many processes
Notice who is in charge at each moment:
- Firmware (UEFI on modern PCs) lives in a chip on the motherboard, so it is there the instant the power comes on. It checks and sets up the hardware, then finds a bootloader on the disk.
- The bootloader (such as GRUB) loads the kernel file into memory and jumps to it.
- The kernel takes over the hardware for good. It sets up memory management, the interrupt handlers from Lesson 1.2 and the system call table from Lesson 1.3, then starts the drivers.
- The kernel starts the first process, PID 1, which starts everything else.
Why PID 1 is special
Every process has a number, its process ID or PID. Normally a new process is created by an existing one: your shell creates a process for every command you type (you will see exactly how in Lesson 2.3). That gives a family tree with one root, and the root is PID 1, usually a program called systemd on Linux.
PID 1 has jobs nobody else has:
- It starts the system’s services, in the right order, and restarts them if they crash.
- It adopts orphans: when a process’s parent ends first, PID 1 becomes the new parent and cleans up after it.
- It must never exit. If PID 1 dies, the Linux kernel has nothing left to fall back on and stops the whole system with a “kernel panic”.
From the moment PID 1 starts, the kernel steps back. It no longer runs a script of its own. It waits for system calls and interrupts, and does what they ask.
In the real world
On a Linux machine that uses systemd, you can see how long each runner took:
$ systemd-analyze
$ systemd-analyze blame
The first command splits the boot time into firmware, bootloader, kernel and user space. The second lists the services, slowest first. A phone boots with the same shape. An Android phone starts with a boot ROM baked into the chip, then a bootloader that checks the kernel’s signature, then the Linux kernel, then init as PID 1, which starts the services and the app runtime. An iPhone has a different kernel, but the same relay: each stage checks the next one before handing over. :::
Quick check
Quick check
-
The firmware is too simple to understand kernel files. It loads a bootloader, whose job is to load the kernel.
-
The kernel is not a process. PID 1 is the first process it starts, and the root of the process tree.
-
After the first one, every process has a parent that asked the kernel to create it.
Module 1 recap
An operating system abstracts hardware and manages it for many programs at once. The kernel is the part with full control. The CPU runs a fetch, decode, execute loop; devices and the timer interrupt it so the kernel gets control back. The CPU’s mode bit keeps programs in user mode, and system calls are their controlled way into kernel mode. At boot, firmware loads a bootloader, the bootloader loads the kernel, and the kernel starts PID 1, the ancestor of every other process.
Next: Module 2 opens up processes: what a running program looks like in memory, and how a shell starts every command you type.
Join the discussion