FreeBSD on Apple Silicon

A basic FreeBSD ARM64 installation on a Apple silicon with QEMU.
FreeBSD on Apple Silicon
  1. On macOS, install qemu and curl with homebrew:

    brew install qemu curl
    
  2. Write a script to download and install FreeBSD:

    ~ % cat bin/qemu_aarch64_install_freebsd.sh
    #!/bin/sh -
    #
    # v1.8 BSD
    # depends: curl
    #
    # 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://download.freebsd.org/releases/arm64/aarch64/ISO-IMAGES/"
    ARC="RELEASE-arm64-aarch64"
    
    v=`curl -s $URL | \
        grep date | tail -1 | \
        sed 's/^.*title="//; s/">.*//'`
    
    TMPF=$(mktemp) || exit 1
    trap "rm -f $TMPF" EXIT
    
    printf "Dowloading FreeBSD %s from mirror...\n" $v
    curl -s -o $TMPF -O ${URL}${v}/FreeBSD-${v}-${ARC}-mini-memstick.img
    printf "Dowloading SHA512 file from FreeBSD.org\n"
    a=`curl -s ${URL}${v}/CHECKSUM.SHA512-FreeBSD-${v}-${ARC} | \
        grep mini-memstick.img | head -1 | awk '{ print $4 }'`
    b=`sha512 $TMPF | awk '{ print $4 }'`
    
    echo "Checking image...\n"
    if [[ $a == $b ]]; then
        qemu-img create -f qcow2 fbsd_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=fbsd_aarch64.qcow2,format=qcow2,cache=writeback,discard=unmap \
            -device virtio-rng-pci \
            -netdev user,id=mynet0 -device virtio-net-pci,netdev=mynet0
    
    fi
    
  3. Execute the script and when the installation is done, shutdown the Virtual Machine.

  4. Start the VM:

    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/fbsd_aarch64.qcow2,format=qcow2,cache=writeback,discard=unmap \
        -device virtio-rng-pci \
        -netdev user,id=mynet0,hostfwd=tcp::7922-:22 -device virtio-net-pci,netdev=mynet0
    
  5. Once started, connect with ssh:

    ssh -p 7922 username@127.0.0.1
    

Write a comment