1. How to use this book

Why this book exists

You already run machines. You have NixOS hosts on a tailnet, systemd units you wrote, containers where they help, and a shell history that reads like a small distribution. What you do not have is a machine you can answer “why did it do that?” about all the way down — because between your software and the silicon sit a Linux kernel, a KVM, and a VMM, each of which you use and none of which you have written.

This book ends that with two machines you wrote.

Capstone A — ward. A jailer plus a Linux-KVM VMM that stays running on your NixOS hosts. ward (Go) supervises the KVM path: it holds images, identity, and policy, and launches jailed wick (Rust) processes — one per guest — which drive /dev/kvm directly. make check boots two guests under KVM: a unikernel on vsock, and a stripped Linux that runs one command and dies. This is the machine you can put next to aecd on a Tuesday.

Capstone B — hearth. A type-1 hypervisor that is itself a unikernel: one address space, no host kernel, no syscall table. It boots as QEMU -kernel on the machine, owns the page tables and the UART, and enters a unikernel guest with no Linux in the trusted computing base. The guest console comes out the hypervisor’s UART. This is the object that is not for sale. The first is how you learn virtio and guest bring-up against a host that already has files, TAP, and a clock; the second is the same VMM idea after Linux is deleted.

The two floors this book builds Two floors. Bottom, capstone A, the host kernel present: a unikernel guest and a stripped Linux guest over wick, a Rust VMM, jailed under ward, a Go supervisor, over NixOS with /dev/kvm. Top, capstone B, the metal: a unikernel guest with no Linux in the TCB over hearth, a C hypervisor using the RISC-V H-extension on QEMU virt with AArch64 EL2 named, one address space with no host kernel and no syscall table, which owns the machine and boots as a QEMU -kernel. Beside both floors runs ember, the literacy kernel that becomes the guest you understand. B · The metal unikernel guest · no Linux in the TCB hearth (C) · RISC-V H-ext on QEMU virt AArch64 EL2 named · owns the machine one address space, no host kernel no syscall table · boots as QEMU -kernel A · The host kernel present a unikernel guest and a stripped Linux guest wick (Rust VMM) jailed under ward (Go) NixOS host · /dev/kvm ember · the literacy kernel becomes the guest you understand

The two floors of the figure are two answers to “who owns the machine?” On the bottom floor, Linux does, and your work wraps it: wick under ward, guests on top, /dev/kvm as the door. On the top floor, hearth is the machine — there is nothing under it to be jailed by or to call into. ember, drawn beside both floors, is the literacy kernel: a small teaching kernel you write in Part II that later becomes, with its userland stripped, the unikernel guest you understand from the inside.

What is granted, what is thin

Granted, and therefore skipped: Unix, C, Go, NixOS, podman, applied crypto, running a fleet, and building tools from scratch. There is no C primer here, no “what is a process”, no Kubernetes, no Raspberry Pi as the teaching machine, no real-mode x86 archaeology, and no hidden plan to replace your NixOS hosts with hearth. Capstone B is competence, not a migration plan.

Thin, and therefore where the book spends its time:

  • Privilege and page tables from the CPU’s side — M/S/U and HS/VS/VU modes, control and status registers, the Sv39 walk, what sret actually does.
  • Nested paging — the two-stage translation a hypervisor owns, and why a guest page fault is not a hypervisor page fault.
  • KVM as an API — what the ioctls wrap, learned after you have driven the same interface by hand.
  • Virtio as a protocol — descriptor chains, available and used rings, written once and fronted twice.
  • The Firecracker cut — what a microVM deletes, and why that makes it fast and small.
  • Unikernels as a deleted kernel — what remains when the user/kernel split inside the guest goes away.
  • What remains of a hypervisor with no /dev/kvm — the question hearth answers with its whole design.

The four trees in the repository you cloned, and which may die:

  • ember (C) — a teaching kernel on RISC-V in QEMU. Literacy. It may die; by the time it could, it has already done its work.
  • wick (Rust) — a Firecracker-shaped one-process VMM on Linux KVM. Kept.
  • hearth (C) — the type-1 unikernel hypervisor. The point.
  • ward (Go) — supervisor for the KVM path only. It does not supervise hearth; hearth is the machine.

