Xen OpenBSD HVM Guest

In this article, I want to describe how to run OpenBSD as an Xen HVM Guest. OpenBSD does not support the Xen PV or PVH Mode so it can only be run in HVM or PVHVM to be correct because OpenBSD supports Paravirtualized Drivers for Network and Storage.

The first thing to do is to download the iso.

wget https://cdn.openbsd.org/pub/OpenBSD/7.6/amd64/install76.iso

The next step is to create a Disk for our VM. I use LVM for that so I create an LVM Volume. In the example below I only create a Volume with 10G. If you need more, then change the value. It is also possible to use Disk Images. If you want that, just look online there are plenty of articles explaining how that works.

sudo lvcreate -n openbsd -L 10g ubuntu-vg

Finally, we can create the config for the VM. Here is, I think, a pretty self-explaining example but I will explain some things. As I said we need to use the HVM type, set a name, the amount of memory, and the number of cores we want. Then we set the path to our Disk and iso. We specify our bridge interface and I use static Mac addresses for fixed dhcp ips. It would be possible to change the OpenBSD iso to install it over a serial console, but that is more work so I install over vnc and choose the use serial as default in the installer. Later I then removed the vnc. I set a vnc keymap because I use a German Keyboard. An English keyboard is the standard, so if you have one you can remove that option, if you have a different one, search for "Keymaps” in the xl.cfg man page which keymaps are supported. The last thing in the config is to add a serial console that we can use. If you want to know what else can be configured, check the xl.cfg man page.

# /etc/xen/openbsd.cfg
type = "hvm"
name = "openbsd"
memory = 2048
vcpus = 2

disk = [
        'phy:/dev/ubuntu-vg/openbsd,ioemu:hda,w',
        'file:/path/to/install76.iso,hdc:cdrom,r'
        ]

vif = ['bridge=xenbr0,mac=00:16:3e:00:00:02']

vnc = 1
vncpasswd = ""
vnclisten = "0.0.0.0"
keymap = "de"

serial = "pty"

After adding our config, we can start the VM and do the installation. Connect with a VNC Client of your choice, is normally use the VNC Viewer from RealVNC on my Mac or iPad. VNC uses the Port 5900 but Xen will search for a free Port if it is already in use. If you have only one VM running it is that port, if you have multiple it is always + 1 per running VM. To connect you only need the IP from your Xen Host plus the Port if it is not the Default one. As I wrote above, I changed the default Console to the Serial Console because I do not need a UI for most of my VMs.

sudo xl create -f /etc/xen/openbsd.cfg

After the OpenBSD installer is done, it asks if you want to reboot or shutdown the VM. Run the Command below because if you choose shutdown it will get stuck.

sudo xl shutdown openbsd

As I wrote above, I only need a Serial Console for the VM. So after installing it, I change the Config to the one below. I commented out the iso and deactivated vnc and the gpu.

type = "hvm"
name = "openbsd"
memory = 2048
vcpus = 2

disk = [
        'phy:/dev/ubuntu-vg/openbsd,ioemu:hda,w',
        # 'file:/VMs/install76.iso,hdc:cdrom,r'
        ]

vif = ['bridge=xenbr0,mac=00:16:3e:00:00:02']

vnc = 0
vga = "none"
serial = "pty"

Now I can start the VM with -c which directly connects to the serial console where I then see the startup of OpenBSD and can log in.

sudo xl create -f /etc/xen/openbsd.cfg -c

I hope that you are now running an OpenBSD VM on Xen. If you need help with setting up a Xen Hypervisor, you can check out my Xen Hypervisor with Ubuntu Blog Post how you can install one.

19 February 2025 - Philipp Keschl