Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asenchi/918748826ae01b9733dab69a9574f4ea to your computer and use it in GitHub Desktop.
Save asenchi/918748826ae01b9733dab69a9574f4ea to your computer and use it in GitHub Desktop.
OpenBSD on Apple M2 with QEMU

OpenBSD on Apple M2 with QEMU

Minimalist installation of OpenBSD on the Apple M2 using QEMU

Ingredients

Installation

  1. install QEMU with Homebrew brew install qemu, also possible with MacPorts
  2. Write a script with execute permissions chmod +x qemu_aarch64_install_openbsd.sh for installing the image.
    • Download the OpenBSD installation image
    • Create an image of the OpenBSD drive
    • Getting the edk2-aarch64-code
    • Installing
#!/bin/sh -
  
curl https://ftp.fr.openbsd.org/pub/OpenBSD/7.1/arm64/miniroot71.img -o miniroot71.img 
curl https://ftp.openbsd.org/pub/OpenBSD/snapshots/arm64/SHA256 -o SHA256
shasum -c --ignore-missing SHA256

qemu-img create -f qcow2 obsd_aarch64.qcow2 32G

qemu-system-aarch64 \
    -M virt \
    -cpu host \
    -accel hvf \
    -smp 4 \
    -m 4096 \
    -nographic \
    -bios /opt/homebrew/share/qemu/edk2-aarch64-code.fd \
    -drive file=miniroot71.img,format=raw,if=virtio \
    -drive file=obsd_aarch64.qcow2,format=qcow2,if=virtio \
    -netdev user,id=mynet0,hostfwd=tcp::7922-:22 -device virtio-net,netdev=mynet0

rm miniroot71.img 
  1. Follow the OpenBSD installation program, please notice the remarks at the end of this document:

  2. When the installation is done, pkill qemu-system-aarch64

Running OpenBSD with QEMU

like this:

qemu-system-aarch64 \
    -M virt \
    -cpu host \
    -accel hvf \
    -smp 4 \
    -m 4096 \
    -nographic \
    -bios /opt/homebrew/share/qemu/edk2-aarch64-code.fd \
    -drive file=obsd_aarch64.qcow2,format=qcow2,if=virtio \
    -netdev user,id=mynet0,hostfwd=tcp::7922-:22 -device virtio-net,netdev=mynet0 

Remarks

  • there is a problem with the DNS if the network interface (vio0) is on autoconf so is better configure it manually, have a look at QEMU's User Networking, for instance IPv4 would work on 10.0.2.15/24 and 10.0.2.2 gateway.

  • alternatively a full image install71.img instead of miniroot71.img would work.

  • for the lazy asses, like me, it is possible to do autoinstall(8) with an install.conf on your localhost like this one:

    System hostname = fugu
    IPv4 address for vio0 = 10.0.2.15    
    Default IPv4 route = 10.0.2.2
    DNS nameservers = 1.1.1.1 8.8.8.8
    Password for root = RootsPassword
    Setup a user = hugo
    Password for user = HugosPassword
    Public ssh key for user = ssh-ed25519 AAA...318C hugo@fugu.local
    What timezone are you in = Europe/Helsinki
    Which disk is the root disk = sd1
    Location of sets = http 
    HTTP Server = ftp.fr.openbsd.org
    URL to autopartitioning template for disklabel = http://10.0.2.2/openbsd-pgdb.disklabel 
    

    also possible to define the disk partition adding openbsd-pgdb.disklabel on your localhost like this one:

    /           0.3G
    swap        2M        10%
    /altroot    0.3G
    /tmp        120M-4G   8%
    /var        3G        13%
    /usr        0.9G-3G   5%
    /usr/local  3G-7.5G   10%
    /home       9G-*      45%
    

Sources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment