💾 Archived View for ibannieto.info › projects › tech › plan9.gmi captured on 2022-07-16 at 13:34:02. Gemini links have been rewritten to link to archived content

View Raw

More Information

-=-=-=-=-=-=-

 _  _                    _       _            _       __
(_)| |__  __ _ _ _  _ _ (_) ___ | |_  ___    (_)_ _  / _| ___
| || '_ \/ _` | ' \| ' \| |/ -_)|  _|/ _ \ _ | | ' \|  _|/ _ \
|_||_.__/\__,_|_||_|_||_|_|\___| \__|\___/(_)|_|_||_|_|  \___/

Home

Projects

Plan9 Notes

For many years I wanted to try Plan 9, a pioneering operating system that was supposed to be a compendium of ideas to shape a new OS and a evolution from UNIX. This operating system is also classified as "dark" operating system on this times and to me, for that reason, I think it is worth to taking a look.

After several days using Plan 9, I just can say that I still don't understand a ton of things and that the traditional (UNIX) concepts differ a lot from the Plan 9 concepts.

I still have a lot to learn, so in this project I will write some notes, tricks and things that I find when I work with Plan 9.

Screenshot of my Plan 9 term

Glenda, the main logo

CatClock the famous clock

Preflight checks and requirements

9front home

Using QEMU under Linux

Install qemu through your favorite package manager. Note that qemu configuration may differ from your system. In my case, I'm using Arch Linux, so it's a good idea to follow your favorite distribution's documentation.

QEMU Arch Wiki

Download the ISO

Download the ISO:

9front global mirror

9front iso amd64

9front iso pi3/pi4

QEMU Preparation

Run QEMU with the following commands:

qemu-img create -f qcow2 9front 8G
qemu-system-x86_64 -hda $image_name -cdrom plan9.iso -boot d -vga std -m 768

The command qemu-img prepares and creates a local QEMU image with 8G of size.

The command qemu-system-XXX launchs a virtual machine with the new image and boots from the ISO

Follow the steps in the installation guide:

Installation Guide

Installation time is more or less 5-10 min in my machine.

Boot QEMU without the installation media with the following command:

qemu-system-x86_64 -hda 9front.qcow2.img -boot d -vga std -m 768

Enhanced QEMU configuration

Boot from virtual CDROM/ISO:

qemu-system-x86_64 -cpu host -smp $(nproc) -enable-kvm -m 2048 \
-net nic,model=virtio,macaddr=52:54:00:00:EE:03 -net user \
-device virtio-scsi-pci,id=scsi \
-drive if=none,id=vd0,file=9front.qcow2.img \
-device scsi-hd,drive=vd0 \
-drive if=none,id=vd1,file=9front.iso \
-device scsi-cd,drive=vd1,bootindex=0 \
-vga std \
-k es

Boot from virtual HDD:

qemu-system-x86_64 -cpu host -smp $(nproc) -enable-kvm -m 4096 \
-net nic,model=virtio,macaddr=52:54:00:00:EE:03 -net user\
,hostfwd=tcp::5640-:564\
,hostfwd=tcp::17019-:17019\
,hostfwd=tcp::5670-:567\
,hostfwd=tcp::17020-:17020 \
-device virtio-scsi-pci,id=scsi \
-drive if=none,id=vd0,file=9front.qcow2.img \
-device scsi-hd,drive=vd0 \
-vga std \
-k es

Maybe outdated but still useful info:

Installing plan 9 on qemu

NOTE: ports 5640 and 17019 needed for a drawterm connection.

Using a Raspberry Pi

Thanks to Richard Miller for the port to the Raspberry Pi.

Write the ISO to the SD card:

sudo dd bs=4M if=plan9.iso of=/dev/sdb conv=fsync oflag=direct status=progress

Then eject the device and plug the SD Card to the card slot of your Raspberry Pi.

NOTE: I found that you can use raspbi3 with 2Gb of RAM and raspi4 with 4Gb and it's more than enough use it with 2-4 Gb of RAM for a server.

First steps

Once the plan9 is booted you may need to change the keyboard layout and the monitor resolution.

Changing the resolution

Obtain a list of vesa bios modes:

% @{rfork n; aux/realemu; aux/vga -p}

Change the resolution (configure one of the valid modes):

% @{rfork n; aux/realemu; aux/vga -m vesa -l 1920x1080x16}

Changing the keyboard

% cat /sys/lib/kbmap/es > /dev/kbmap

More info

Saving the configuration

You have to get in to the boot stuff in the 9fat partition:

% 9fs 9fat

% cd /n/9fat

% acme plan9.ini

Using rio

TO BE DONE

Left Button: Select

Middle Button: Menu (cus/paste/snarf/plumb/look/send/noscroll)

Right Button: Window Menu (new/resize/move/delete/hide)

In a term:

Using rc

TO BE DONE

List files (also works with ls):

% lc -lsF
"" -> last command
cat >/dev/text -> clear the console

In this link you can get a very useful list with unix to plan9 command translation:

UNIX to Plan 9 command translation

Staying updated

replica/pull

Install git

cd /tmp
hget https://orib.dev/git/git9/HEAD/snap.tar.gz | tar xvz
cd git9
mk all
mk install

Note that 9front comes with git preinstalled.

Install golang

mkdir -p /sys/lib/go/
ramfs
cd /tmp
hget http://9legacy.org/download/go/go1.18.3-plan9-amd64-bootstrap.tbz | bunzip2 -c | tar x
dircp go1.18.3-plan9-amd64-bootstrap /sys/lib/go/

