P9 - hpaluch/hpaluch.github.io GitHub Wiki

Plan 9

"Plan 9" is unique system (from UNIX creators). However it may be hard to grasp first.

Main characteristics:

  • everything is file (including env, sockets)
  • because everything is file there are possible many neat tricks:
    • irc or http client and http server is written in shell (!)
    • even terminal windows uses files for operations, for example /dev/text is completed buffer of your terminal window so you can for example grep it
    • /dev/snarf is clipboard - you can read it or modify it
    • similarly works mouse and keyboard
  • fully UTF-8 compatible (Plan9 authors invented UTF-8)
  • transparently distributed system - remote resources (CPU, files, ...) can be just mounted on local machine and accessed as local files
  • full namespace support - each process has its own view of filesystem

NOTE: There are several distributions of Plan9 - I tested 9front flavour.

Quick install:

WARNING! Refrain from using Delete key - it is used as "Terminate" in Plan 9 (similar to Ctrl-C on UNIX). If systems seems to not responding, try to type some character in terminal and then remove it with Backspace - usually it helps.

Really brief installation guide:

  • using KVM, selected Alma 9 as OS, 2 CPUs, 2GB of RAM, 20GB of disk, using VirtioBLK disk, SATA CD-ROM, virtio-net network card
  • NOTE: BIOS+MBR scheme recommended (UEFI+GPT is quite new on Plan9 - use on your own risk)
  • you have to select boot device - default is fine
  • select display resolution - in my case I changed 1024x768x16 to 1440x900x16
  • graphics type: I selected vesa
  • confirmed PS/2 mouse
  • after a while rio GUI should start
  • now you have to enter inst/start to start real installation
  • press ENTER to confirm configfs stage
  • confirm default cwfs64x
  • confirm partdisk with defaults
  • on disk selection there are:
    • sdE0 installation SATA DVD ROM
    • sdF0 target 20GB VirtioBLK disk
  • enter sdF0 as target disk name
  • use mbr as partition scheme
  • you will be asked to create Plan 9 partition - type as suggested w ENTER and q ENTER
  • press ENTER to confirm prepdisk stage
  • accept default of using prepared Plan 9 partition (/dev/sdF0/plan9 in my case)
  • again you can use w ENTER and q ENTER to confirm suggested partitioning
    • NOTE: it is nested partitioning similar to BSD disklabel (where BSD has single primary partition on MBR and inside of that single partition are subpartitions for specific system)
  • press ENTER to confirm mountfs stage
  • confirm fscache selection with ENTER, then fsworm with ENTER and finally other with ENTER
  • confirm yes on Ream (= Format filesystem)
  • next press ENTER for confignet stage
  • press ENTER for automatic (DHCP) configuration
    • ignore no router advs after 3 sols on /net/ether0 error - that's expected when you have no IPv6 router on network.
  • press ENTER to confirm mountdist stage
  • type /dev/sdE0/data as Distribution disk and ENTER
  • press ENTER to confirm Location of archives = /
  • press ENTER for stage copydist
  • press ENTER for stage ndbsetup (basically /etc/hosts and DNS)
  • sysname - press ENTER to accept cirno default
  • press ENTER for stage tzsetup
  • I use CET (Central European Time) for EU
  • finally press ENTER for bootsetup stage
  • press ENTER to confirm 9fat partition
  • type yes ENTER to write master boot record
  • type yes ENTER to confirm Active flag on boot partition (required by some BIOS vendors to boot at all)
  • finally press ENTER for finish installation

System should automatically reboot. On reboot just:

  • confirm default bootargs (ending with fscache)
  • confirm user glenda
  • you can see sdE0 i/o errors - that's OK, because LibVirt automatically removes ISO on reboot

How to view boot messages with ease:

  • cat them to text file using:
    mkdir logs
    cd logs
    cat /dev/kmesg > kmesg.txt
    acme kmesg.txt
    
  • to exit Acme editor do middle-button press on Exit menu.
  • to run Acme again:
    • left-click and hold and select existing acme kmesg.txt command
    • middle-click and hold - move mouse to send - release middle-button to execute ("send")

Remember:

  • to move Window - move mouse to bold frame (cursor will change)
    • press and hold right-button (frame color will change to red)
    • move mouse while still holding middle button will move window
  • to resize Window - move mouse to bold frame and use left-click hold and move.

Installed system under Proxmox (disk: VirtIO BLK, network: VirtIO NET).

  • Do NOT use lvm-thin - copying will take forever. I suspect that there is significant write amplification
  • I use qcow2 on ext4 (because I will need snapshots, otherwise I would use raw), cache: unsafe
  • 1 CPU, 2 GB RAM

There is really good installation guide - and mostly you just press enter when asked for something:

Both installation (and after installation) runs GUI called rio(1) very good intro is at:

How to create New Terminal window:

  • Right click and Hold on empty background
  • move mouse to New menu item and release Right button
  • when Cross (+) appears again Right-click (important) and hold - draw new Window
  • move mouse to draw rectangle of new window. When done - release button and Terminal will start in that rectangle area.

You can use man ITEM for most commands...

