Skip to content

Instantly share code, notes, and snippets.

@astreknet
Last active October 25, 2024 21:27
Show Gist options
  • Save astreknet/4860e3362ad98e1116f0a970b99e2afc to your computer and use it in GitHub Desktop.
Save astreknet/4860e3362ad98e1116f0a970b99e2afc 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.eu.openbsd.org/pub/OpenBSD/7.5/arm64/miniroot75.img -o miniroot75.img 
curl https://ftp.openbsd.org/pub/OpenBSD/7.5/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 \
    -serial mon:stdio \
    -bios /opt/homebrew/share/qemu/edk2-aarch64-code.fd \
    -drive file=miniroot75.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 miniroot75.img SHA256 
  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 installXX.img instead of minirootXX.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 = myHost
    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 = myName
    Password for user = myPassword
    Public ssh key for user = ssh-ed25519 AAA...318C [email protected]
    What timezone are you in = YOUR/TIMEZONE
    Which disk is the root disk = sd1
    Location of sets = http 
    HTTP Server = ftp.eu.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

@solus-hq
Copy link

Screenshot 2022-08-31 at 11 44 43

Hello @ast3k!

Could you please take a look at possible workarounds, I did somehow manage to launch installer several times, but it ended up being unable to complete installation due to insufficient virtual disk size. Now it just throws these kind of errors

@astreknet
Copy link
Author

