-- Leo's gemini proxy

-- Connecting to ibannieto.info:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini;lang=en

9front Notes

Tricks and things that I find interesting when I'm working with 9front.


Requirements

Linux + working installation of qemu

Download the plan9 ISO from the 9front site

Create a virtual hard disk image for Plan 9

Boot virtual machine from the ISO

Install Plan 9 (well, 9front which is a fork)


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

rio is the default window manager.


Mouse buttons:


Left Button: Select

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

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


Shortcuts in a term:


CTRL + " = Repeat last command

CTRL + f = autocomplete

CTRL + a = go to the start of a line

CTRL + e = go to the end of a line

CTRL + u — delete from cursor to start of line

CTRL + w — delete word before the cursor

CTRL + h — delete character before the cursor

CTRL + b — Move cursor to the position immediately after the prompt. (rio only)

SUPR = terminate task


Using rc

TO BE DONE


List files (also works with ls):


% lc -lsF

"" -> last command
echo >/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


Network stuff

All networking stuff is in /net


Main config:


% cat /net/ndb
ip=10.0.2.15 ipmask=255.255.255.0 ipgw=10.0.2.2
	sys=hyperion
	dns=10.0.2.3

Stats from the ether0 interface:


% cat /net/ether0/stats
in: 663497
link: 1
out: 518573
crc errs: 0
overflows: 0
soft overflows: 0
framing errs: 0
buffer errs: 0
output errs: 0
prom: 0
mbps: 1000
addr: 52540000ee03

Various stats and configurations:


% cat /net/arp
% cat /net/iproute

cpu+auth+fs server

How to configure a cpu+auth+fs server in 9front.


Open a term window within rio and follow this steps:


- 9fs 9fat

- cp plan9.ini plan9.ini.old

- acme plan9.ini


bootfile=9pc
bootargs=local!/dev/sdC0/fs -m 832
mouseport=ps2
monitor=vesa
vgasize=1024x768x16
nobootprompt=local!/dev/sdC0/fs -m 832 -A -a tcp!*!564
user=glenda
auth=192.168.1.3
authdom=galactica
service=cpu

- cd

- auth/wrkey


authid: glenda
authdom: galactica
secstore key: yourpass
password: yourpass

- auth/keyfs

- auth/changeuser glenda


Password: yourpass
Confirm Password: yourpass
assignnew: y
Post id: glenda
...

- auth/enable glenda

- cd /lib/ndb

- acme local


sys=somehost ether=000000 authdom=galactica auth=192.168.1.3 ip=192.168.1.1
ipnet=Home ip=192.168.1.0 ipmask=255.255.255.0 ipgw=192.168.1.1 auth=192.168.1.3 authdom=galactica fs=192.168.1.3 cpu=192.168.1.3 dns=192.168.1.3

- echo sync >> /src/hjfs.cmd

- fshalt -r


(reboot)


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.


How to use git:


% git/clone https://mygitrepositoryurl/project/project.git

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 go-plan9-amd64-bootstrap /sys/lib/go/
hget https://curl.se/ca/cacert-2021-01-19.pem >/sys/lib/tls/ca.pem

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

Staying updated

Not sure if this command works in 9front:


% replica/pull

Update 9front:


cd /
bind -ac /dist/plan9front /
git/pull -u gits://git.9front.org/plan9front/plan9front

Which is consolidated in the command:


% sysupdate

After the tree is updated, recompile/build the updated programs as needed.


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)


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 from Devine Lu Linvega:

Devine Lu Linvega on rio


Recompile apps

Do you want to patch and / or recompile something command / app in your system? Yeah, it's pretty easy: modify some source code into /sys/src/cmd/ and type mk install inside of /sys/src/cmd:


% cd /sys/src/cmd
% mk install

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


Mounting 9p filesystems in Linux

Mount a shared 9p filesystem in your host under Linux:


$ sudo mount -o rw -t 9p yourhost /mnt

There is a wee little issue mounting Plan 9 with qemu/virtio.

Check (using the dmesg command) the logs in order to troubloshooting.


More information on this matter will be here, but in short: some modules needs to be loaded before mounting a remote filesystem from a VM hosts. It's not yet cristal clear to me and I need to test more deeply.


Connecting from Windows

You must use the drawterm fork from 9front in order to connect to Plan 9 (9front only) console from Windows.


Key "Pause" to toggle full-screen


drawterm compiled for Windows


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:


9front releases

9legacy docs

9times

9front wiki

Configuring a Standalone CPU Server

plan9 wiki

UNIX to Plan 9 command translation

Using Acme

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


Back

-- Response ended

-- Page fetched on Sun May 12 06:15:10 2024