OpenBSD on Apple M (QEMU)

OpenBSD is the OS with the coolest mascot, and that is more than enough to try it, here's a quick and dirty solution for QEMU
OpenBSD on Apple M (QEMU)

Starting from an apple silicon, macOS with QEMU (from homebrew ) as we did with FreeBSD :

  1. Script to download, verify, crate image and install it:
~ % cat ~/bin/qemu_aarch64_install_openbsd.sh 
#!/bin/sh -
#
# v2.1 BSD
# downloads and install on QEMU the last OpenBSD arm64
# tested on apple M2
# depends: curl, qemu
#
# cache=none on drive if it breaks
#
# Copyright (c) 1996, 2026 tuco astrek <tuco@astrek.net>
#
# Permission to use, copy, modify, and/or distribute this software for
# any purpose with or without fee is hereby granted.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

URL="https://ftp.openbsd.org/pub/OpenBSD/"
MIRROR="https://ftp.eu.openbsd.org/pub/OpenBSD/"

v=`curl -s $URL | \
    grep -B2 Changelogs | \
    head -1 | \
    sed "s/\/<\/a><\/td>//; s/^.*>//"`

TMPF=$(mktemp) || exit 1
trap "rm -f $TMPF" EXIT

printf "Dowloading OpenBSD %s from mirror...\n" $v
curl -s -o $TMPF -O ${MIRROR}${v}/arm64/miniroot${v//./}.img
printf "Dowloading SHA256 file from OpenBSD.org"
a=`curl -s ${URL}${v}/arm64/SHA256 | grep miniro | awk '{ print $4 }'`
b=`sha256 $TMPF | awk '{ print $4 }'`

echo "Checking image with main site..."
if [[ $a == $b ]]; then
    qemu-img create -f qcow2 obsd_aarch64.qcow2 16G
    qemu-system-aarch64 \
        -machine virt,highmem=on \
        -accel hvf \
        -cpu host \
        -smp 4 \
        -m 4G \
        -nographic \
        -bios /opt/homebrew/share/qemu/edk2-aarch64-code.fd \
        -drive if=virtio,file="$TMPF",format=raw,media=cdrom,readonly=on \
        -drive if=virtio,file=obsd_aarch64.qcow2,format=qcow2,cache=writeback,discard=unmap \
        -device virtio-rng-pci \
        -netdev user,id=mynet0 -device virtio-net-pci,netdev=mynet0
fi
  1. Then we can run it this way:
qemu-system-aarch64 \
    -machine virt,highmem=on \
    -accel hvf \
    -cpu host \
    -smp 4 \
    -m 4G \
    -nographic \
    -bios /opt/homebrew/share/qemu/edk2-aarch64-code.fd \
    -drive if=virtio,file=${HOME}/obsd_aarch64.qcow2,format=qcow2,cache=writeback,discard=unmap \
    -device virtio-rng-pci \
    -netdev user,id=mynet0,hostfwd=tcp::7822-:22 -device virtio-net-pci,netdev=mynet0

Write a comment