C owns anything that owns page tables. Rust owns the Linux VMM. Go owns the supervisor.

How the book is built

Four trees, one spine

The finished repository you cloned has this shape:

tsp/
├── ember/                 # C, RISC-V teaching kernel (Part II)
├── hearth/                # C, type-1 unikernel hypervisor (Part VII)
├── wick/                  # Rust VMM on Linux KVM (Part V)
├── ward/                  # Go supervisor, KVM path only (Part IX)
├── labs/chNN/             # one directory per lab chapter
├── book/                  # this book (HonKit sources)
├── docs/superpowers/      # specs and plans (not published)
├── deploy/                # Caddy site block
└── Makefile

The four trees are four codebases with one contract: everything a chapter claims about them is checked by make check.

The chapter template

Every chapter after this one has the same six sections, in order:

  1. Why this layer exists — what breaks without it, and where it reappears in wick or hearth.
  2. Mechanism — the idea, with the hardware interface derived where it is used: CSRs, page-table walks, virtqueue rings, ioctls.
  3. Walkthrough — code listings extracted from the reference source.
  4. Exercises — short problems, answers in collapsed blocks.
  5. Lab — a build task that boots, KVM_RUNs, or srets into a guest.
  6. Further reading — primary sources, cited by title and year.

Labs boot or they are not labs

The labs run in labs/chNN/. QEMU hosts ember and hearth; a Linux host with /dev/kvm runs wick and ward through KVM_RUN. A lab skipped because the machine at hand has no /dev/kvm is documented in the lab’s notes — the skip is an honest state, not a pass, and the lab is rerun on a KVM host before the part is called done. A chapter that only prints listings is not done.

Listings cannot drift

Every code listing in a chapter is a copy of a marked region of a real source file that compiles and passes its tests. In the source, the region is bracketed by comment markers — /* listing:NAME */ and /* end-listing:NAME */ in C, with the language’s own comment form in other trees. In the chapter, the directive <!-- listing: PATH#NAME --> sits on the line immediately before a fenced code block, where PATH is relative to the repository root; the block under it is regenerated, never hand-edited.

tools/listings walks every Markdown file under book/, extracts each named region, and compares it byte-for-byte with the fenced block. make listings fails the build on any drift or on a dead SUMMARY.md link; make sync rewrites stale blocks from source. The consequence: a listing in this book is never a paraphrase, never a version from three refactors ago. When you read a listing, you are reading the code the tests ran against.

The test that names the object: if the hearth image has a syscall table, it is wick. A “bare-metal” hypervisor that secretly calls into Linux is not capstone B; the book fails itself if that ever appears.

The route: KVM is a wrapper

The spine is ordered so that interfaces arrive before the machinery that wraps them.

Parts I–III build literacy. Part I is the machine itself — C, a linker script, QEMU’s RISC-V virt board; bytes, privilege, Sv39, traps, time; every chapter boots. Part II writes ember: a guest-shaped kernel with processes, a heap, pipes, virtio-blk as a guest, a small file system, userland. Part III reads the shapes of an operating system — monolith, microkernel, exokernel, library OS; what Linux actually is from this vantage; xv6; seL4 — so the vocabulary of isolation budgets exists before virtualization needs it.

Part IV derives the hardware interface first. Trap-and-emulate and the Popek/Goldberg conditions, then the RISC-V H-extension: HS-mode, VS/VU, hstatus, hedeleg. Chapter 19 is nested paging — two-stage translation, why a guest page fault is not a hypervisor page fault — and its lab is hearth chapter zero: identity-map a payload in VS-mode and sret into it with no devices. Only then, in chapter 20, does /dev/kvm appear — as Linux wrapping exactly the interface you just drove by hand. The ioctl is not the subject; it is the wrapper. Chapter 21 settles the device bus (virtio-mmio) and chapter 22 implements the virtio backend once, against a ring in shared memory, to be fronted in both wick and hearth.

Parts V–VI build the guests and their host. Part V builds wick: what a microVM deletes, booting someone else’s kernel, block/net/vsock, the jailer, snapshots, density. Part VI builds the unikernels the book will host twice, and chapter 32 freezes the guest contract — a packed boot-info block, not FDT — before hearth exists. Nothing in Part VII may change it.

