Index

Free, with Google

Keep going, free.

A free account opens lessons 2 and 3 of every track, 33 more lessons, and keeps your progress and review cards on every device.

Start free with Google

A chalk plan

Open everything on chalk.

Every lesson, board, video, lab and paper, and the full review decks. Yearly is $39/year.

See plansStart free instead

Module 06 · How Computers Work · Build the machine's software · about 14 min to read

Play it as a journeyTutor comes with a plan

From power button to PID 1: how a machine boots

Processes Threads and the Kernel
Processes Threads and the Kernel · Open board

The kernel and the programs it runs. This lesson goes one step earlier: how the kernel itself gets into memory, and which program it starts first.

Someone restarts a server after a kernel update. The screen does not show a login. It shows one line:

Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)

The chips work, the disk is fine, and the kernel is running. It just cannot find its own disk. To fix this, you need to know what each boot stage hands to the next.

By the end you will be able to name every stage between the power button and the first program, say what each one hands to the next, and read a boot failure to find which stage stopped.

The history (optional)

Intel’s manual says that after a reset, an x86 chip from the 80386 onwards fetches its first instruction from address FFFFFFF0 hex. That is 16 bytes below the top of a 4 GiB address space. On 1 March 2023 the security company ESET reported BlackLotus, a UEFI bootkit: malware that plants itself in the early boot stages, before the operating system starts. ESET said it was the first publicly known malware in the wild to bypass UEFI Secure Boot on fully updated Windows 11 machines. It abused a flaw, CVE-2022-21894, that Microsoft had patched in January 2022, and ESET said it was sold on forums for about US$5,000 from October 2022.

Before you start. The kernel is the one program that can make processes and give each its own walled memory (Processes, Threads & the Kernel). The CPU runs one instruction at a time from memory, and it only reads memory, not disks (The CPU (fetch-decode-execute, the ISA, assembly)). A disk or other device is reached through a controller and the bus (I/O, Interrupts & the Bus). A running shell starts programs by copying itself and then loading a new program over the copy (The program that starts programs).

Lesson 36 of 41 in How Computers Work

The rest of this lesson is part of a plan.

A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year.

See plansAlready a member? Sign in

Or start free: a free account opens lessons 2 and 3 of every track.

In this lesson

  • The problem: RAM is empty at power on
  • Firmware (UEFI): the code that is already there
  • Bootloader: the program that finds the kernel
  • Kernel: it starts, but it has no disk driver yet
  • initramfs: a tiny disk that lives in RAM
  • PID 1: the first program, and the parent of everything
  • Reading the panic at the top
  • Why this order
  • The numbers, in code
  • What an initramfs is made of
  • What the init script does, in order
  • Secure Boot: each stage checks the next
  • Trade-offs and failure modes

Terms it explains: firmware, UEFI, bootloader, kernel command line, initramfs, PID 1, context switch, fork/exec, init/systemd, kernel, MMU + page table, namespaces + cgroups, page (~4KB) / frame, page fault, PID, preemption, process, scheduler, segfault, swap, syscall, thread, user vs kernel mode (ring 3/0), virtual memory.

Lab

The program needs twelve pages at once. What happens when it gets eleven frames?

Drag Frames of real memory from 24 down to 11, then back to 12, and watch Time spent working.

Open The working set

Three long jobs are running when you press a key. How long until the keypress gets the CPU?

Click Take turns, drag How long one turn lasts from 100 ms down to 1 ms, and watch The keypress waits.

Open The time slice

How many workers should a pool have, and why does the answer flip when the tasks mostly wait?

Drag Workers on shift down to the core count, then push Share of each task spent waiting to 90% and watch Finished each second.

Open The thread pool

Related papers

Review How Computers Work