System info - run sysinfo script. Most commands are in /rc/bin (try ls /rc/bin).

How to shutdown:

fshalt

Basic terminal tips

Terminal window is called rio(1) and it works like full screen editor.

I strongly recommended watching at least these YouTube Videos for introduction:

NOTE: Autoscroll is disabled by default. You have two choices:

  1. press ENTER to show next page
  2. click-and-hold Middle button and select scroll and release Middle button - this will enable auto-scroll

Selecting text - again 2 choices: a) double-click on text to select word or text inside quotes b) left-click and hold left button - move mouse to select text - but see below for details.

Copy/Cut & Paste using "chords":

  1. left-click and hold left button - select text - still hold left-button
  2. now also press middle button (keep holding left-button) - it will Cut text 2.b) if you want to Copy instead of cut - still hold left and middle button. Additionally press Right button - text will be pasted back - same effect as Copy.
  3. release all buttons (I'm rather releasing from Right to Left)
  4. position mouse to place where you want paste text
  5. left-click, hold and right-click - text will be pasted
  6. release all buttons

Copy/Cut & Paste using menu:

  1. select text with any method - release left-button when selection is done
  2. Middle click and hold to show menu. Select Snarf (Copy) or Cut and release mouse button
  3. Position your mouse to place where you want paste text
  4. Middle click and hold to show menu. Select Paste and release mouse button.

Other menu items:

  • plumbing -> will open selected file in application (typicaly in page viewer)
  • send -> will run command in clipboard

Random tips

  • Use Del key instead of Ctrl-C to stop program
  • To find assigned IP address: cat /net/ndb or netstat -i
  • To see routing tables cat /net/iproute
  • most scripts are under /rc/bin
  • default shell (equivalent of /bin/sh under Unix) is named rc - try man rc

Generating graphical manual pages (from Video tutorial):

  • example: man -t rio | page -w

Building docs

Try:

cd /sys/doc
mk

Should generate lot of *.ps files in /sys/doc

WARNING! OpenSUSE Viewer (gv) is somehow broken (strange rendering of fonts). However you may use ps2df file.ps (included with ghostscript package) and then evince file.pdf.

Serving filesystem from Plan9 server to Linux client

After lot of digging found working example on: https://mitjafelicijan.com/mount-plan9-over-network.html

On Plan9 I run:

ip/ipconfig # enables network
aux/listen1 -tv tcp!*!9999 /bin/exportfs -r /sys/src

On Linux client:

mount -r -t 9p -o version=9p2000,port=9999,trans=tcp IP_ADDRESS_OF_PLAN9_SERVER /mnt/9p
# should see contents of /sys/src
ls -l /mnt/9p

Connecting remotely

Default plan installation is so called "standalone terminal" - single user. Although it is possible to run "manually" some services as single user it is not standard way.

There are at least 2 guides:

Or:

Trying:

  • http://wiki.9front.org/cpu-setup
  • verify that we are now in terminal (single user + GUI) mode:
    echo $service
    
    terminal
    
  • note also sysname:
    echo $sysname
    
    Server1
    
  • create new hostowner user kvik:
    con -C /srv/cwfs.cmd
    newuser kvik
    newuser sys +kvik
    newuser adm +kvik
    newuser upas +kvik
    
  • to exit con you have to:
    • press Ctrl-\ (documented)
    • press ENTER to get >>> prompt (undocumented!)
    • press q followed by ENTER to quit
  • now reboot with fshalt -r
  • on boot remember to enter new hostowner name kvik (instead of glenda)
  • there will be error message regarding ./lib/profile we have to fix it with:
    /sys/lib/newuser
    
  • it will boot empty rio
  • to create terminal - click and hold right-button, select New, release button
  • and draw window.
  • verify that ./lib/profile now exists with:
    ls -l $home/lib/profile
    
  • again reboot with fshalt -r
  • again enter username kvik
  • now empty rio should start without errors.

TODO: verify

To study:

On your client you have to build drawterm

TODO:

Probably this guide is most close: http://wiki.9front.org/cpu-setup

Problems:

  • there was nothing listening on port 5356 (secstore) I tried to run on plan9:
    auth/secstored
    
  • I then run on client (Linux) machine:
    drawterm -a IP_OF_PLAN9 -c IP_OF_PLAN9 -u genda -d -d -d
    
  • but on terminal there was error:
    cpu: negotiating authentication method: IP_OF_PLAN9:
    
    goodbye
    
  • on plan9 server terminal there was error:
    incoming call for tcp!*!ncpu from CLIENT_IP in /net/tcp/4
    aux/listen1: exec directory entry not found: /bin/cpu
    

It seems that I have to edit /n/9fat/plan9.ini and add service=cpu there... Following FAQ I have to mount with 9fs script - in case of VirtIO SCSI under Proxmox:

WARNING! Do not do that below - it will cause boot failure!!!

9fs 9fat /dev/sd00/9fat
# Do NOT use quotes "" - it will cause error
echo 'service=cpu' >> /n/9fat/plan9.ini
cat /n/9fat/plan9.ini

Resources

Interesting stories: