Installing Plan 9 on Qemu

-as of Fri Sep 2 20:09:46 CES 2022-

Plan 9 installs easily under current versions of QEMU and KVM. Here are some detailed instructions. See plan9 on qemu on windows for installing on Windows with TAP networking.

INSTALLATION

First install QEMU. Optionally, you can install KQEMU also. This will give a significant speed advantage. To use KVM, replace calls to QEMU by calls to kvm.

Create a disk image, 2 gigabytes should be plenty for a testing install.

qemu-img create -f qcow2 plan9.qcow2 2G

If you are creating a VM for long-term use and not simply exploration or testing, you probably want a larger image size and to use the .raw format. Install the image. You probably want to do a simple fossil only install rather than a fossil+venti one---read the papers to discover what the difference is.

During the install, remember that the default hard drive file is at /dev/sdC0 and the cdrom is at /dev/sdD0. The distribution is located at /dev/sdD0/data in the / directory. You will be installing to /dev/sdC0/plan9 after the partition is created and you want to use the Plan 9 mbr and plan9 bootup. The install may proceed slowly depending on host OS and QEMU version and the availability of DMA for disk access. (Is this still true? Installing under KVM was not that slow for me recently. --rob)

qemu -hda plan9.qcow2 -cdrom plan9.iso -boot d

During the install you will be prompted for your monitor type. Recent QEMU versions work with the default setting of xga, using -vga std. For older versions, you may need to enter:

vesa

Once you have finished the installation you can boot this image with just:

qemu plan9.qcow2

Once booted you can list the available VESA VGA modes:

aux/vga -m vesa -p 

Before exiting QEMU, halt the Plan 9 filesystem so it can sync its disks:

echo 'fsys main sync' >>/srv/fscons
sleep 5
echo 'fsys main halt' >>/srv/fscons

(The standard fshalt script as of 2013 seems to be broken in QEMU. When fshalt changes VGA mode to text, many versions of QEMU experience bugs.)

PRE-INSTALLED QEMU IMAGES

The following images are default installs prepared under qemu-0.9.1, using a plan9.iso from January, 2011:

fossil

fossil+venti

NETWORKING

Basic networking (without requiring root access) can be enabled with:

qemu -hda plan9.qcow2 -net nic -net user

By default, the guest system (Plan 9) will be able to access the host system with IP address 10.0.2.2. See qemu(1) for more details.

If you are running a (standalone) CPU server, you need to open up some ports for the host system:

qemu -hda Plan9.qcow2.img -net nic \
    -net user,hostfwd=tcp:127.0.0.1:17567-:567,hostfwd=tcp:127.0.0.1:17010-:17010

This enables the host system to drawterm into localhost. Note that QEMU listens on port 17567 instead of 567 (auth server) because 567 is a privileged port on Unix.

HARD DRIVE FILE PERFORMANCE

For better disk performance than the -hda parameter, try specifying drives like this:

qemu -drive file=plan9.raw,media=disk,index=0,cache=writeback

Writeback caching is slightly less safe but offers considerably better performance, as tested in current Linux distros. (2013).

I would also recommend using .raw format images rather than .qcow2. The smaller size of qcows is entirely short-term; long term they grow without limit for every disk operation. .raw format is more portable and will not grow beyond the given size.

DEALING WITH PRIVILEGED PORTS

Traditional Unix reserves ports 1-1024 to root which is inconvenient. To provide access to these ports and avoid running vms as root, make use of the os-level port redirection in your host os. Here is an example for linux using iptables to redirect the most important Plan 9 specific ports, 9p port 564 and authsrv port 567:

iptables -t nat -A PREROUTING -p tcp --dport 567 -j REDIRECT --to-port 2567
iptables -t nat -A OUTPUT -o lo -p tcp --dport 567 -j REDIRECT --to-port 2567
iptables -t nat -A PREROUTING -p tcp --dport 564 -j REDIRECT --to-port 2564
iptables -t nat -A OUTPUT -o lo -p tcp --dport 564 -j REDIRECT --to-port 2564

This is combined with QEMU port redirection which takes the redirected port from the host and sends it to the normal Plan 9 port inside QEMU. An example QEMU command line for a combined cpu/file/auth server to be used after the iptables redirections above:

qemu [...] -net nic -net user,hostfwd=tcp::17007-:17007,hostfwd=tcp::17010-:17010,hostfwd=tcp::2564-:564,hostfwd=tcp::2567-:567

NETWORK TROUBLESHOOTING

Some versions of QEMU have a bug in the QEMU DNS server. If you experience DNS failures in QEMU when using DHCP, trying adding a line like

DNSSERVER=8.8.8.8  # Google public DNS

to your termrc or cpurc. When setting up QEMUs to provide cpu access or other services, it is often important to check the network environment on the host box. Commands in the host OS such as:

netstat -tnlp  # numeric listing of all programs listening on tcp ports

are helpful to verify that the QEMU is listening on the right service ports and other programs are not competing for access. Some other things to remember are the question of the IP QEMU provides to the machine (10.0.2.15) in its standard NAT mode and that dialing loopback vs numeric ips on the host and guest may interact in unexpected ways. Some users prefer to configure virtual bridges or vlan interfaces to provide VMs with independent IPs. This is highly OS and distribution specific; find a guide that works for your setup.