Notes on setting up vm-bhyve 04 May 2024

I'm replacing my general/util server at home and want to manage VMs on the new host with vm-bhyve. Setting it up is well documented, but running linux VMs still steers folks towards grub, which is not really great. These are just my notes (for later, after I forget) on using cloud images and uefi. This is a supplement to the docs, not a replacement!

I created a template, creatively named brian-linux.conf:

loader="uefi"
cpu=2
memory=4G
network0_type="virtio-net"
network0_switch="public"
disk0_type="nvme"
disk0_dev="sparse-zvol"
disk0_name="disk0"

I'm running on ZFS, so can use sparse-zvol for storage to make disk space only soft allocated, letting me overcommit.

Now, the commands to make things happy and run some cloud images:

# Additional dependencies for vm-bhyve
pkg install cdrkit-genisoimage    # to use cloud-init
pkg install qemu-tools            # to use cloud images
pkg install bhyve-firmware        # to use uefi

# Download some cloud images to use for our VMs
vm img https://dl-cdn.alpinelinux.org/alpine/v3.19/releases/cloud/nocloud_alpine-3.19.1-x86_64-uefi-cloudinit-r0.qcow2
vm img http://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img

vm create                               \ # C-k off comments if you copy this
    -t brian-linux                      \ # our template, from above
    -i noble-server-cloudimg-amd64.img  \ # the cloud image
    -s 50G                              \ # disk size override
    -c 4                                \ # cpu count override
    -m 32G                              \ # memory override
    -C -k ~brianm/.ssh/id_rsa.pub       \ # cloud-init ssh pubkey
    v0001                                 # vm name

Docs cover these, but reminding myself of how I configured it beyond defaults:

vm switch vlan public 4     # use vlan 4 for VMs
vm set console=tmux         # tmux for console access

Nice side effect of using cloud-init is that it logs the DHCP assigned IP address as well, so I can fire up the console and go search for it (C-b C-[ C-s Address)! Probably should write a script to extract it, to be honest.