9legacy downloads

Install castor9

castor9 is a plan 9 gemini client.

ramfs
cd /tmp
git/clone https://git.sr.ht/~julienxx/castor9
cd castor9
mk install

castor9

Install netsurf

netsurf is a www browser.

% git/clone git://github.com/netsurf-plan9/nsport
% cd nsport
% fetch clone http

To build go to the directory nsport and run mk:

% cd nsport
% mk
% mk install

To update your copy of the sources:

% cd nsport
% fetch pull

netsurf-plan9

Installing contrib

mkdir -p /dist/replica/client
9fs sources
/n/sources/contrib/fgb/root/rc/bin/contrib/install -f fgb/contrib

Building 64-bit userland and the kernel

cd /
rc sys/lib/rootstub
cd /sys/src
mk nuke
mk libs                     #(makes and installs this arch's libs)
objtype=amd64 mk all
objtype=amd64 mk install
cd 9/pc64
mk install
9fs 9fat
cp /amd64/9pc64 /n/9fat

Building the system from source

Developing in C

Creating a simple hello world:

% touch hello.c && acme hello.c
#include <u.h>
#include <libc.h>

void main(void)
{
  print("Hello World from Plan 9!\n");
  exits(0);
}

Create a mkfile:

% touch mkfile && acme mkfile
</$objtype/mkfile

BIN=/$objtype/bin
TARG=hello

OFILES=\
	hello.$O\

HFILES=\

</sys/src/cmd/mkone

Run mk and execute the program:

% mk
6c -FTVw hello.c
6l  -o 6.out hello.6

% 6.out

C programming in Plan 9

How to create a mkfile

Plan 9 programming in C (great resource)

Connecting from Linux

You must use the drawterm fork from 9front in order to connect to Plan 9 (9front only) console from your favorite OS:

drawterm/drawterm -h 'tcp!127.0.0.1!17019' -u glenda -a 'tcp!127.0.0.1!5640'

Also text-mode only:

drawterm/drawterm -G -h 'tcp!127.0.0.1!17019' -u glenda -a 'tcp!127.0.0.1!5640'

drawterm 9front fork

NOTE that if you are using another Plan 9 distro you must use another version of drawterm, which is different that the 9front (authentication mechanism p9sk1 is changed/improved in 9front, 9legacy uses original auth AFAIK)

More info

Sharing files with Linux

9fs protocol permits to have your local filesystem avaiable to access on your drawterm session. Your Linux files can be accessed from your drawterm session, in an isolated manner, so that the files are only visible on said drawterm session not for another session, not for another user.

Edit the file $home/lib/profile , right before starting webfs, add the following:

bind -a /mnt/term/home /usr >[2]/dev/null

This will bind all files in /mnt/term/home/ to /usr. So all files in /usr (e.g. your 9front home folder /usr/glenda) will be kept, plus all files in /mnt/term/home/ will also be seen under /usr.

So for example, if your user folder on Linux is at /home/iban, it will now be available on 9front (through a drawterm session only) at /usr/iban.

Source

Patch rio for wallpaper support

To add wallpaper support to rio, you want to edit the rio file /sys/src/cmd/rio/data.c, within the iconinit function, you can draw a graphic to the background image by adding the following code. In this example, the graphic is stored at the location defined with open():

int fd;
Image *bimg = nil;
fd = open("/usr/glenda/lib/wallpaper", OREAD);
if(fd >= 0){
	bimg = readimage(display, fd, 0);
	close(fd);
}
if(bimg){
	background = allocimage(display, Rect(0, 0, Dx(bimg->r), Dy(bimg->r)), RGB24, 1, 0x000000FF);
	draw(background, background->r, bimg, 0, bimg->r.min);
}
else
	fprint(2, "iconinit: %r\n");

The file format should be in Plan 9's native raw file format, to convert any jpg into this format, use:

jpg -9t wallpaper.jpg > /usr/glenda/lib/wallpaper

NOTE this information is NOT MINE, is ORIGINAL from Devine Lu Linvega, MANY THANKS to this user.

Devine Lu Linvega on rio

Serve content with rc-httpd

Modify the file in /rc/bin/rc-httpd/select-handler and change "example.com" with your domain.

#!/bin/rc
PATH_INFO=$location
switch($SERVER_NAME) {
case example.com
     FS_ROOT=/sys/www/$SERVER_NAME
     exec static-or-index
case *
     error 503
}

Logs are in /sys/log/www :

% tail /sys/log/www

Setting up rc-httpd

Capturing the screen

% cat /dev/window | topng > window.png # Capture the current window
% cat /dev/screen | topng > screen.png # Capture entire screen

Setup faces

TO BE DONE

jpg -c avatar.jpg |  resample -x 100  |  crop -b 255 255 255 -i -30 |  mug > myface.1
jpg -c avatar.jpg  | iconv -c m8 | resample -x 48 -y 48 > myface.1

Adding your face

The face nation

Setup email

TO BE DONE

Mail configuration

Configuring Gmail (thanks Lucas S. Vieira)

Links

Sources of information for plan9 and 9front:

9front releases

9legacy docs

9times

9front wiki

Configuring a Standalone CPU Server

plan9 wiki

Tip of the day

UNIX to Plan 9 command translation

Using Acme

List of Web browsers

The Plan 9 Namespace for Dummies

plan9 on qemu

Acme Repo

Setting up 9front on a Raspberry Pi

seh.dev

Devine Lu Linvega on Plan 9 (awesome site)

various tools from a 9front developer

Last Updated

Last Updated: 10/JUL/2022

Back