Solved FreeBSD on Apple Silicon

Thanks for that pointer!
Interestingly, when I searched the forum before posting my question, I got no hits at all.
Searching for M1 -the obvious choice, returned:
Oops! We ran into some problems.
The search could not be completed because the search keywords were too short, too long, or too common.
Searching for M1 chip returned hundreds of unrelated results, under a heading that says:
Search results for query: M1 chip
The following words were not included in your search because they are too short, too long, or too common: M1
So, essentially it just searched for chip.
It would be interesting to actually perform a search on the forum contents and see how much hit it would produce NOT related to Apple's M1 chip. Then show it to the person who decided that something 2-characters long cannot be relevant or accurate. :(
 
Honestly the forum search is a bit.. ehm.. meh..

Google works a lot better, use these search terms: site:forums.freebsd.org m1. In case you didn't know, you can use a site: keyword to restrict your searches to a specific site.
 
I got no hits at all.
Searching for M1 -the obvious choice, returned:
Because the forums search is limited to a three character string.

See discussion
 
I've got FreeBSD 13.2 running inside VMWare Fusion Pro 13 on an M1 Max Mac Studio, and it all seems to work nicely. This is running on top of macOS 13.4.

Edit: I installed FreeBSD from the ISO.
 
Has anybody here tried FreeBSD 13.0 on an M1 Mac?
I wonder how it works. Any experience to share?
I have installed FreeBSD 12.4 and 13.2 using UTM (in MBA M2 Apple Silicon)
I just installed aarch64 simple configuration just to analyze if FreeBSD will run...

I didn't try install or use these FreeBSD as a real vm with freebsd applications....
Just installed try to ping ....and it works...

But while idle FreeBSD I noticed that Qemulauncher process responsible for VM creates load ~200% CPU on my Apple Silicon M2

I added this line: kern.hz=100 in /boot/loader.conf
and now runs perfectly.

1691604918906.png
1691605912751.png
 
I have installed FreeBSD 12.4 and 13.2 using UTM (in MBA M2 Apple Silicon)
...
I added this line: kern.hz=100 in /boot/loader.conf
and now runs perfectly.
Things are very promising now.
And the kern.hz trick is very useful to know. Thanks for sharing!
With Asahi Linux now being able to be installed and run directly on Apple Silicon hardware, and seeing reports that FreeBSD aarch64 works in UTM, it may soon be possible to run it directly on hw too. I expect difficulties to get booting done right, probably a few more special area, but we are eventually getting there.
 
I had FreeBSD running on an M1 via UTM as Cromulent mentioned. If I recall, it supported few video modes and full-screen wasn't an option for me.
 
I've run it in UTM, but I think it would be interesting if it ran natively on the M1 and even more interesting if you could merely reboot to go back to the original OS. Ie, boot up to a USB thumbdrive and then unplug and reboot to go back to the original OS.
 
Hello it does run on UTM version 4.5.3 on the Apple M1 with Sonoma 14.5, I can even run a freeBSD jail inside of the virtual machine.

I am running freeBSD 14.1 Generic arm64 on it.

Screenshot 2024-07-16 at 22.30.26.png
 
UTM seemed to cause some instability on my M1, so I switched to using Qemu directly (UTM uses Qemu under the hood). I installed Qemu via pkgsrc.

Some Mac-specific instructions are here: https://wiki.freebsd.org/arm64/QEMU

I wrote a script based on that for quick-and-easy setup of a text-only VM using NAT networking. Haven't tried setting up a desktop env yet.

Code:
#!/bin/sh -e

##########################################################################
#   Synopsis:
#       qemu-freebsd-guest version RAM-size processors
#
#   Description:
#       Boot a FreeBSD instance under QEMU, downloading and
#       installing a VM image first if necessary.
#      
#   History:
#   Date        Name        Modification
#   2024-07-23  Jason Bacon Begin
##########################################################################

usage()
{
    printf "Usage: $0 version ramsize (MiB) processors\n"
    printf "Example: $0 14.1-RELEASE 2048 4\n"
    exit 1
}


##########################################################################
#   Main
##########################################################################

if [ $# != 3 ]; then
    usage
fi
version=$1
suffix=${version##*-}
ramsize=$2
procs=$3

case $(uname -m) in
arm64)
    if [ $(uname) = Darwin ]; then
        host_mem=$(sysctl -n hw.memsize)
        host_mem=$(($host_mem / 1024 / 1024))
        allowed_mem=$(($host_mem - 2 * 1024))
        echo $allowed_mem
        #exit
        if [ $ramsize -gt $allowed_mem ]; then
            printf "Error: Maximum ramsize is $allowed_mem.\n" >> /dev/stderr
            exit 1
        fi
       
        arch=aarch64
        # https://download.freebsd.org/releases/VM-IMAGES/14.1-RELEASE/aarch64/Latest/
        if [ $suffix = RELEASE ] || [ $(echo $suffix | cut -c 1-2) = RC ]; then
            remote_dir=releases/VM-IMAGES/$version/aarch64/Latest/
        else
            remote_dir=snapshots/VM-IMAGES/$version/aarch64/Latest/
        fi
        image=FreeBSD-$version-arm64-aarch64.raw
        cpu=cortex-a57
        bios=edk2-aarch64-code.fd
        machine=virt,accel=hvf
    else
        printf "arm64 is only supported on macOS.\n" >> /dev/stderr
        exit 1
    fi
    ;;

*)
    printf "$(uname -m) is not currently supported.\n"
    exit 1
    ;;
esac

qemu_dir=~/Qemu
if [ ! -e $qemu_dir/$image ]; then
    if [ ! -e $qemu_dir/$image.xz ]; then
        site=https://download.freebsd.org/
        mkdir -p $qemu_dir
        cd $qemu_dir
        curl -O $site/$remote_dir/$image.xz
    fi
    printf "Decompressing $image...\n"
    unxz $qemu_dir/$image.xz
    size=20G
    printf "Expanding $image to $size...\n"
    truncate -s $size $qemu_dir/$image
fi

# https://wiki.freebsd.org/arm64/QEMU
# Enable ssh via TCP port 8022
# Must add sshd_enable="YES" to /etc/rc.conf and run "service sshd start"
qemu-system-$arch -m $ramsize -cpu host \
    -bios $bios -M $machine -nographic \
    -smp $procs \
    -drive if=virtio,file=$qemu_dir/$image,id=hd0,format=raw \
    -netdev user,id=net0,hostfwd=tcp::8022-:22 \
    -device virtio-net,netdev=net0

# Alt: https://dev.to/krjakbrjak/qemu-networking-on-macos-549k
#    -netdev vmnet-bridged,id=net0,ifname=en0
# Above requires qemu running as root.  Look into socket_vmnet.
 
Back
Top