Skip to content

Instantly share code, notes, and snippets.

@baryluk
Last active April 10, 2024 19:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baryluk/e9ba5af68d67e14b8a5716a70656d550 to your computer and use it in GitHub Desktop.
Save baryluk/e9ba5af68d67e14b8a5716a70656d550 to your computer and use it in GitHub Desktop.
Plan 9 in qemu / 9front in qemu
#!/bin/bash
wget -c https://9front.org/iso/9front-9442.0e66f87316e571f7edf5274369ec69a5905507aa.amd64.iso.gz
gunzip -k 9front-9442.0e66f87316e571f7edf5274369ec69a5905507aa.amd64.iso.gz
if ! [ -f plan9.raw ]; then
qemu-img create plan9.raw 10G
fi
exec qemu-system-x86_64 -enable-kvm \
-smp $(nproc) \
-m $((8*1024)) \
-cpu host \
-M q35 \
-cdrom 9front-9442.0e66f87316e571f7edf5274369ec69a5905507aa.amd64.iso \
-net nic -net user,hostfwd=tcp:127.0.0.1:17567-:567,hostfwd=tcp:127.0.0.1:17010-:17010 \
-drive file=plan9.raw,media=disk,index=0,cache=writeback
# When booting, you can use high resolutions using vess driver, for example 2560x1600x32 works.
# Use ps2intellimouse instead of default ps2, to get scrollwheel working.
# (You can also do it post boot with: echo intellimouse > /dev/mousectl or set mouseport=ps2intellimouse in plan9.ini)
# Not that by default there is no unionfs (divergfs), so most of the directories,
# including home directory /usr/glenda/ will be read only. To really get full usability,
# you need to install it to disk, then boot from disk.
# To start networking with DHCP, run ip/ipconfig. It should work out of the box.
# It should configure both IPv4 and IPv6,
# and DNS (usually using the qemu dns server proxy).
# ip/ping and hget are useful tools to do testing.
# ssh should also work to modern servers, but public keys storage will not due to read only nature of live boot.
# (install system to disk to make it work)
# To configure loopback / localhost:
# ip/ipconfig -P loopback /dev/null 127.1
# ip/ipconfig -P loopback /dev/null ::1
# Starting tips for Unix people:
# to open a new terminal - right click on the desktop window, select New (default), then draw using right mouse click and draw a window, it will start 9term and rc (or other shell) inside
# to kill a window - right click on the desktop window, select Delete with right click, then click desired window with right click to kill it
# rc - default shell and scripting language, there is ape/psh (ksh compatible shell in APE - ANSI/Posix environment suite)
# - it is not bash, so a lot of things is different, i.e. conditionals, looping, redirects, command substitution, read docs
# 9term - default terminal emulator
# - Del to abort currently running program in terminal. (Ctrl-C will not work!)
# - you can scroll with up / down, and with Shift-PgUp / Shift-PgDown, and as explained below with scrollwheele
# - middle click on left scroll bar to scroll. or using scrollwheel if you use ps2intellimouse driver
# sam / acme - text editors. acme being more powerful. both are usable, and follow different designs.
# rio - a window manager / interface, not X11
# (if you are familiar with Unix i3 or sway, take also a look at riow in 9front)
# Ctrl-F to do tab completion in the rc in 9term. (Ins should also work, but my keyboard has no Ins to test this)
# plumber - a per-user server (you can even have multiple in separate process groups), for dispatching commands, something like dbus, but more configurable using rules and text based messages, with program autostart
# (i.e. used for opening files in editors, hyperlinks, mail links in terminal output, opening images and audio files, etc)
# (you can send messages manually to it using /mnt/plumb/send; many programs like terminal, have middle button shortcut to send what is under cursor to plumber)
# symlinks - there are no symlinks or hardlinks, you could bind/mount files tho to achive somehow similar things in some cases
# command options - compared to Unix / Gnu tools, plan 9 tools are very simple, and follow striclty Unix philosophy. Extra features are done using extra programs and combining programs using pipes.
# (so you will be surprised that a lot of Linux / GNU tools like ls, ps, cat, etc, will not have your favorite option. It is not a bug or lack of manpower to implement it, but an indended design feature!)
# PATH - there is no PATH in plan 9. Instead /bin is a merged mount of all bin directories.
# USER - there is no $USER, use $user
# HOME - there is no $HOME, use /usr/$user
# ~ - there is no ~ in rc, use /usr/$user
# cc - use 6c+6l for compiler and linker (amd64), 7c+7l (arm64), 8c+8l (i386), 5c+5l (arm) (similar to golang tools)
# (take some example simple apps, like cat, as a starting point to see what includes you need)
# (note that these compilers have different preprocessors, with some new features, and some features removed;
# if you want to use ANSI C stuff, use cpp preprocessor first).
# mk - a make variant used by most plan9 programs
# (for POSIX make, use ape/make)
# ls / lc - ls shows is like gnu ls -1, lc is like normal gnu ls (multiple columns). Also check ls -l, and lc -l.
# If you are a programer, some good starting points for man pages: open, read, rfork, errstr, proc, ns, kill.
# A major differences from Unixes, are error handling, processes, (obviously file system), signals, etc.
# In many ways Plan 9 is more UNIX than UNIX or Linux. Even APE is more POSIX conformant than Linux.
# Majority of programs are written in dialect of C, and in rc scripting language.
# For modern C / C++, it should be possible to use gcc, at least some older versions work.
# Golang is experimentally supported, but bootstrapping takes some effort.
# (you can get latest golang on Linux, and cross compile bootstrap to GOOS=plan9 GOARCH=amd64;
# or use go1.4 which had a compiler written in C, then compile natively on plan9, then
# with that compiler compiler newer golang sources, not sure if you can jump directly to go1.19, but with few jumps it can be done)
# Most programs use Tk / draw toolking, which is inspired by Tcl/Tk, but is used directly from plan9 C or rc.
# There was a Python 2.x port in the past. Might worth be reviewing and porting Python 3.x
# There is no javascript interpreter afaik, but I think there is wasm interpreter / jit available.
# It would be a great thing to bring something like this to plan9.
# Web browsing: for simple fetches of files you can use hget (remember to prefix http:// or https://).
# For mounting a single file, and start using it even while the download is progress use httpfile server.
# For more complex stuff, you can use webfs.
# For actual browsing, abaco is decent. It lacks CSS or JS support. It uses webfs as a http backend.
# abaco has a very similar interface to acme editor.
# (note abaco is crashing for me when loading main page of https://9p.io/ - the irony; some subpages should work tho)
# https://duckduckgo.com/ search engine works pretty well. google one is a bit less usable.
# I really recommend reading man pages throughly. There is a lot of amazing information on everything.
# Including internals, tips and tricks, and many more. Especially about basic programs,
# differences from Unix, and how to do mounts, 9p servers, etc.
# It might take a day or two, or few weekends, but it is really all logical and super flexible.
# `man intro` is a great start, intro(1) for general working flow. intro(2)-intro(9) for more internals of
# kernel, differences to libc, network protocols, developing 9p servers, configuration, etc.
# plan9 and 9front runs surprisingly well on real machines, including desktop and laptops.
# Older ones are better, but there are drivers to A LOT of devices (storage, network, audio,
# keyboard, usb, vga).
# Older thinkpads might be a good choice. For non-x86 something like rasberry pi 1-4,
# or MNT Reform laptop are an option too. Afaik there is no USB 3, or NVMe SSD support yet.
# For more modern systems, be sure to test graphics and networking.
# Also word of caution: A lot of people in plan 9 community might be a real wirdos.
# But I would say they are very smart, and have a lot of technical skills, so do not be
# discouraged by some of their personal opinions they express here and there.
# (If you think old school Unix guys are weird, then Plan 9 guys are the next level).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment