Input your search keywords and press Enter.

A Week with Plan 9

I spent the first week of 2021 learning an OS called Plan 9 from Bell Labs. This is a fringe Operating System, long abandoned by its original authors. It’s also responsible for a great deal of inspiration elsewhere. If youve used the Go language, /proc, UTF-8 or Docker, youve used Plan 9-designed features. This issue dives into Operating System internals and some moderately hard computer science topics. If that sort of thing isnt your bag you might want to skip ahead. Normal service will resume shortly.
The best way to read Tales From The Dork Web is via email. Sign up below to try it.
This weeks music comes from Jefferson Airplane. Press Play and read on. Screenshots come from various Plan 9 builds. Memes are sourced from the Internet. Renee French drew Glenda the Plan 9 bunny.
Plan What?
Plan 9 From Bell Labs is an Operating System designed by many responsible for Unix. Its more an exploration of ideas than a complete OS. Much of Plan 9 made it into the Google ecosystem, the Go language, Windows and Linux. I wanted to spend a few hours a day over the course of a quiet week learning the bits of Plan 9 that interest me.
There were several things in particular that interested me:

  • The everything-as-a-file concept
  • 9P, Distributed CPU, Auth and FS servers
  • Plan 9s Programming Environment

There are several Plan 9 distributions available. The most well-known is 9front, produced by Cat-v members. Richard Millers Plan9 distribution is a Raspberry Pi port. This features wifi support and other Pi-specific features. Millers distribution is also closer to the original Plan 9.
9Front And Surprise Auschwitz
I started with 9Front as it looks the most active. The FQA is more harmful than good. If you don’t appreciate the odd Nazi death camp pic in the manual as a visual joke, 9Front may not be for you. I wanted to submit my notes for the FQA but not till I I understood what the fuck is with Appendix L. There are 3 types of people wholl see it – Those who wont use 9Front because of it, those whose choice is unaffected by it, and those feeling welcomed by it. My concerns lay with the 3rd group. The Nazi death camp joke author was so courteous I replaced all 9Front links and screenshots from this issue. 9Front doesnt owe me change. I dont owe the project more attention.
I reimplemented everything using Richard Millers Raspberry Pi Plan 9 distribution. As such screenshots here dont always match dates. It turns out exploring Plan 9 on even your oldest Pi is an excellent experience. If you dont have one itll work in Qemu. I tried other distributions but I found Millers Pi distro the best overall.
Day 1 – New Years Eve
Installing Plan 9 on a Raspberry Pi is easy. Download, unpack and write the image. Youll have more fun with a keyboard, 3 button mouse, HDMI connection and Ethernet cable. Before boot I changed the Pi cards cmdline.txt to read (on one line):
readparts=1 nobootprompt=local user=glenda nvram=#S/sdM0/nvram bootargs=local!#S/sdM0/fossil ipconfig= authdom=linux sysname=gentoo
The first thing I noticed was the responsiveness on a Raspberry Pi 3B. Its quicker than Raspbian by a country mile, albeit with quirks. Quanstros newbie guide is very helpful for that first 30 minutes of use. If you install Plan 9, make sure you take it with you.
Unfortunately only my teensiest keyboard worked and its horrific to type on. I followed these steps to connect to my Plan 9 CPU server across my network via Drawterm. I spend most of my day in remote session tools like SSH, Tmux and VNC and RDP. Drawterm didnt feel too different to what Im already used to.
I read Devine Lu Linvegas Rio notes and followed some of Sigrids article on applying patches to enable OS themes. As this is as close as Plan 9 gets to ricing I called the system gentoo. I used the topng command to convert the screenbuffer file to a PNG across an FTP server as though it was a local file.
Day 2 – New Years Day – Getting To Know Plan9
Rio provides Plan 9s GUI, which relies on a 3-button mouse for interaction. The shift key works in-lieu of a middle button. This gets tedious, so try clicking your scroll-wheel. The left mouse button selects. The middle button shows a contextual menu. The right mouse button lists other menu options. Plan 9 also features mouse chording. This means holding several buttons like a piano chord for extra functions. Its mostly for cut and paste.
Menus appear when mouse buttons are held. Letting go selects an option. The right button menus first option is new. You can draw out a terminal window with the right mouse button when its selected.
Inside terminal windows, left and right keys act as normal. The up and down arrow keys scroll the window, not the cursor. The cursor location is set by left mouse click.
Various Plan 9 comp-sci papers live under /sys/docs. These are best viewed with the page command. This appears to render PDF files as images, or at least text cant be selected. The first paper I read was on the sam text editor.
The sam text editor is a text editor with a command language. It shares concepts with vi and ed but has a very different implementation. When opened, sam displays a window containing two smaller blank windows inside. Holding down the right mouse button and selecting the text file changes the pointer. Right-clicking in the bottom window puts the text in the bottom and a sam command line at the top. Right clicking in the top makes text fill the window.
The editing experience is like a worse Windows notepad. The top window provides a command line interface for manipulating text. For example, to save enter w (write). To quit, enter q. The mouse-driven context switching between writing and command windows was painful. Thats not to say sam cant work for you. It just didnt for me.
Web browsing on Plan 9 is a little like passing a kidney stone. Plan 9 mounts web-connectivity via the webfs filesystem at /mnt/web. Theres an example web client on the Pi distribution in /sys/src/cmd/webfs/webget.c.
This sounds like I disliked Plan 9 at first, but that’s not true. Its not bad, its just incomplete. Exploring WebFS was worth the disorientation. I explored it by pulling weather reports from wttr.in. Wttr.in only sends ANSI text if the user-agent matches that of curl. I modified the webget.c example to set a matching user-agent and it pulled the data down first time. No sockets needed.
Plan 9s native terminal isnt ANSI compliant. I emulated and ANSI compliant terminal with the vt command. ANSI glyphs werent rendered. Im sure I could make it better but I was more interested in WebFS workings than front-end output.
Day 3 – 2nd Jan – Security Model and Databases
Most Operating Systems have a root or administrator user. This often comes with special features like raw socket access. In Plan 9 the host owner account (glenda by default), is a normal user. Some services run as glenda and as such the glenda user has elevated access to these services. That aside I saw no special status given to the account.
Any multi-user system needs some form of authentication mechanism. Plan9 has an encrypted store (secstore) for long-term secret storage. Factotum provides run-time key-value storage exposed as a filesystem. Security in Plan9 documents this exceptionally well.
I use ed25519 SSH keys but Plan 9 only supports RSA. After generating and copying an RSA key across to my OpenBSD laptop I was able to SSH in from Plan 9 via the vt terminal. I used password-based authentication to access a freshly installed Raspberry Pi elsewhere. SSH and factotum behaved differently in drawterm across different distributions. I havent looked into why.
Factotum is an agnostic key/value tuple store that just happens to be good for secrets. Factotum exposes itself to the OS through a filesystem. The structure resembles the webfs filesystem.
The man page is excellent. The UX is terrible. Still, its a mind-blowing concept.
These sentences became my Plan 9 mantra for the week.
Thumbing through the wpa client I realised how often I referred to the pre-installed source code. For laypeople still reading this is highly unusual. Plan 9s source code is highly readable, even for bad coders like me.
Another way Plan 9 exposes the everything-as-a-file model is the network database (NDB). This lives in /lib/ndb with networking exposed through /net. As with /proc, the /net hierarchy is oddly similar to Linux in some ways. The /net hierarchy is Plan9s network communication interface. Network connections are handled through this instead of conventional sockets.
The network database stores network configuration settings in several places. This uses a brilliant NDB flat-file database structure. Users query the NDB database using tools under /bin/ndb. What makes NDB especially interesting is that it’s a general purpose text-based database. Gavin Freeborn has an amazing tutorial on getting started with ndb. NDB is also available for non-Plan 9 systems thanks to plan9port. If you use the Go language or Googles Cloud Products you may have used NDB without knowing it.
Day 4 – 3rd Jan – Namespaces and 9P
At a fundamental level a namespace is a way of referring to an objects surface area by name. That sounds abstract, so let me back it up.
Despite Plan 9s world-view, a lot of stuff isnt a file in the real world. A network is a network. A website is a website. OS designers have to choose how applications will interact with these things. In Plan 9 filesystems are the de facto interaction medium. Filesystem mounts are stitched together into a patchwork quilt called a namespace. A namespace is a map of mounts in shell script form, rather than the territory. Just because you can mount something doesnt mean you can access the contents.
Its possible to create entire network services using nothing but shell scripts. This barely scratches the surface of whats possible. Mount the audio file for a system on another continent and you can play audio directly to it. Need to connect two Plan 9 systems but only one has a network card? Import the networked system’s /net hierarchy over serial and borrow the network connection. Need to connect to the office? Import your office desktops /net for an instant tunnel. There’s no distinction between local and remote debugging. You can mount a remote /proc filesystem over 9p and use a local debugger.
If that sounds interesting check out The Use of Namespaces in Plan 9 under /sys/doc. As with all core Plan 9 papers, its well written. This paper also details the 9p protocol underpinning everything.
9P is genuinely mind-blowing. There is no distinction between local and remote resources. There are only those mounted in the namespace and those that arent. 9p makes any resource presentable as a filesystem shareable anywhere in the world.
Day 5 – 4th Jan – Plumbing
When we open a document on an Operating System we expect it to know which application to open. A PDF should open in a PDF viewer. A photo should open in a photo viewer. But how does Plan 9 know what to open? The answer is plumbing.
Plumbing uses a text-based filesystem to manage what happens when a file is accessed. The plumber can check the filename, source, destination, content and act on it. Heres what rules look like:
That might look unimpressive at first. The result is that the user can define what to do with content instead of the OS or Application vendor. What happens when you mix everything-is-a-file with perform-actions-based-on-file-criteria? Magic. It doesnt need to matter where the file is from. Plumbing can act on it specifically or regardless.
Plumbing makes all text hypertext. Highlight a word and send it to the plumber. The plumber acts based on the rules. Select the package number from a delivery notification email. Plumbing could query deliveries without leaving your mail client. Plumbing is like file associations on steroids. In this case the steroids themselves are also on steroids.
Day 6, 5th Jan – ACME
ACME is often described as an editor. In reality it’s a structured text user-interface. This falls somewhere between elements of tmux and the twin Textmode Window Manager. It looks confusing at first but has great ideas. ACME creates windows with text editing capabilities inside. But its so much more than an editor.
Mouse buttons work differently to the rest of Plan 9 which is frustrating at first. After some time using Acme I wish the rest of Plan 9 acted like this. In the screenshot below I have four editing panes. I opened the text file in the top-left pane by typing the full location in the title bar and clicking the right mouse button. Yes, thats correct.
I typed the word win into the editor and middle-clicked it, which opened the bottom left window. win spawns a command prompt in Acme. I then middle-clicked NewCol to create the right-hand column. In a new window I typed <astro. I selected the text with the middle button. When I let go the astro command ran and the output replaced the text.
There is so much more to this that I cant even begin to cover it here. If youd like to see more of Acmes sheer Black Magic Fuckery, Russ Coxs video is superb.
Of course Acme also exports a filesystem. This allows applications to interact with Acmes contents and the application itself. It should be possible to edit a script in Acme that:

  • that when run from within Acme
  • edits the files containing the contents of the Acme window (i.e. the script)
  • modifies the contents of the Acme window, and saves it
  • and launches the script being edited in the Acme window (i.e itself).

