# kernel/: Linux on wasm64 with emulated aarch64 user mode This directory holds the Linux kernel built as a single wasm64 module (Joel Severin's `arch/wasm`, reworked). User space is unmodified aarch64 Linux ELF (ARMv8.0-A), run by the kwemu software CPU (`src/a64`, contract in `include/kw_emu.h`; a decoded-op interpreter and an early JIT). The CPU walks real page tables, so fork, mmap and copy-on-write behave like real Linux. A stock Alpine aarch64 minirootfs boots to a shell under Node, in Chromium, and in WebKit (Safari 27+, whose JSPI it needs), and Ubuntu Base 26.10 (glibc, apt, systemd) boots from a disk image under Node. The browser page and the single-file bundle use a 32-bit-memory build of the same kernel, which needs no memory64. Paths in this file are relative to `kernel/`, except those starting with `src/`, `include/`, `vendor/` or `zig-out/`, which are relative to the repository root. Commands are run from the repository root. ## Build and run `./setup.sh` (repository root) checks the prerequisites and runs `zig build` and `kernel/build.sh all`. By hand: ```sh kernel/build.sh all # wasm-ld 22, Binaryen, UP and SMP kernels + vmlinux32.wasm, Alpine initramfs + bundle, disk kernel/build.sh kernel # the UP kernel only (the quick loop), then the bundle kernel/build.sh smp # the SMP kernel (vendor/build/kernel-smp), then the bundle with the SMP patch node js/cli.ts --smp 2 --append "console=hvc0 rdinit=/usr/bin/kwtest" # kwtest on the SMP kernel from the bundle, 2 CPUs node js/cli.ts # Alpine (the bundle), interactive; Ctrl-] quits node js/cli.ts --append "console=hvc0 rdinit=/usr/bin/kwtest" # kwtest smoke test as /init (the bundle) node js/cli.ts --kernel vendor/build/kernel/vmlinux --append "console=hvc0 rdinit=/usr/bin/kwtest" # same tests on the wasm64 build node js/cli.ts --append "console=hvc0 rdinit=/usr/bin/kwbench" # rough guest speed node test/wasi-node.ts # the kernel with Node's node:wasi for every WASI import kernel/build.sh lower # vmlinux32.wasm (32-bit memory) from the existing vmlinux (fetches wasm-opt if needed) kernel/build.sh bundle # vendor/build/bundle/unkernel-alpine.wasm: vmlinux32.wasm + Alpine in one file (also copied to web/kernel/ for pnpm dev) pnpm install && pnpm dev # the page (web/): Vite dev server on http://localhost:8080/ (prints LAN URLs for phones too) pnpm build:web # web/.output: the built page and its Nitro server (pnpm start:web runs it) node web/test/headless.mjs --shots /tmp/shots # desktop + phone + failure checks in headless Chromium (built output) node --test test/net.test.ts # network stack unit tests (synthetic frames) node web/test/net.mjs # apk/wget through Wisp in headless Chromium kernel/build.sh disk # vendor/build/disk/alpine.ext4 (needs e2fsprogs) node js/cli.ts --disk vendor/build/disk/alpine.ext4 # Alpine on ext4, root=/dev/wda rw, persistent kernel/build.sh ubuntu # vendor/build/disk/ubuntu.ext4: Ubuntu Base 26.10 (needs e2fsprogs) node js/cli.ts --disk vendor/build/disk/ubuntu.ext4 --snapshot # Ubuntu on ext4, a root shell (see Ubuntu) kernel/build.sh datadisk # vendor/build/disk/kwdata.kwsparse.gz, the data disk template (needs mke2fs) node js/cli.ts --data /tmp/kwdata.img # Alpine plus the data disk at /data (created from the template if missing) kernel/build.sh stats # vendor/build/bundle/unkernel-alpine-stats.wasm: kwemu with -Dkwemu-stats (own kernel output dir) node js/cli.ts --kernel vendor/build/bundle/unkernel-alpine-stats.wasm --stats # kwemu's exit counters at exit node --test test/block.test.ts # CowDisk/store logic, kwsparse, FileDisk, requestSync (fake store) node web/test/data.mjs # data disk in headless Chromium: persistence, overlay root, safe mode and recovery, second tab, export/reset/import node test/overlay-node.mjs # the overlay root under Node: persistence, kw.root=initramfs, safe mode for broken changes (--apk, --image2 need the network) ``` `build.sh` steps, each also available on its own (`toolchain`, `binaryen`, `kernel`, `smp`, `lower`, `alpine`, `disk`, `datadisk`, `bundle`; `ubuntu` and `stats` are separate and not part of `all`): * **toolchain**: sparse-clones `llvmorg-22.1.8` (commit checked), applies `patches/llvm/`, and builds `wasm-ld` only. The patches are Joel's GNU-ld linker-script support and weak-signature fix, forward-ported from LLVM 18, plus two fixes for non-shared memory. clang 22 and the other LLVM tools come from the system. LLVM 22 is required, not 18: clang >= 20 and Zig emit table64 `call_indirect` for wasm64, and an LLVM 18 linker produces an invalid module from those objects. * **kernel**: fetches Linux v7.3.4 from kernel.org (commit `7595a62d45e`, shallow), applies `patches/linux/` as branch `kw-arm64-user` (`arch/wasm` is based on Joel Severin's linux-wasm port), and builds `vmlinux` with `kw_defconfig`. Kbuild drives the toolchain through `tools/fake-llvm/llvm-wrapper.py`. The emulator comes from `zig-out/lib/libkwemu.a` (`zig build -Dkwemu-jit=true`, run first; `KWEMU_JIT=0` leaves the JIT tier out; `KWEMU=path` takes a prebuilt library as is); with `KWEMU=none` a stub is linked instead. `include/kw_emu.h` is copied over the kernel's `arch/wasm/include/asm/kw_emu.h` (with a warning) if the two differ. It then runs `lower`. After a reconfigure it checks that `.config` has every option `kw_defconfig` sets. The banner has fixed stamps, so two builds of the same tree are identical: `(unkernel@unkernel)`, a build id (`#` and 12 hex digits, a hash of the tree, the kwemu sources and the toolchain inputs) and the date of the newest commit on the tree (`.agents/kernel.md`, Two kernels). * **smp**: the SMP kernel from the same tree (`kw_defconfig` plus `arch/wasm/configs/kw_smp.config`, kwemu built with `-Dkwemu-atomics=true` in `vendor/build/kwemu-smp`) into `vendor/build/kernel-smp`, lowered like the UP one. `all` builds it (`KW_SMP=0`: not); `kernel` never does. * **binaryen**: downloads the Binaryen release `version_133` (pinned checksum) into `vendor/toolchain/binaryen`. `lower` does this if no suitable `wasm-opt` is found. * **lower**: `vendor/build/kernel/vmlinux32.wasm`, the kernel with its memory and table lowered to 32 bits, which the browser page and the bundle use (see Browser page). It uses `wasm-opt -g --memory64-lowering --table64-lowering`, which takes about 1 s. The `wasm-opt` is `$WASM_OPT`, then `vendor/toolchain/binaryen`, then `PATH`. It must know `--table64-lowering`. If there is none and the download fails, the step fails and a stale `vmlinux32.wasm` is removed. * **bundle**: `vendor/build/bundle/unkernel-alpine.wasm`, `vmlinux32.wasm` with `alpine.cpio` (gzipped), its command line and, if it exists, the data disk template in custom sections (`tools/bundle.mjs`; `unkernel.initrd`, `unkernel.cmdline`, `unkernel.datadisk`). There is no wasm64 bundle. With an SMP kernel built from the same tree it also has `unkernel.kernel.smp.kwpatch` (`tools/bundle.mjs --smp`), a patch from the UP kernel to the SMP one (`tools/kwdiff.mjs`, 1.3 MiB), which the runtime applies when it is asked for more than one CPU. bundle.mjs refuses an SMP kernel of another build (banners that differ in more than `SMP`, another `KW_ABI_VERSION`); build.sh then warns and bundles without the patch, or fails with `KW_SMP=1` (as in `all`). The patch is cached in `vendor/build/kernel-smp/up.kwpatch` while both kernels stay the same. `kernel`, `smp`, `lower`, `alpine` and `datadisk` refresh the bundle when both inputs exist; without a template it warns and bundles none. * **datadisk**: `vendor/build/disk/kwdata.kwsparse.gz`, the template of the data disk (see Block devices): an empty ext4 file system labelled `kwdata`, 4 GiB, 4 KiB blocks, made with `mke2fs -t ext4 -b 4096 -L kwdata -m 0 -J size=8 -E lazy_itable_init=0,lazy_journal_init=0,root_owner=0:0,orphan_file_size=32K` and the ext4 features of `alpine-disk.sh`'s image (pinned in a generated `mke2fs.conf`), checked with `e2fsck -fn`, then encoded by `tools/kwsparse.mjs` (554 non-zero blocks, 17 KiB gzipped). The orphan file is 8 blocks instead of the default 256, because the kernel reads it one block at a time at every mount. Give `orphan_file_size` a unit: a bare number is taken as blocks. The output is reproducible: fixed `-U` and `hash_seed`, and `E2FSPROGS_FAKE_TIME` / `SOURCE_DATE_EPOCH` for the timestamps. `all` runs it before `bundle`, and without mke2fs warns and goes on. * **alpine** (`guest/alpine.sh`), the only initramfs, `vendor/build/initramfs/alpine.cpio`, and `alpine-test.cpio`, which always has kwtest and kwbench: * The Alpine minirootfs 3.24.4 (version and checksum pinned in `tools/env.sh`, `ALPINE_TARBALL=file` overrides). It gets a small `/init` and an inittab with `hvc0::respawn:-/bin/sh` and `::respawn:/usr/bin/kwtty serve` (see vsock). * busybox, zlib, libcrypto, libssl, libapk and apk are the same Alpine packages rebuilt for kwemu's CPU (`guest/alpine-opt.sh`: gcc 16 `-O2 -march=armv8-a` without the vectorizer and with integer registers only where a file allows it, linked with lld; libcrypto on its integer code instead of the NEON and crypto-extension code that kwemu interprets). That made an ash loop about 11% faster, gzip and gunzip 30-50%, `apk add` of larger packages 11%, OpenSSL's SHA-256 2.3x, AES-GCM 1.7x and ChaCha20-Poly1305 30x as fast (2026-11-18); `KW_ALPINE_OPT=0` keeps Alpine's builds. Every other package is Alpine's own aarch64 build. The disk image gets them too. Details in `.agents/guest-packages.md`. * `/usr/bin/kwtest` and `/usr/bin/kwbench` (`guest/kwtest.c`, `guest/kwbench.c`), built static with `zig cc -target aarch64-linux-musl -mcpu=generic` (ARMv8.0), so they run as `/init` (`rdinit=/usr/bin/kwtest`; it powers off, or halts on a failure) or from the shell. They come as a second cpio archive after the image's, which the kernel unpacks after the first. With `KW_RELEASE=1` (set by the release workflow) `alpine.sh` leaves them out of `alpine.cpio`, so release bundles, the npm package and the deployed page have no kwtest; boot a release bundle with `--initrd alpine-test` to run it. The choice is in `alpine.sh`, not `build.sh`, because `build.sh` is part of CI's kernel cache key. Both archives have the same image id (`/usr/lib/kw-image`), which leaves the test programs out. * `/usr/bin/glimmer`, built the same way (see Display, input and sound), and so are `/usr/bin/kwvsock`, `/usr/bin/kwshm`, `/usr/bin/kwtty` and `/usr/bin/kw9p` (see vsock, Host file systems and Shared memory). * The cpio archive is written by `tools/mkcpio.py`; no root is needed. * **disk** (`guest/alpine-disk.sh`, `DISK_SIZE`, default 512M; `all` keeps an existing image that is newer than its inputs, `disk` always rebuilds): the same minirootfs as a sparse ext4 image, without root: `mke2fs -d` from the extracted tree, then `tools/ext4-owners.py` emits debugfs `sif` commands that make every inode root-owned and restore the tarball's exact modes and owners (setuid, `/etc/shadow` root:shadow). Inode tables and journal are zeroed at mkfs time (no lazyinit writes on first boot); `e2fsck -fn` checks the result. Boot uses the real `/sbin/init` (busybox) with an inittab running `/etc/kw-rc` (mount -a, hostname), `/etc/kw-net.sh` and a shell on hvc0; `::shutdown:/etc/kw-shutdown` kills everything and remounts `/` read-only, so `poweroff` leaves the fs clean. * **ubuntu** (`guest/ubuntu-disk.sh`, `DISK_SIZE`, default 2G sparse; `UBUNTU_TARBALL=file` overrides the download): Ubuntu Base 26.10 arm64 (`ubuntu-base-26.10-base-arm64.tar.gz` from `cdimage.ubuntu.com/ubuntu-base/releases/26.10/release/`, SHA-256 pinned in `tools/env.sh`) as `vendor/build/disk/ubuntu.ext4`, built like the Alpine disk. See Ubuntu below. The CLI (`js/cli.ts`, run by Node directly; `node dist/cli.mjs` after `pnpm build`, `npx unkernel` once installed) has the page's defaults: Alpine from the bundle (`js/unkernel-alpine.wasm` is a symlink to `vendor/build/bundle/unkernel-alpine.wasm`; `dist/` has a copy), and `vendor/build/kernel/vmlinux32.wasm` for anything else. `--help` lists the options and exit codes. Options: `--kernel` (or a positional path; either build or a bundle), `--initrd alpine|none` or a cpio path (a bare name is `vendor/build/initramfs/.cpio`), `--disk image|URL` (repeatable: wda, wdb, ...; a file is written in place, an http(s) URL is range-fetched with an in-memory overlay; with a disk and no `--initrd`/`--append` it boots `root=/dev/wda rw`), `--snapshot` (file writes go to a memory overlay), `--mem MiB` (512), `--append`, `--timeout s`, `--data FILE` (the data disk, after the `--disk` disks: a file used in place, created sparse from the template if missing: `--data-template`, else the bundle's, else `vendor/build/disk/kwdata.kwsparse.gz`), `--stats` (also prints the JIT counters), `--no-jit` (kwemu interprets only), `--size COLSxROWS`, and `--input` for scripted typing (`\n`, `^C`, `{N}` = pause N s, `{sync}` = raise the sync IRQ and log when the next block flush arrives), `--display[=WxH]`, `--sound` and `--sound-wav FILE` (see Display, input and sound; `--help` lists the `--input` tokens that dump a frame and inject keys and mouse events). Networking is on by default; `--no-net` removes the device, `--net-mtu N` sets the MTU handed out by DHCP, and `--net-wisp URL` sends the guest's TCP through a Wisp server instead of host sockets. `build.sh` also takes `KSRC=dir` (a kernel git worktree), `KOUT=dir` and `KOUT_SMP=dir` (the two kernels' build outputs) and `KW_BUILD=dir` (the root of every build output, default `vendor/build`), so a branch can be built without touching the main tree or its outputs; the header of `build.sh` lists the rest (`KW_SMP`, `KWEMU`, `KWEMU_SMP`, ...). Downloads are pinned: the kernel base commit and the LLVM tag/commit in `build.sh`; Binaryen, Alpine and Ubuntu Base by SHA-256 (`build.sh`, `tools/env.sh`); the page's npm dependencies (wterm, React, Tailwind) through `pnpm-lock.yaml`. Host tools are taken from real binaries on `PATH`, skipping wrapper scripts (`tools/env.sh`, `use_real_host_tools`). ## Networking * **Kernel:** `kwnet` (`drivers/net/kwnet.c`) is an Ethernet device whose frames are copied to and from the host (`wasm_driver_net_init`/`send`/ `rx_len`/`recv`). Received frames raise IRQ 2 in `wasm_host_irqs`, polled like the console, and are drained by NAPI into GRO. The device claims checksum offload and TSO and marks RX `CHECKSUM_UNNECESSARY`, so the guest computes no checksums and sends 64 KiB TCP segments. Networking is optional: when `wasm_driver_net_init` returns < 0 (the runtime does that without `opts.net`; a host without networking can stub it so) no device is registered. * **Host:** `js/core/net.ts` (`NetStack`) is a user-mode stack ("slirp-lite") that terminates the guest's frames. Guest 10.0.2.15/24, gateway 10.0.2.2, DNS 10.0.2.3. It answers ARP, runs a DHCP server, answers DNS A queries through the backend (AAAA and other types get an empty answer), answers pings to the gateway and DNS addresses, and terminates TCP. TCP handling covers the handshake, MSS and window scaling, flow control both ways, go-back-N retransmit after 1 s, FIN half-close and RST. Each connection is bridged to a backend: * Node (`js/node/net.ts`, `directBackend()`, the CLI's default): real sockets and `dns.lookup`. With `hostLoopback` (the CLI sets it), TCP to 10.0.2.2 goes to the host's 127.0.0.1. * Browser page (`web/src/net.ts`, outside the SDK): Wisp (below); `?net=0` or `?wisp=0` removes the device. (A WebSocket-to-TCP relay the page used to offer is in git history.) * Wisp (`js/core/net-wisp.ts`, `wispBackend()`, Wisp v1; Node and browsers): the guest's TCP connections multiplexed over one WebSocket to a Wisp server (wisp-js, epoxy-server, ...). The default list is `DEFAULT_WISP_SERVERS` (the project's server, `wss://wisp.pi0.io:6680/`), exported by the SDK; on the page `?wisp=URL[,URL...]` replaces it. The CLI uses it with `--net-wisp URL`. That server has an allow list of expected Origins (`http://localhost` is on it); anything else, including no Origin, gets 404. On Node, whose WebSocket sends no Origin, the Node entry's `wispBackend()` and the CLI send `Origin: http://localhost` (`NODE_WISP_HEADERS`, overridable with the `headers` option, which browsers ignore). A page served from an origin outside the list needs its own Wisp server. With several URLs all are opened at once and the first to finish the handshake wins. Wisp is weaker than direct sockets, and the guest can tell: * no DNS: lookups get stable fake addresses from 198.18.0.0/15 and the server resolves the name, so every name "resolves" and a bad one fails at connect time; * no connect acknowledgement: the guest's connect succeeds at once, and a refused or unreachable host becomes a reset; * no half-close: the guest's FIN is not forwarded; * flow control covers only guest-to-server data (credits counted in packets); server data is buffered in the page without a limit. `?wisp=0` disables the fallback: DHCP still works, DNS gets SERVFAIL (musl gives up after its 5 s timeout), and TCP gets a reset. A `ws://` Wisp server cannot be used from an `https://` page (mixed content). * **Guest:** the Alpine inittab runs `/etc/kw-net.sh`, which brings up `lo` and, if eth0 exists, runs `udhcpc` (it writes `/etc/resolv.conf`). The guest clock is host wall time, so TLS works. apk uses the minirootfs's https repositories, but starts with `main` only: every apk command that loads the indexes parses all enabled ones, ~0.65 s for main and ~2.7 s with community (2026-11-15). The community line is in `/etc/kw-apk-lazy`, and `/etc/kw-apk-enable` appends it to `/etc/apk/repositories` when something needs it; it stays there. By hand: `/etc/kw-apk-enable`, or append the line yourself. Packages installed with `apk add -X URL` are not upgraded later (apk no longer has their repository), so the repository is enabled for good instead. In an interactive root shell with a default route, a command that is not found (`htop`, `node`) is installed with `apk add cmd:NAME` and then run (`/etc/profile.d/kw-apk.sh`, a busybox ash `command_not_found_handle`, and `/etc/kw-apk-install`). ash passes the hook only the command name, so the arguments come from the history line, and only for a simple line: after `htop; ls` it asks you to run the command again. `$?` is 127 either way. `KW_AUTO_APK=0` turns the hook off. kw-apk-install does not ask apk: it looks the command up in a list of the `cmd:` names each cached index provides, built from the index when first needed and again when the index changes (`/var/cache/kw-apk/*.cmds`). Building takes ~1.2 s for main and ~3.1 s for community, a lookup ~0.1 s (2026-11-15). A command in none of the enabled repositories is looked up in the lazy ones: their index is fetched with wget to the file name apk uses for its cache (`APKINDEX.<8 hex digits of sha1(index URL)>.tar.gz`, unless the page has pushed it there), and on a hit the repository is enabled and apk reuses that file rather than downloading it again. kw-qemu enables community too (for `qemu-ARCH`). * **`~/.local/bin` comes first on PATH** (`/etc/profile.d/kw-path.sh`, `kernel/guest/kw-path.sh`): Alpine's `/etc/profile` sets a fixed PATH, and this adds `$HOME/.local/bin` in front of it for every login shell (the console, terminal sessions, `sh -l`); kwtty gives programs it starts directly the same PATH (see vsock). Per-user installs go there (`pip install --user`, the fx and claude installers), and so do the page's stand-ins for fx, claude and opencode, which install the real program on their first call (.agents/web.md, Stand-ins). * **bwrap** is a shim too (`/usr/local/bin/bwrap`, `kernel/guest/bwrap-shim.sh`): the kernel has no seccomp, so it drops `--seccomp FD` and runs bubblewrap's `/usr/bin/bwrap` with the rest. GTK programs need it to load images (Xfce). * **curl** is a shim (`/usr/local/bin/curl`, `kernel/guest/curl-shim.sh`) over busybox wget, because the real one costs about 2.4 MB of download and 5 MB of RAM. It handles only GET requests with `-L` whose result it can reproduce exactly (`curl -fsSL URL | sh`, `curl -fLo FILE URL`; options `-f -s -S -L -k -g -o -O -H -A -e -m`). Everything else (other options, a body, no `-L`, credentials, an HTTP error without `-f`, a TLS failure) runs the real curl, installed on first use by `/etc/kw-apk-install curl`; after that, the shim execs `/usr/bin/curl` directly. Output is written only after a complete transfer, so `curl | sh` does not stream. * **x86_64, riscv64, i386 and arm binaries** run through qemu-user (aarch64 is native; the kernel has no AArch32, so 32-bit arm needs qemu too). i386 also covers i486-i686 (Alpine's `x86`), and arm covers armv5-armv7 (`armhf`, `armv7`), little-endian only. The kernel has `CONFIG_BINFMT_MISC`, and the inittab runs `/etc/kw-binfmt.sh`, which registers the four ELF types (flag P) with the interpreter `/etc/kw-qemu`, which runs the binary under `qemu-ARCH` (ARCH is `x86_64`, `riscv64`, `i386` or `arm`). The first time an ARCH is needed (as root, with a network, under a lock so parallel execs do not race apk) it installs `qemu-ARCH` and a library root for dynamic binaries at qemu's default prefix `/usr/gnemul/qemu-ARCH`: musl, libgcc, libstdc++ and gcompat (glibc's loader names and sonames on top of musl, so simple glibc binaries run too), about 4 MB, verified with that architecture's keys from `alpine-keys`. Add more with `apk add --root /usr/gnemul/qemu-ARCH --arch APKARCH --keys-dir /usr/share/apk/keys/APKARCH PKG` (APKARCH is `x86` for i386 and `armv7` for arm). Expect it to be several times slower than native aarch64 code (riscv64 kwemu with its JIT measured about 7x): qemu's TCG output is interpreted by kwemu like any other code. * **`kw-arch ARCH [command...]`** runs a command (default: a shell) with `uname` and `arch` reporting x86_64, riscv64, i686 or armv7l instead of aarch64, for installers that pick their download by `uname -m`: `curl -fsSL https://opencode.ai/install | kw-arch x86_64 bash`. Only the commands are faked (shims in `/usr/lib/kw-arch` first on PATH), not the `uname()` syscall. * **Not implemented:** * IPv6 (off in the kernel) and IP fragments. * UDP other than DHCP and DNS; other datagrams get ICMP port unreachable. * ICMP to anything except 10.0.2.2/3. There is no ping to the internet. * TCP SACK and timestamps, and inbound connections (no port forwarding). ## Block devices (kwblk) * **Kernel:** `drivers/block/kwblk.c`, blk-mq, one hw queue (depth 32), disks `wda`, `wdb`, ... probed at boot from the host (`wasm_driver_block_info`). `->queue_rq()` writes the request (op, sector, direct-mapped segment addresses) into its PDU and calls `wasm_driver_block_submit`, which never suspends, so it is fine in blk-mq's atomic dispatch context (no `BLK_MQ_F_BLOCKING`, no kthread). The host either completes it synchronously (return <= 0 = status) or returns 1, later writes the status into the PDU, queues it and raises IRQ 3; the handler drains `wasm_driver_block_reap()`. Like the console IRQ it is polled on user-mode exits and in idle, which the host wakes, so other tasks keep running while a range fetch is in flight. Read, write, flush (volatile write cache), discard and write-zeroes (if the backend has them). * **Host:** `js/core/block.ts` (`BlockHost`, hooked into the `Kernel` via `opts.disks`), backends: * `FileDisk` (`js/node/disk.ts`, `openDisk()`): an image file, `readSync`/ `writeSync` straight into kernel memory, flush = `fdatasync`. * `HttpBase`: read-only base fetched with HTTP Range requests in 256 KiB chunks (adjacent misses coalesced up to 4 MiB, in-flight dedupe), kept in memory. * `CowDisk`: copy-on-write overlay in 4 KiB blocks over a base (ext4's 4 KiB writes never need the base). Without a store the overlay is in memory. With an `IdbStore` (`js/web/disk.ts`, `openHttpDisk()`, `openDataDisk()`) it is loaded lazily: memory holds only the blocks written since their last committed save, plus the set of block numbers that have a record. Reads take memory, then IndexedDB (one `getAll` over the request's key range), then the base. A read that goes to IndexedDB also fetches the stored blocks after it (8, doubling to 128 while the misses stay sequential) into a readahead buffer of at most 4 MiB, which a read consumes and a write drops. A partial write of a block that is not in memory is a read-modify-write; writes to a block wait for an earlier pending one, so they apply in submission order and a stale fetch never overwrites a newer write. Discard and write-zeroes store an empty (zeros) record, or, over an all-zero base, delete the record. * `ZeroBase` / `SparseBase`: an all-zero base (the data disk) and one made of a few blocks (a kwsparse image; a snapshot copy). * **Persistence semantics.** The disk has a volatile write cache (the driver advertises flush): a completed write is only in the page's memory. Each flush saves every block written before it in one IndexedDB transaction (durability `strict`) and completes when that commits; a flush issued while a save is in flight waits for it. So the saved state is always the state at some completed flush, which ext4's journal handles like a power cut. What is lost when a tab dies is what was written after the last flush (ext4 commits every 5 s; `sync` or fsync flush at once). If a save fails (quota, disk error) its blocks stay dirty for the next flush and the flush returns EIO; the page reports it (a full quota as `QuotaExceededError`). The IndexedDB connection is reopened if the browser closes it or another tab needs a version change, and a failed transaction is retried once. `strict` rather than the default or `relaxed`: a flush is where the guest asks for durability, and only strict also survives an OS crash or power loss; it costs one device flush per guest flush. * **requestSync.** `Kernel.requestSync({timeout = 3000})` (in the SDK: `KernelInstance.sync()`) sets IRQ 4 (`WASM_IRQ_SYNC`) in `wasm_host_irqs` and wakes the kernel, which clears it and runs `ksys_sync()`. It resolves true once every persistent disk (a `CowDisk` with an attached store, a writable `FileDisk`) has completed a flush issued after the call, or false on the timeout; then it clears the bit itself, because a kernel without IRQ 4 never does. * **Page:** the page attaches no root disk (it boots the bundled initramfs only); `openHttpDisk()` is for SDK users. * **Page, data disk** (`web/src/data.ts`, on by default where IndexedDB exists, `?data=0` turns it off): an ext4 file system labelled `kwdata`, 4 GiB, that the guest finds by label and mounts at `/data`. It is the page's only kwblk disk, `wda`. * Template: the bundle's `unkernel.datadisk` section; without one the page runs without a data disk and logs why. On first use its blocks are copied into the store in one transaction, which then marks the store initialized; after that the disk is the store over a `ZeroBase`, and a new template never touches it. * The store is `kwdisk:kwdata-v1`, keyed by the format version, not by the template or an ETag. It is never cleared implicitly: if its identity (format, size) does not match, the page does not attach it, runs a fresh in-memory disk and says why (other `kwdisk:kwdata-*` versions are only logged). * One tab at a time: `navigator.locks.request('kwdisk:kwdata', {ifAvailable: true})`, held for the page's lifetime; where Web Locks are missing (plain-http LAN pages are not a secure context) a BroadcastChannel probe, which two tabs opened in the same instant can both pass. A tab without the lock gets an in-memory snapshot, a copy of the saved disk if it is at most 64 MiB (one read transaction, so consistent), else the template, and a WARN line, toast and panel note. * `navigator.storage.persist()` is requested; the Environment tab's *Storage* line shows whether it was granted and the usage (`storage.estimate()`). * The page calls `requestSync()` when it is hidden (`visibilitychange`) and on `pagehide`, and Reboot waits for it (up to 3 s). * `KW.exportData()` (panel: *Export*) syncs, then downloads the disk as `kwdata-