There are two ways to build and run the Plan 9 fork used in Principia Softwarica: using Docker (quickest), or building from source (more educational).
This builds everything in a container and extracts a bootable disk image:
git clone https://github.com/aryx/principia-softwarica cd principia-softwarica docker build -t principia . docker run -u $(id -u):$(id -g) --rm -v "$PWD:/out" principia \ sh -c "cp kernel/COMPILE/9/pc/9qemu /out && cp dosdisk.img /out"
Then run Plan 9 under QEMU:
qemu-system-i386 -smp 4 -m 512 -kernel ./9qemu -hda ./dosdisk.img
This is the more educational path. You will use the Plan 9 C toolchain itself to compile the entire operating system.
Because Plan 9 uses a special dialect of C and non-standard assembly, you cannot use gcc or clang directly. You first need goken9cc, a fork of Ken Thompson's C compilers that can cross-compile Plan 9 from Linux, macOS, or Windows.
# Prerequisites: gcc, libc6-dev, byacc (or bison) sudo apt-get install gcc libc6-dev byacc git clone https://github.com/aryx/goken9cc cd goken9cc ./configure # Bootstrap mk and rc using gcc (since we can't use mk to build mk yet) ./scripts/build-mk.sh # Copy the freshly built mk/rc/ed into bin/ so they're on PATH ./scripts/promote-mk.sh # Set PATH, MKSHELL, and NPROC . ./env.sh # Now build the full toolchain using the bootstrapped mk mk mk install
This installs the Plan 9 C toolchain —
5a, 5c, 5l (targeting ARM) and
8a, 8c, 8l (targeting 386) —
as well as Plan 9 utilities like mk and rc.
These are cross-compilers: they run on your host machine (Linux amd64
or arm64) but produce binaries for the Plan 9 target architecture.
git clone https://github.com/aryx/principia-softwarica cd principia-softwarica # Choose your target: pc (386) or pi (ARM) cp mkconfig.pc mkconfig # or: cp mkconfig.pi mkconfig . ./env.sh mk mk install mk kernel
This compiles all Plan 9 programs and installs the binaries in
ROOT/386/bin or ROOT/arm/bin depending
on the target architecture.
You need the dosfstools and mtools
packages installed. Then:
mk disk
Install qemu-system-x86, then:
mk run
This boots Plan 9 in a QEMU window. You can run rio to start
the windowing system and with a right click get the system menu; select New
and drag and draw a window in which a new terminal
with a shell will appear where you can compile programs,
browse the filesystem, and explore the code described in the
books.
Plan 9 can also run on a physical Raspberry Pi. Use
mkconfig.pi instead of mkconfig.pc
when building, and write the resulting image to an SD card.
The Principia books are not introductions to programming or computer science. They assume you already have a rough idea of how a kernel works, how a compiler works, etc. You should be familiar with the C programming language and comfortable with Unix-like systems. The books cover the practice — the actual source code — not the theory.