WLOG - notes something different

hjsf

A topic of plan9 / 9front file systems that's actually a bit scarce.

A couple of notes as a quick start or a reminder.

partition management

Creating and preparing (not to be confused with formatting) are done through the disk/fdisk and disk/prep commands.

Both commands offer an interactive mode and a parameter interface to be used in commands and scripts.

For more examples, check the /bin/inst/ folder for install scripts that use these commands to prepare a drive for installation. Most of the notes are from reading those scripts.

partitioning

To partition your drive, check for sd (storage devices) in your /dev folder.

For example, a disk in QEMU will be /dev/sd00 while an SD card on a Raspberry Pi install will be /dev/sdM0, and so on.

To partition the drive, interact with its data file.

Example of manual interactive partitioning:

disk/fdisk /dev/sd00/data

Example of automatic, non-interactive partitioning:

disk/fdisk -baw /dev/sd00/data

Automatic partitioning (flags a and w) will try to set up an optimized partition structure if there is unallocated space on the drive.

The disk/fdisk utility can call an error if it does not find a preexisting partition table. Either MBR or GPT. In that case an empty partition table has to be created first with disk/mbr or disk/edisk utilities.

mbr partition table

disk/mbr -m /386/mbr /dev/sd00/data

gpt partition table

disk/edisk -bw /dev/sd00/data

preparing

Partitioning itself does nothing without a file system structure. We need to prepare the newly created partition as hjfs. To prepare a partition, interact with the plan9 file.

Example of automatic, no-ninteractive file system preparation:

disk/prep -wa fs /dev/sd00/plan9

reaming

The file system as such does not have a format command but can be set with the ream option when the file system is started, which will clear the partition.

IMPORTANT: Start the file system with the -r (ream) option only when you want to clear the partition.

Example of starting the hjfs with ream option:

hjfs -n hjfs.newfs -m 64 -Srf /dev/sd00/fs

using hjfs

Everything being a file in plan9 / 9front one does not simply mount a file system and use it, but rather the file system service has to be started, from where the file system can be mounted into your namespace.

starting

Use the hjfs command to start the file system service on a particular partition. To serve the file system use the fs file.

Example of starting hjfs:

hjfs -n hjfs.newfs -m 64 -Sf /dev/sd00/fs

mounting

To use the file system in your namespace mount it from the /srv/ directory. To mount the file system use the hjfs file.

Example of mounting the hjfs file system from a service named hjfs.newfs:

mount -c /srv/hjfs.newfs /n/newfs

using

Once mounted somewhere, perform file system operations as usual.

unmounting

When done with the file system, unmount it. If it's not a system partition (which will stop with the system), it is recommended to sync the file system first.

Example of sending a sync command to hjfs file system service:

echo sync >> /srv/hjfs.newfs.cmd

Example of unmounting the hjfs file system:

unmount /n/newfs

stopping

Before unplugging storage devices or shutting down the system, stop the hjfs file system service.

Example of sending a halt command to hjfs file system service:

echo halt >> /srv/hjfs.newfs.cmd

administering hjfs

Since the file system is provided as a service, that service can be controlled. That is done through the hjfs.cmd file. As always, refer to the man page for more details and examples.

sync

To instruct the service to sync data to media, use the sync command.

Example of sending a sync command to hjfs file system service:

echo sync >> /srv/hjfs.cmd

file system usage

To receive information on file system usage, use the df command.

Example of sending a df command to hjfs file system service:

echo sync >> /srv/hjfs.cmd

This will print out information to the kprint (kernel print) device or current console (if the file system is not the system file system).

The printout to the kprint device can be displayed directly on the screen buffer (overwriting other screen elements). To avoid that, the kprint device can be read with the cat command. Reading the kprint device blocks it for other processes.

Example of reading / redirecting kprint device:

cat /dev/kprint

resising partitions

There is no simple / quick solution.

A common issue if using premade images, such as images for the Raspberry Pi, since booting an external media with the installer is a no-go. I also did not want to mess around with PXE boot and another file server.

So tested here is a method of copying data to another hjfs partition, deleting and recreating a bigger partition on the SD card, and copying data back. The intermediate device was a QEMU 9front install.

Individual commands can be sourced from the text above.

