Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@fundon
Forked from ctsrc/README.md
Created August 6, 2021 14:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fundon/e03d2a29d0a05a8ac98f5b3d0a9266a8 to your computer and use it in GitHub Desktop.
Save fundon/e03d2a29d0a05a8ac98f5b3d0a9266a8 to your computer and use it in GitHub Desktop.
How to run FreeBSD 13.0-BETA1 for ARM64 in QEMU on Apple Silicon Mac (MacBook Pro M1, etc)

How to run FreeBSD 13.0-BETA1 for ARM64 in QEMU on Apple Silicon Mac (MacBook Pro M1, etc)

FreeBSD 13.0-BETA1 for ARM64 boot in QEMU on Apple Silicon Mac screenshot

This guide was adapted from https://gist.github.com/niw/e4313b9c14e968764a52375da41b4278#running-ubuntu-server-for-arm64

Running FreeBSD 13.0-BETA1 for ARM64

  1. Install Xcode from App Store or install Command Line Tools on your Mac running on Apple Silicon.

    xcode-select --install
    
  2. Install Homebrew and QEMU dependencies.

    https://brew.sh/

    brew install ninja pkgconfig glib pixman libusb libssh zstd usbredir
    
  3. Clone QEMU source code with patches applied by patchew.

    mkdir -p ~/src/
    cd ~/src/
    git clone https://github.com/patchew-project/qemu.git
    
  4. Checkout tag that has Hypervisor.framework patches

    cd qemu
    git checkout patchew/20210120224444.71840-1-agraf@csgraf.de
    

    See https://patchew.org/QEMU/20210120224444.71840-1-agraf@csgraf.de/ for details.

  5. Build QEMU

    mkdir build/
    cd build/
    ../configure --target-list=aarch64-softmmu --enable-cocoa
    make -j
    
  6. Download pre-build EDK II OVMF EFI image for QEMU.

    This EFI image is built from stable202011 tag with additional resolutions in QemuRamfb.c.

    https://gist.github.com/niw/4f1f9bb572f40d406866f23b3127919b/raw/f546faea68f4149c06cca88fa67ace07a3758268/QEMU_EFI-cb438b9-edk2-stable202011-with-extra-resolutions.tar.gz

    To build it from the source code for adding more resolutions, see the following section.

  7. 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.
  8. Download FreeBSD 13.0-BETA1 for ARM64 raw VM image xz-compressed file

    https://download.freebsd.org/ftp/releases/VM-IMAGES/13.0-BETA1/aarch64/Latest/FreeBSD-13.0-BETA1-arm64-aarch64.raw.xz

  9. 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.0-BETA1-arm64-aarch64.raw.xz .
    unxz -k ~/Downloads/FreeBSD-13.0-BETA1-arm64-aarch64.raw.xz
    
  10. Run your FreeBSD 13.0-BETA1 for ARM64 VM

    ~/src/qemu/build/qemu-system-aarch64 \
      -M virt,highmem=off \
      -accel hvf \
      -cpu cortex-a72 \
      -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.0-BETA1-arm64-aarch64.raw,if=virtio,cache=writethrough \
      -nographic \
      -serial mon:stdio
    

A screenshot of FreeBSD 13.0-BETA1 for ARM64 console in QEMU on Apple Silicon Mac, showing the tail end of the boot output along with the login prompt and the output of uname -a Another screenshot of FreeBSD 13.0-BETA1 for ARM64 console in QEMU on Apple Silicon Mac, this time showing that networking is working and is able to connect over HTTP to the website www.example.com

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