Xen OpenBSD HVM Guest
In this article, I want to describe how to run OpenBSD as a 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 to use serial as default in the installer. Later, I 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. I 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 several, 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 configuration 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 require help with setting up a Xen Hypervisor, you can check out my Xen Hypervisor with Ubuntu Blog Post on how you can install one.
19 February 2025 - Philipp Keschl