Quick start: virtual machines on OpenBSD
openbsd virtualisationSince OpenBSD 5.9 it is possible to run virtual machines using a native virtualisation solution.
This is a short note/guide on how to set up a VM on OpenBSD in the simplest way that lets you have a quick play with vmm/vmd.
Preliminaries
-
First of all, we need to enable vmd on our host and get it running:
# rcctl enable vmd # rcctl start vmd
-
You may also want to make sure you firewall can initially let everything through:
# Pass everything on the VM interface pass quick on tap0 # NAT for the VM network pass out on egress from 100.64.0.0/10 to any nat-to (egress)
Installation
-
Let’s assume we store all of our VMs in
/var/vm
and openbsd will be the name of our experimental VM.# mkdir /var/vm/openbsd # cd /var/vm/openbsd
-
To install OpenBSD inside of the VM we download the installation image (and store it in the same directory as the VM, which probably is not very clean):
# wget https://cdn.openbsd.org/pub/OpenBSD/6.9/amd64/install69.iso
-
Then, we create a virtual 10G disk:
# vmctl create -s 10G openbsd.qcow2
-
To start the VM and boot it from the installation image, we run the following command:
# vmctl start -m 1G -L -i 1 -r install69.iso -d openbsd.qcow2 openbsd
-
Connect to the console. This effectively finds the console for the openbsd VM and calls
cu
.# vmctl console openbsd
To disconnect from the console you need to type in an escape sequence:
~.
(or~~.
if you are connected via SSH).
Configuration of vmd
You can add your VM’s configuration to /etc/vm.conf
:
vm "openbsd" {
memory 1G
enable
disk /var/vm/openbsd/openbsd.qcow2
local interface
}
This will allow you to skip all the additional switches to vmctl start
that we used earlier.
Controlling the VM
To control your VM, you can use vmctl
:
-
run
vmctl status
to check the status of all the VMs running in your system, orvmctl status openbsd
to check the status of your VM, -
vmctl start openbsd
andvmctl stop openbsd
start and stop your VM, respectively.