Acme is the M.C. Escher art of text editing.
Day 7 – 6th Jan – Programming
Plan 9 has its own C dialect, distinct from others you may be familiar with. There are enough gotchas to make porting painful, but its close enough for anything from scratch. Plan 9 splits compilers by architecture. It does this using almost randomly numbered filenames for compiler and linker. Programming Plan 9 in C was disorienting. Its not bad, its just very different to anything Im used to.
While Acme has amazing features, it has its share of annoyances. I was often tricked by the scrolling-the-window-but-not-the-cursor behaviour. Theres no syntax highlighting. You can jump to specific line numbers using the Sam command language but theres no numbering. In some ways Acme is the ultimate in customizability. An editor where you can edit the menu bar is almost infinitely flexible. In other ways its not. For example, youre stuck with Acme’s tab handling unless you change and recompile the source.
Yet Acme is incredibly powerful. You can run a terminal from it, use page to view docs or use the web command to view web pages. Theres even tic-tac-toe for it.
The C flavour will catch you out at times. The compiler naming is mildly awkward but manageable. Things got easier after building blocks for file i/o, drawing and window management. Standing on the shoulders of previous travellers helped immensely. There are other languages available and of course the rc scripting language. It is nice to have consistent tools for writing GUI applications. The drawing primitives were a joy to use. The GUI menu management was pretty sane compared to most other tools I’ve used. If this was in a cross-platform GUI toolkit Id definitely try it.
Conclusions
Plan 9 is as filled with unpolished brilliance as Mozarts Requiem. Its the Sagrada Familia of Operating Systems. Its creators left long ago but people keep building on the scaffolds. If nothing else, its a collection of fantastic ideas never intended for mass consumption. This is The Holy Mountain of Operating Systems.
Is this a production-grade OS? Hell no. Its clunky, unfinished, and the filesystem model feels consistent but forced. Not everything needs to be complete. As an exploration rather than a product, I think Plan 9 is a success. Plan 9 is the Unix kool-aid acid test, brought to you by Bell Labs Merry Pranksters.
Richard Millers Plan 9 Pi distribution is a great way to give a drawer-dwelling Raspberry Pi or two a new lease of life. Even if you go no further than a wet weekend afternoon figuring it out, its more than youd have done with it otherwise.
Follow the White Rabbit. Turn on, Drawterm in and hop out.
Things You May Have Missed
Jonathan Blows talk covers more than just civilizational collapse. It goes deep into the decline of software quality and the inter-generational loss of technical knowledge. This really is an excellent talk worth watching, and explains a lot as to why your computer is so freaking slow.
Kartik Agaram is building a computer anyone can audit. Hes spent the whole of 2020 working on his Mu Computer to make it a reality. Im impressed how far hes come. Oriol Ferrer Mesià has been building modern retro computer terminals.
Phaedra is the most Gemini thing Ive seen this year. Öppens pulled a blinder with a 55kb (thats right) Android Gemini client that runs all the way back to API 1. The only possible restriction comes with TLS on older devices. Also worth checking out is the Ariane client on the same page.
MVG Goes through the hated Lenslok DRM, possibly the first (and worst) Captcha. I remember bit flipping Lenslok on ZX Spectrum games as a kid. The Apple firmware protection I bypassed used similar state of the art 80s techniques. Plus ca change, eh?
The CIA have released all of their UFO documents. You can download ISOs of the PDFs, as well as some PDFs that now have indexed text all from The Black Vault.
Finally, the regrettable decline of Space Utopias shows the need for optimistic sci-fi.
Periwinkle wrote some brilliant songs from an indigenous American perspective. Her words from 1981 ring just as true today. If you like this Id recommend the rest of the album, from Columbus had six ships to Ode to an Indian Swan. Id like to end with a quote from holocaust survivor and Nazi hunter Simon Wiesenthal:
For evil to flourish, it only requires good men to do nothing.
I hope youve enjoyed this issue of Tales From The Dork Web. Ill be back in two weeks with another issue. If youd like it in your inbox you can sign up below.read more

Leave a Reply

Your email address will not be published. Required fields are marked *