Part VII builds hearth. The image that owns the machine; entering a guest; emulation vs passthrough; the virtio backend without a host kernel; several guests; interrupts into the guest. Parts VIII–IX climb the isolation ladder, build ward, and land the two capstones.

The dialects, stated plainly. The written hypervisor ISA is the RISC-V H-extension on QEMU virt. The second port is AArch64 EL2 (stage-2, HCR_EL2, vGIC), the subject of chapter 39, with QEMU virt,virtualization=on as a first-class capstone-B target — and the path onto a Raspberry Pi with EL2 if you ever want one real board. VMX is an optional later dialect, not chapter 39. Apple Silicon is a fine QEMU host and is never a type-1 target.

Environment

Install the host toolchain with make deps: on Omarchy it is omarchy pkg add for the QEMU system emulators, cross gcc’s, and dtc; on Debian/Ubuntu the same via apt; on NixOS, nix develop from flake.nix builds the dev shell with everything pinned. rustc and go come from your own toolchain (mise, rustup) — deps does not install them. Go 1.27 and Node 26 are pinned in mise.toml for the book’s own tools.

Then run make doctor. It prints one line per check and exits non-zero on any failure:

ok   make                     GNU Make 4.4.1
ok   rsync                    rsync  version 3.5.0-g471e17dc  protocol version 32
ok   dtc                      Version: DTC v1.8.1
ok   qemu-system-riscv64      QEMU emulator version 11.1.1
ok   qemu-system-aarch64      QEMU emulator version 11.1.1
ok   riscv64-gcc              riscv64-linux-gnu-gcc (GCC) 16.2.1 20260810
ok   aarch64-gcc              aarch64-linux-gnu-gcc (GCC) 16.1.0
ok   rustc                    rustc 1.98.1 (48a229cea 2026-09-01)
ok   go                       go version go1.27.1 linux/amd64
ok   aarch64-virt-el2         virt,virtualization=on accepted

Read it line by line. make, rsync, and dtc are the book’s own plumbing. The two QEMU lines are the emulator pair the whole book runs on — one for ember and hearth, one for the chapter 39 dialect. The two cross lines are the GNU compilers for guest images; the tool accepts the naming variants distributions use (riscv64-linux-gnu-gcc on Arch and Debian, riscv64-unknown-linux-gnu-gcc under Nix pkgsCross, and the *-unknown-elf-* bare-metal form). rustc builds wick, go builds ward and the book’s tools. The last line boots nothing: it asks qemu-system-aarch64 to accept -machine virt,virtualization=on, because a QEMU that rejects EL2 would sink chapter 39’s labs. A FAIL on any line means make deps (or nix develop) did not finish its job on that machine.

Which host plays which role:

Role Host
QEMU host for ember / hearth-as-metal any machine, including Apple Silicon
KVM host for wick / ward a Linux host with /dev/kvm — in practice your NixOS boxes
Never a type-1 target Apple Silicon (no EL2 under macOS)

Any machine, the Mac included, is a valid QEMU host for ember and for hearth as metal — that is TCG, and it needs no privileges. The wick/ward labs need a Linux host with /dev/kvm.

The book keeps the same host-command rules your fleet does, and its labs never ask you to break them: machines are addressed by MagicDNS name, never tailnet IP; nothing is ever piped into an interpreter; and no lab uses a foreground sleep as a timer — when a lab needs to wait for something it waits on the thing itself, a pipe or a socket, not on a clock.

Lab: take stock

Nothing boots in this chapter. The first image that boots is chapter 2’s. What this lab produces is knowledge of your own machines, written down.

On every machine you intend to use with this book, from the repository root:

make doctor

Record, in a file outside the repository (never commit it):

  • which machine is the QEMU host — the one whose doctor output is fully ok, where ember and hearth-as-metal labs will run;
  • which machine is the KVM host — the Linux box with /dev/kvm present, where wick and ward labs will run;
  • every machine where /dev/kvm is absent or doctor fails, and what the failing line said.

If doctor fails on the machine you meant to use as the QEMU host, fix that before chapter 2: every chapter from there on boots.

Further reading

The three documents this book keeps open:

And the paper behind the microVM cut, read in Part V:

results matching ""

    No results matching ""