Hi @solus-hq
Notice that you are creating a qemu image of 32G (although won't just more than 3G). Check your free space.

I just run mine to check and seems to work fine:

qemus % ./qemu_aarch64_install_openbsd.sh  
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 43.0M  100 43.0M    0     0  5379k      0  0:00:08  0:00:08 --:--:-- 9128k
Formatting 'obsd_aarch64.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=34359738368 lazy_refcounts=off refcount_bits=16

BdsDxe: failed to load Boot0001 "UEFI Misc Device" from VenHw(93E34C7E-B50E-11DF-9223-2443DFD72085,00): Not Found
BdsDxe: loading Boot0002 "UEFI Misc Device 2" from PciRoot(0x0)/Pci(0x2,0x0)
BdsDxe: starting Boot0002 "UEFI Misc Device 2" from PciRoot(0x0)/Pci(0x2,0x0)
disks: sd0* sd1 sd2
>> OpenBSD/arm64 BOOTAA64 1.8
boot> 
cannot open sd0a:/etc/random.seed: No such file or directory
booting sd0a:/bsd: 2652268+722656+13001984+629528 [221560+91+613344+239668]=0x1406908
FACP APIC PPTT GTDT MCFG SPCR DBG2 IORT 
type 0x2 pa 0x40000000 va 0x0 pages 0x4000 attr 0x8
type 0x7 pa 0x44000000 va 0x0 pages 0xf7e3b attr 0x8
type 0x2 pa 0x13be3b000 va 0x0 pages 0x106 attr 0x8
type 0x1 pa 0x13bf41000 va 0x0 pages 0x2f attr 0x8
type 0x9 pa 0x13bf70000 va 0x0 pages 0x10 attr 0x8
type 0x5 pa 0x13bf80000 va 0xa3863000 pages 0x80 attr 0x8000000000000008
type 0x4 pa 0x13c000000 va 0x0 pages 0x20 attr 0x8
type 0x6 pa 0x13c020000 va 0xa3903000 pages 0x170 attr 0x8000000000000008
type 0x5 pa 0x13c190000 va 0xa3a73000 pages 0x50 attr 0x8000000000000008
type 0x6 pa 0x13c1e0000 va 0xa3ac3000 pages 0xa0 attr 0x8000000000000008
type 0x5 pa 0x13c280000 va 0xa3b63000 pages 0xf0 attr 0x8000000000000008
type 0x7 pa 0x13c370000 va 0x0 pages 0xb88 attr 0x8
type 0x4 pa 0x13cef8000 va 0x0 pages 0x2370 attr 0x8
type 0x7 pa 0x13f268000 va 0x0 pages 0xa4 attr 0x8
type 0x3 pa 0x13f30c000 va 0x0 pages 0x344 attr 0x8
type 0x5 pa 0x13f650000 va 0xa6f33000 pages 0x90 attr 0x8000000000000008
type 0x7 pa 0x13f6e0000 va 0x0 pages 0x10 attr 0x8
type 0x6 pa 0x13f6f0000 va 0xa6fd3000 pages 0x120 attr 0x8000000000000008
type 0x7 pa 0x13f810000 va 0x0 pages 0x14 attr 0x8
type 0x4 pa 0x13f824000 va 0x0 pages 0x23 attr 0x8
type 0x3 pa 0x13f847000 va 0x0 pages 0x37 attr 0x8
type 0x4 pa 0x13f87e000 va 0x0 pages 0x66d attr 0x8
type 0x3 pa 0x13feeb000 va 0x0 pages 0x4 attr 0x8
type 0x4 pa 0x13feef000 va 0x0 pages 0x101 attr 0x8
type 0x3 pa 0x13fff0000 va 0x0 pages 0xd attr 0x8
type 0x4 pa 0x13fffd000 va 0x0 pages 0x3 attr 0x8
type 0xb pa 0x4000000 va 0xa70f3000 pages 0x4000 attr 0x8000000000000001
type 0xb pa 0x9010000 va 0xab0f3000 pages 0x1 attr 0x8000000000000001
Copyright (c) 1982, 1986, 1989, 1991, 1993
	The Regents of the University of California.  All rights reserved.
Copyright (c) 1995-2022 OpenBSD. All rights reserved.  https://www.OpenBSD.org

OpenBSD 7.1 (RAMDISK) #1522: Mon Apr 11 22:03:55 MDT 2022
    [email protected]:/usr/src/sys/arch/arm64/compile/RAMDISK
real mem  = 4287787008 (4089MB)
avail mem = 4073906176 (3885MB)
random: boothowto does not indicate good seed
mainbus0 at root: ACPI
psci0 at mainbus0: PSCI 1.1
cpu0 at mainbus0 mpidr 0: Unknown, MIDR 0x0
cpu0: 192KB 64b/line 6-way L1 PIPT I-cache, 128KB 64b/line 8-way L1 D-cache
cpu0: 16384KB 128b/line 16-way L2 cache
cpu0: TLBIOS+IRANGE,TS+AXFLAG,FHM,DP,SHA3,RDM,Atomic,CRC32,SHA2+SHA512,SHA1,AES+PMULL,SPECRES,SB,FRINTTS,GPI,LRCPC+LDAPUR,FCMA,JSCVT,API+PAC,DPB,SpecSEI,PAN+ATS1E1,LO,HPDS,CSV3,CSV2
efi0 at mainbus0: UEFI 2.7
efi0: EDK II rev 0x10000
ampintc0 at mainbus0 nirq 288, ncpu 4: "interrupt-controller"
ampintcmsi0 at ampintc0: nspi 64
agtimer0 at mainbus0: 24000 kHz
acpi0 at mainbus0: ACPI 5.1
acpi0: tables DSDT FACP APIC PPTT GTDT MCFG SPCR DBG2 IORT
acpimcfg0 at acpi0
acpimcfg0: addr 0x3f000000, bus 0-15
acpiiort0 at acpi0
"ACPI0007" at acpi0 not configured
"ACPI0007" at acpi0 not configured
"ACPI0007" at acpi0 not configured
"ACPI0007" at acpi0 not configured
pluart0 at acpi0 COM0 addr 0x9000000/0x1000 irq 33: console
"QEMU0002" at acpi0 not configured
"LNRO0005" at acpi0 not configured
"LNRO0005" at acpi0 not configured
"LNRO0005" at acpi0 not configured
"LNRO0005" at acpi0 not configured
"LNRO0005" at acpi0 not configured
"LNRO0005" at acpi0 not configured
"LNRO0005" at acpi0 not configured
"LNRO0005" at acpi0 not configured
"LNRO0005" at acpi0 not configured
"LNRO0005" at acpi0 not configured
"LNRO0005" at acpi0 not configured
"LNRO0005" at acpi0 not configured
"LNRO0005" at acpi0 not configured
"LNRO0005" at acpi0 not configured
"LNRO0005" at acpi0 not configured
"LNRO0005" at acpi0 not configured
"LNRO0005" at acpi0 not configured
"LNRO0005" at acpi0 not configured
"LNRO0005" at acpi0 not configured
"LNRO0005" at acpi0 not configured
"LNRO0005" at acpi0 not configured
"LNRO0005" at acpi0 not configured
"LNRO0005" at acpi0 not configured
"LNRO0005" at acpi0 not configured
"LNRO0005" at acpi0 not configured
"LNRO0005" at acpi0 not configured
"LNRO0005" at acpi0 not configured
"LNRO0005" at acpi0 not configured
"LNRO0005" at acpi0 not configured
"LNRO0005" at acpi0 not configured
"LNRO0005" at acpi0 not configured
"LNRO0005" at acpi0 not configured
acpipci0 at acpi0 PCI0
pci0 at acpipci0
0:1:0: rom address conflict 0xfffc0000/0x40000
"Red Hat Host" rev 0x00 at pci0 dev 0 function 0 not configured
virtio0 at pci0 dev 1 function 0 "Qumranet Virtio Network" rev 0x00
vio0 at virtio0: address 52:54:00:12:34:56
virtio0: msix shared
virtio1 at pci0 dev 2 function 0 "Qumranet Virtio Storage" rev 0x00
vioblk0 at virtio1
scsibus0 at vioblk0: 1 targets
sd0 at scsibus0 targ 0 lun 0: <VirtIO, Block Device, >
sd0: 43MB, 512 bytes/sector, 88064 sectors
virtio1: msix per-VQ
virtio2 at pci0 dev 3 function 0 "Qumranet Virtio Storage" rev 0x00
vioblk1 at virtio2
scsibus1 at vioblk1: 1 targets
sd1 at scsibus1 targ 0 lun 0: <VirtIO, Block Device, >
sd1: 32768MB, 512 bytes/sector, 67108864 sectors
virtio2: msix per-VQ
"ACPI0013" at acpi0 not configured
"PNP0C0C" at acpi0 not configured
softraid0 at root
scsibus2 at softraid0: 256 targets
root on rd0a swap on rd0b dump on rd0b
WARNING: CHECK AND RESET THE DATE!
erase ^?, werase ^W, kill ^U, intr ^C, status ^T

Welcome to the OpenBSD/arm64 7.1 installation program.
(I)nstall, (U)pgrade, (A)utoinstall or (S)hell?

I also tried with the last queen version QEMU emulator version 7.1.0 and works.

As an alternative you can take out the -nographic option and see it in the qemu view serial0

@solus-hq
Copy link

@ast3k Thank you for you help!

  1. I created a smaller disk image
  2. I was choosing the wrong disk device (sd0 insteand of sd1) which led to insufficient disk space when moving kernels or something
  3. I was using miniroot71.img and now I'm using install71.img

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