Running an ARM64 OpenBSD Virtual Machine on Apple Silicon
- Install an HVF-equipped build of QEMU
- Download the OpenBSD 7 Install Image
- Create a new virtual disk
- Set up the launch script
- Install OpenBSD
- Set up host to guest SSH access
Install an HVF-equipped build of QEMU
The QEMU developers recently merged Apple Silicon support for Apple’s Hypervisor.Framework virtualization layer. This means that barring any complications or removals, the next release tag for QEMU should include this support.
For more information, see the 6.2 planning page on the QEMU wiki.
Alas, if you are reading this before the next release of QEMU that contains this code is generally available, you will need to build QEMU from source.
If you use the Homebrew package manager, then this means you already have the Xcode build tools installed, so this can be as easy as:
$ git clone https://gitlab.com/qemu-project/qemu.git
$ cd qemu
$ brew install meson
$ brew deps qemu | xargs brew install
$ mkdir builddir
$ cd builddir
$ ../configure --target-list=aarch64-softmmu
$ meson compile
$ sudo meson install
If the idea of building and installing the bleeding edge of QEMU is offensive to you, then you may wish to check out the latest tag and apply the Apple Silicon Hypervisor.Framework patches on top of it.
Download the OpenBSD 7 Install Image
Create a directory for stashing install media:
$ mkdir -p $HOME/virt/images/base
Download the install image and the SHA256 info:
$ cd $HOME/virt/images/base
$ curl -LkO https://cdn.openbsd.org/pub/OpenBSD/7.0/arm64/SHA256
$ curl -LkO https://cdn.openbsd.org/pub/OpenBSD/7.0/arm64/install70.img
Always check the checksums:
$ shasum -a 256 -c SHA256 --ignore-missing
install70.img: OK
Create a new virtual disk
$ qemu-img create -f qcow2 openbsd.qcow2 15G
Set up the launch script
cat > run_openbsd.sh <<EOF
#!/usr/bin/env sh
qemu-system-aarch64 \
-M virt \
-accel hvf \
-m 2048 \
-cpu cortex-a57 -M virt,highmem=off \
-drive file=/usr/local/share/qemu/edk2-aarch64-code.fd,if=pflash,format=raw,readonly=on \
-drive file=install70.img \
-drive file=openbsd.qcow2,format=qcow2 \
-nographic \
-serial tcp::4444,server,telnet,wait
EOF
Don’t forget to replace the path to your openbsd.qcow2
.
Mark it as executable:
$ chmod u+x run_openbsd.sh
In the next step you will launch the VM, but won’t see anything. That is because QEMU is waiting for you to connect over telnet before it proceeds.
So, in one window:
$ ./run_openbsd.sh
And in another window:
$ telnet localhost 4444
Wait for the early boot messages to finish and eventually you should see something resembling an OpenBSD install prompt.
Install OpenBSD
This step is up to you! Just remember that once it’s finished installing,
remove the -drive
line in your run_openbsd.sh
that contains the
install70.img
. You don’t need it anymore!
Enjoy your super-fast OpenBSD VM on your super-fast Apple Silicon machine!
Set up host to guest SSH access
You don’t have to live your life exclusively over telnet. If you’d
prefer to SSH in at this point, go ahead and add these lines to
your run_openbsd.sh
launcher script:
-net user,hostfwd=tcp::2222-:22 \
-net nic \
This will forward port 2222 on your host to port 22 in the guest (which is the default port that sshd will listen on).
In the guest, enable sshd:
# rcctl enable sshd
# rcctl start sshd
On the host, copy your public key over (unless you’d rather type the password for the user in your guest)
$ ssh-copy-id -i ~/.ssh/id_ed25519 -p 2222 ckuehl@localhost
Finally, now you can simply SSH into your guest whenever you want:
$ ssh -p 2222 ckuehl@localhost