Order of operations with comments:

  1. create an additional qemu image to serve as a transfer storage

    qemu image creation:

    qemu-img create -f qcow2 9front_extra.qcow2 8G
    

    qemu image mounting parameter for qemu:

    -drive if=none,id=vd1,file=/tmp/9front_extra.qcow2
    
  2. create disk image of Raspberry Pi SD card:

    Use dd or other preferred utility.

    SD card image mounting parameter for qemu:

    -drive if=none,id=vd2,file=/tmp/RpiOne_resized.img -device scsi-hd,drive=vd2
    
  3. boot qemu

    This assumes you have a working 9front QEMU installation.

    boot:

    qemu-system-x86_64 -cpu host -enable-kvm -m 4096 \
    -net nic,model=virtio,macaddr=63:43:00:00:AA:02 \
    -net user -device virtio-scsi-pci,id=scsi \
    -drive if=none,id=vd0,file=/tmp/9front_terminal.qcow2 -device scsi-hd,drive=vd0 \
    -drive if=none,id=vd1,file=/tmp/9front_extra.qcow2 -device scsi-hd,drive=vd1 \
    -drive if=none,id=vd2,file=/tmp/RpiOne_resized.img -device scsi-hd,drive=vd2
    

    Check that /dev/sd00 (system partition), /dev/sd01 (extra storage) and /dev/sd02 (Rpi SD card image) are present

  4. create, format (start) and mount extra hjfs partition

    create:

    disk/mbr -m /386/mbr /dev/sd01/data
    disk/fdisk -baw /dev/sd01/data
    disk/prep -wa fs /dev/sd01/plan9
    

    start and format (r parameter is important):

    hjfs -n hjfs.extrafs -m 64 -Srf /dev/sd01/fs
    

    IMPORTANT: if you have any additional users, create them on the new hjfs file system, or ownership will not transfer. In my case, I have a user named "web":

    echo newuser web >> /srv/hjfs/extrafs.cmd
    

    mount:

    mount -c /srv/hjfs.extrafs /n/extrafs
    
  5. start and mount Rpi SD card image

    start (NO formatting - note the missing r option):

    hjfs -n hjfs.pifs -m 64 -Sf /dev/sd02/fs
    

    mount:

    mount -c /srv/hjfs.pifs /n/pifs
    
  6. copy data from the SD card partition to extra storage

    copy:

    dircp /n/pifs /n/extrafs
    
  7. make sure files are transfer over

    You can check if the transferred file size matches with the command du.

    list disk usage:

    du -h /n/extrafs
    du -h /n/pifs
    
  8. unmount and stop SD card image

    Make sure you're not in the /n/pifs directory.

    unmount SD card image:

    unmount /n/pifs
    

    stop SD card hjfs file system service:

    echo halt >> /srv/hjfs.pifs.cmd
    

    This should remove the /srv/hjfs.pifs and /srv/hjfs.pifs.cmd files.

    if not, remove them:

    rm -f /srv/hjfs.pifs /srv/hjfs.pifs.cmd
    
  9. change SD card partition (delete, create, prepare, start/fromat)

    Change the partition size by deleting it and creating a new, bigger partition.

    open SD card image to edit partitions:

    disk/fdisk /dev/sd02/data
    

    Use and navigate disk/fdisk for that. Type "h" for the help menu, "p" to print the partition table (note the name), "d" and name to delete the old partition, "a" and name with parameters to create a new partition, "w" to write, and "q" to quit fdisk.

    prepare newly created partition:

    disk/prep -wa fs /dev/sd02/plan9
    

    start and format (r parameter is important):

    hjfs -n hjfs.pifs -m 64 -Srf /dev/sd02/fs
    

    IMPORTANT: if you have any additional users, create them on the new hjfs file system, or ownership will not transfer. In my case, I have a user named "web":

    echo newuser web >> /srv/hjfs/pifs.cmd
    

    mount:

    mount -c /srv/hjfs.pifs /n/pifs
    
  10. copy data from extra storage back to the resized SD card partition

    copy:

    dircp /n/extrafs /n/pifs
    
  11. make sure files are transfer over

    You can check if the transferred file size matches with the command du.

    list disk usage:

    du -h /n/extrafs
    du -h /n/pifs
    
  12. sync changes to the SD card partition before unmounting

    sync:

    echo sync >> /srv/hjfs.pifs.cmd
    
  13. unmount and stop file systems

    unmount:

    unmount /n/pifs
    unmount /n/extrafs
    

    stop:

    echo halt >> /srv/hjfs.pifs.cmd
    echo halt >> /srv/hjfs.extrafs.cmd
    
  14. power off qemu machine

    Just to de-associate any mounted images.

    poweroff:

    fshalt
    
  15. write modified SD card image back to the SD card

    Again, use dd or a preferred utility.