shithub: wiki.9front.org

ref: 89e95268e95255fe126bd29fbf9bc3f658fefeb4
dir: /freebsd-bhyve.md/

View raw version
Running 9front using bhyve(8) on FreeBSD
========================================

Required ports:

	sysutils/bhyve-firmware
	sysutils/uefi-edk2-bhyve
	sysutils/uefi-edk2-bhyve-csm
	net/tigervnc-viewer

Add the following lines to `/etc/rc.conf`. Replace `re0` with your own
network interface. It's good practice to assign each VM a unique `tap`
interface in case you need to run multiple VMs at the same time. For
simplicity's sake, this setup uses only one `tap`:

	if_bridge_load="YES"
	if_tap_load="YES"
	cloned_interfaces="bridge0 tap0"
	ifconfig_bridge0="DHCP addm re0 addm tap0"
	ifconfig_bridge0_alias0="inet 10.0.0.1/24"

Reboot your machine and then grab a [9front ISO](https://9front.org/releases/).

Make a directory where you'll store everything 9front-related.
I usually keep all my
[bhyve(8)](https://www.freebsd.org/cgi/man.cgi?query=bhyve&sektion=8)
VMs under a
[ZFS dataset](https://docs.freebsd.org/en/books/handbook/zfs/):

	$ cd /path/to/vms/
	$ mkdir 9front
	$ mv /path/to/9front_iso 9front.iso

Create an empty file to be used as the VM's hard drive. 10G
will be more than enough:

	$ truncate -s 10G disk.img

Make a startup script. Feel free to tweak the variable values to match your
own setup. Obviously, when you're done installing 9front from the ISO, you'll
be running the script without the `-s 3,...` line:

	$ cat 9front_start

	#!/bin/sh

	name="9front"
	cpu="2"
	mem="2G"
	iso="9front.iso"
	disk="disk.img"
	tap="tap0"

	ifconfig ${tap} up

	bhyve -c ${cpu} -m ${mem} -wH \
		-s 0,hostbridge \
		-s 3,ahci-cd,${iso} \
		-s 4,ahci-hd,${disk} \
		-s 5,virtio-net,${tap} \
		-s 29,fbuf,tcp=0.0.0.0:5900,w=800,h=600,wait \
		-s 30,xhci,tablet \
		-s 31,lpc \
		-l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI.fd \
		${name}

Make a shutdown script in order for bhyve(8) to close properly:

	$ cat 9front_stop

	#!/bin/sh

	name="9front"
	tap="tap0"

	ifconfig ${tap} down
	bhyvectl --force-poweroff --vm=${name}
	bhyvectl --destroy --vm=${name}


Make the scripts executable and start the VM:

	$ chmod +x 9front_start 9front_stop
	# ./9front_start; ./9front_stop


Run vncviewer(1) to connect to the VNC display:

	$ vncviewer 0.0.0.0

When prompted for the monitor type during boot, choose `xga`.

## Notes

- IPv6 does not seem to work with 9front guests.
- Some machines present overclocking problems when the host uses
`TSC-low` as a time source (see
[timecounters(4)](https://man.freebsd.org/cgi/man.cgi?query=timecounters&section=4)).
Changing it to `HPET` usually solves the problem.