> emu Zones
The emu brand allows you to run virtual machines under qemu, similar to the implementation for bhyve.
This is an experimental feature, introduced in Tribblix m38.
To run zones using the emu brand, first ensure that the qemu overlay is installed
zap install-overlay qemu
To boot a guest, the command would be something like:
zap create-zone -t emu -z emu1 \
-x 192.168.0.236 \
-I /var/tmp/tribblix-0m38.iso \
-M x86_64:max \
-V 8G
Here, the -t flag tells us that this is an emu zone, the
-z flag gives the name of the zone, the -x
flag specifies the zone's permitted IP address, the -I flag
tells qemu where to find the ISO image to boot from, and the -V
flag says to create an 8G virtual disk for the guest to use.
The key difference with emu zones is that you need to specify the cpu
details with the -M flag. Currently this takes 2 fields separated
by a colon; the first field maps directly to the qemu binary to use (ie.
qemu-system-x86_64), the second field is the cpu model. You can get the list
of available cpu models by running qemu with the -cpu help flags.
You can set the number of vcpus for the guest with the -c
flag (the default is a single cpu). Likewise, the guest memory can be set
with the -m flag (the default is 1G of memory). As an example,
add -c 2 -m 2G.
That will create and boot the zone. To interact with it, use VNC. As
root, start up socat like so:
socat TCP-LISTEN:5905,reuseaddr,fork UNIX-CONNECT:/export/zones/emu1/root/tmp/vm.vnc
Note the name of the path to the zone, which you'll need to change depending on the name of the zone. Also, you can choose a different port, just remember that it must be unique, and the VNC display number is offset by 5900.
Then, as yourself, you can connect with
vncviewer :5
and you should see, and be able to interact with, the system as it boots.
There's a slightly more convenient way to view the graphical console
without the manual mucking about with socat and vncviewer described above.
If you share your user account with the zone using the -U
flag (which in the case of emu zones means sharing with the zone and not
with the OS running as the guest):
zap create-zone -t emu -z emu1 -U ptribble ...
then the startvnc command can be used to connect to the VNC console as that user, like so:
startvnc -Z emu1
You can run the installer as normal. But before you can use the installed system you need to remove the virtual CD and reboot.
zap remove-cd -z emu1 -r
Cloud-init
Often, you'll want the guest to automatically configure itself.
You can use cloud-init for this.
Adding the -C flag to the create-zone
invocation will enable cloud-init. On its own, this doesn't
do a great deal, but should set up the IP address and dns resolution
correctly.
Using the -k flag with the name of an SSH public key file
will enable cloud-init and configure the guest to allow SSH
access to the default account (or root) using the given SSH key. For example,
you might use:
zap create-zone -t emu -z emu2 \
-x 192.168.0.237 \
-I /var/tmp/ubuntu-22.04.1-live-server-amd64.iso \
-k /export/home/ptribble/.ssh/id_rsa.pub \
-V 8G