Alpine on OpenBSD's vmd(8)
These are my notes on setting up Alpine Linux as a guest under OpenBSD's native vmd(8) hypervisor. This is useful way to gain access to Linux on an OpenBSD host. One can easily run Docker, Portainer, and other typically Linux-oriented software from the comfort of OpenBSD. :)
Be sure to review the man pages
$ man vmm # virtual machine monitor
$ man vmd # virtual machine daemon
$ man vm.conf
Check if your system can run vmd
$ dmesg | grep vmm >/dev/null && echo ye || echo ni
Enable vmd
$ doas rcctl enable vmd
$ doas rcctl start vmd
Create the VM directory
Create your directory somewhere nice, examples:
$ mkdir -p /home/cosmic/vmm
$ mkdir -p /home/vmm
Tip: If you need more space on an existing system, you may be able to collapse /src and /obj into a single partition and remount it as /home/vmm, if needed.
Create the VM disk
$ vmctl create -s 2G alpine-virt-aarch64.qcow2
vmctl: qcow2 imagefile created
Getting the Alpine ISO
First, I went to Alpine's download page to grab the URL to the latest virt X86_64 Alpine ISO:
> Similar to standard. Slimmed down kernel. Optimized for virtual systems.
In this case it yielded this link:
https://dl-cdn.alpinelinux.org/alpine/v3.18/releases/x86_64/alpine-virt-3.18.2-x86_64.iso
If you are running on arm64 (e.g. Raspberry Pi) be sure to grab the corresponding aarch64 Alpine ISO:
https://dl-cdn.alpinelinux.org/alpine/v3.20/releases/aarch64/alpine-virt-3.20.3-aarch64.iso
ftp will grab it easily and quickly.
$ cd /home/cosmic/vmm
$ ftp $ALPINE_ISO_URL
Other notes
The key things I wanted to note:
-
If you're SSHed into the box and need to leave the virtual console, use
~~.and type the tildes somewhat rapidly. Plain~.will drop your ssh session, but you're usingtmuxanyway, right? -
Next, the host
dhcpleasedwas stealing the DHCP packets destined for the VM. I needed torcctl stop dhcpleasedbefore I could get a lease in the VM. Source
VM configuration
This will need to be edited as root. An example file can be read here:
$ less /etc/examples/vm.conf
Here's my /etc/vm.conf with disk commented out since we need to boot the ISO first:
vm "alpine" {
boot device cdrom # disk
cdrom "/home/cosmic/vmm/alpine-virt-3.20.3-aarch64.iso"
disable
disk "/home/cosmic/vmm/alpine-virt-aarch64.qcow2"
interface tap0 {
up
}
owner cosmic:wheel
memory 256M
}
Check your config
$ doas vmd -dnv
configuration OK
Alpine setup
I chose to use openntpd as my NTP server, I like OpenBSD software (as you might be able to tell). Supposedly chrony is more accurate, e.g. subsecond precision, but that doesn't matter for me. Kinda silly but it also reminds me of "crony":
While a crony is basically just a good pal or sidekick, the word sometimes has a negative connotation — that you and your crony are up to no good together.
You can test dhcp before running alpine-setup with udhcpc eth0. Make sure eth0 is up first.
Post setup
With Alpine running successfully, we can install Docker now:
# visudo
Add this line: user ALL=(ALL) ALL
apk add docker docker-cli-compose