FreeBSD unkernel

Starting

How it works

This is FreeBSD 16-CURRENT running entirely in your browser: the real FreeBSD kernel, compiled to WebAssembly, running real FreeBSD/arm64 programs. No server runs anything; the page only downloads files.

The kernel

FreeBSD's kernel gains a new architecture, wasm, built with LLVM from FreeBSD's source as 64-bit WebAssembly and lowered to 32-bit memory with Binaryen so every browser can run it. WebAssembly has no MMU, so kernel addresses are offsets into its memory: kernel memory is physically contiguous, and disk I/O works on lists of pages instead of mapped buffers. Each kernel thread has its own stack, switched with JSPI (WebAssembly JavaScript Promise Integration); interrupts are bits the host sets and the kernel polls.

Programs

User space is an unmodified FreeBSD/arm64 world built from the same tree. Its programs run on kwemu, an AArch64 emulator linked into the kernel: the kernel runs a process until it makes a system call or faults, then handles that the usual way. Each process has its own address space, walked through software page tables.

Disks

The root file system is FreeBSD's minimal base set: UFS, compressed with mkuzip (about 50 MB) and read-only, fetched piece by piece with HTTP range requests as the kernel reads it.

Your changes go to a second disk, kept in the browser's private file system (OPFS). On first boot rc.d/kwdata formats it and mounts it on /data; /usr/local, /root, /home and /var live there (nullfs), and /etc is a union of the image's files and the ones you changed (unionfs). They survive reloads; Reset disk erases them. One tab at a time owns the disk.

Network

The kwnet driver hands Ethernet frames to unkernel's TCP/IP stack in JavaScript, which serves DHCP and DNS. Run under Node it reaches the Internet, and pkg install works; a browser needs a relay server, which this page does not have yet.

Credits

Built on unkernel by Pooya Parsa (source), which runs Linux the same way: this port reuses its AArch64 emulator, its JavaScript host and SDK, and its device protocols. And on the FreeBSD project. The port: freebsd-unkernel and its kernel source.