Guide: Run FreeBSD 13.1-RELEASE for ARM64 in QEMU on Apple Silicon Mac (MacBook Pro M1, etc) with HVF acceleration (Hypervisor.framework)
This guide was adapted from https://gist.github.com/niw/e4313b9c14e968764a52375da41b4278#running-ubuntu-server-for-arm64
-
Install Xcode from App Store or install Command Line Tools on your Mac running on Apple Silicon.
xcode-select --install
-
Install Homebrew and QEMU.
brew install qemu
rehash
qemu-system-aarch64 --version
QEMU emulator version 7.0.0 Copyright (c) 2003-2022 Fabrice Bellard and the QEMU Project developers
-
Download pre-build EDK II OVMF EFI image for QEMU.
This EFI image is built from
stable202011
tag with additional resolutions inQemuRamfb.c
.To build it from the source code for adding more resolutions, see the following section.
-
Prepare pflash for non-volatile variable store, such as screen resolution.
mkdir ~/qemu-vm/ cd ~/qemu-vm/ tar xvf ~/Downloads/QEMU_EFI-cb438b9-edk2-stable202011-with-extra-resolutions.tar.gz dd if=/dev/zero of=pflash0.img bs=1m count=64 dd if=/dev/zero of=pflash1.img bs=1m count=64 dd if=QEMU_EFI.fd of=pflash0.img conv=notrunc dd if=QEMU_VARS.fd of=pflash1.img conv=notrunc
- This step is optional, you can use
-bios QEMU_EFI.fd
instead of-drive ...if=pflash
lines in the next step, but in that case, any changes in EFI will not be persistent.
- This step is optional, you can use
-
Download FreeBSD 13.1-RELEASE for ARM64 raw VM image xz-compressed file
(See https://docs.freebsd.org/en/books/handbook/mirrors/ for a list of mirrors to choose from.)
-
Decompress xz-compressed file, keeping a copy of the original compressed file
Keeping a copy of the original file is convenient because then you can use it if you want to create additional VMs later. Just be careful not to overwrite the image of your first VM when you want to make a second VM though :P
mv ~/Downloads/FreeBSD-13.1-RELEASE-arm64-aarch64.raw.xz . unxz -k FreeBSD-13.1-RELEASE-arm64-aarch64.raw.xz
-
Grow the disk image
After you've decompressed the disk image, it'll be about 5 GiB in size. Depending on what you plan to do the amount of available space may be a bit on the low side. Let's grow the disk image by another 30 GiB.
qemu-img resize -f raw FreeBSD-13.1-RELEASE-arm64-aarch64.raw +30G
By performing this resize before you boot the VM for the first time, FreeBSD will automatically adjust the partition size during first boot.
-
Run your FreeBSD 13.1-RELEASE for ARM64 VM
qemu-system-aarch64 \ -M virt \ -accel hvf \ -cpu host \ -smp 4 \ -m 4096 \ -drive file=pflash0.img,format=raw,if=pflash,readonly=on \ -drive file=pflash1.img,format=raw,if=pflash \ -device virtio-gpu-pci \ -display default,show-cursor=on \ -device qemu-xhci \ -device usb-kbd \ -device usb-tablet \ -device intel-hda \ -device hda-duplex \ -drive file=FreeBSD-13.1-RELEASE-arm64-aarch64.raw,format=raw,if=virtio,cache=writethrough \ -nographic \ -serial mon:stdio
(Installed via Homebrew.)
Events per second: 25,445,903.16 or ~25.4 Mio events/sec
sysbench cpu --threads=2 run
sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)
Running the test with following options:
Number of threads: 2
Initializing random number generator from current time
Prime numbers limit: 10000
Initializing worker threads...
Threads started!
CPU speed:
events per second: 25445903.16
General statistics:
total time: 10.0000s
total number of events: 254468472
Latency (ms):
min: 0.00
avg: 0.00
max: 0.12
95th percentile: 0.00
sum: 8916.15
Threads fairness:
events (avg/stddev): 127234236.0000/15768.00
execution time (avg/stddev): 4.4581/0.00
(Installed via FreeBSD ports.)
Events per second: 15,467,914.47 or ~15.5 Mio events/sec
sysbench cpu --threads=2 run
sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)
Running the test with following options:
Number of threads: 2
Initializing random number generator from current time
Prime numbers limit: 10000
Initializing worker threads...
Threads started!
CPU speed:
events per second: 15467914.47
General statistics:
total time: 10.0003s
total number of events: 154689213
Latency (ms):
min: 0.00
avg: 0.00
max: 0.21
95th percentile: 0.00
sum: 5684.03
Threads fairness:
events (avg/stddev): 77344606.5000/169564.50
execution time (avg/stddev): 2.8420/0.00
@dmilith What do you mean it won't work? I am running qemu 7.0 as shown in the output of the guide, running on MacBook Pro (13-inch, M1, 2020).
I see that you are using the highmem=off argument. With qemu 7.0 you must run without that part.
Please install qemu 7.0 and follow the guide step by step and you will see that it does work.