FreeBSD on Apple Silicon

A basic FreeBSD ARM64 installation on a Apple silicon with QEMU.
FreeBSD on Apple Silicon
  1. Install qemu and curl with homebrew:

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

    #!/bin/sh -
    #
    # dependencies: curl
    
    VER="15.0"
    
    TMPF=$(mktemp) || exit 1
    trap "rm -f $TMPF" EXIT
    
    curl -C - -O https://download.freebsd.org/releases/arm64/aarch64/ISO-IMAGES/$VER/FreeBSD-$VER-RELEASE-arm64-aarch64-mini-memstick.img
    curl -o $TMPF https://download.freebsd.org/releases/arm64/aarch64/ISO-IMAGES/$VER/CHECKSUM.SHA512-FreeBSD-$VER-RELEASE-arm64-aarch64
    pass=`shasum -c --ignore-missing $TMPF | awk '{ print $2 }'`
    if [[ $pass == "OK" ]]; then
        qemu-img create -f qcow2 fbsd_aarch64.qcow2 16G
    fi
    
    qemu-system-aarch64 \
        -M virt \
        -cpu host \
        -accel hvf \
        -smp 4 \
        -m 4G \
        -nographic \
        -serial mon:stdio \
        -bios /opt/homebrew/share/qemu/edk2-aarch64-code.fd \
        -drive file=FreeBSD-$VER-RELEASE-arm64-aarch64-mini-memstick.img,format=raw,if=virtio,cache=writethrough \
        -drive file=fbsd_aarch64.qcow2,format=qcow2,if=virtio \
        -netdev user,id=mynet0,hostfwd=tcp::9022-:22 -device virtio-net,netdev=mynet0 \
    
    rm $TMPF FreeBSD-$VER-RELEASE-arm64-aarch64-mini-memstick.img 
    
  3. Execute the script and when the installation is done, shutdown the Virtual Machine.

  4. Create a script to start the VM:

    #!/bin/sh -
    #
    # ssh connection via port 7922
    
    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=fbsd_aarch64.qcow2,format=qcow2,if=virtio \
        -netdev user,id=mynet0,hostfwd=tcp::7922-:22 -device virtio-net,netdev=mynet0 
    
  5. Once started, connect with ssh:

    ssh -p 7922 username@127.0.0.1
    

Write a comment
No comments yet.