The accepted answer does not work anymore because the patch series does not show up when you click the link in that blog post. I had tried going through the same set of instructions. So I went through a lot of material to skim out what was out there. I was using Qemu after about 10 years since I last tried it so it took some time but it looks like someone already had built an app (an actual .app with a UI) which contains the qemu build for M1 that contains the hvf accelerator/hypervisor support.
I have written a detailed blog post about it here (in case the instructions are unclear or if you want to see the pictures).
Before you go in for the long haul, do take a look at the UTM App. It is free and open-source and I have used this app to successfully run my Ubuntu (ARM) image on Mac. There are features missing compared to VirtualBox and others, but as of now, this is the easiest it can get to running Ubuntu on your mac.
Now, the steps for long (manual) method:
Get the ACVM App
You can download it from here. You can try compiling it or just get the released version from releases.
Download the Ubuntu image
Download the Ubuntu for ARM image from Ubuntu's website. You can download a daily-live image from here or you can get the ARM server image from here and install the GUI later. I suggest you get the stable image and install the GUI later but current build served me just fine.
Create Target Disk
Create a target disk where your VM will live. If you moved the ACVM app into /Applications
, then run the following commands:
cd /Applications/ACVM.app/Contents/Resources
mkdir $HOME/UbuntuVM
./qemu-img create -f qcow2 $HOME/UbuntuVM/Ubuntu.qcow2 40G
You can change the size of the target disk to what you want but 40 G should be fine.
Start the ACVM app
Start the ACVM app and drop your ISO file in the CD image area and qcow
image you just created in the Main image section and click on start. There is also qemu command that you can use.
You should see Ubuntu booting up. Proceed with installation!
Start the installed Ubuntu
Ensure you are still in /Applications/ACVM.app/Contents/Resources
and run:
./qemu-system-aarch64 \
-serial stdio \
-M virt,highmem=off \
-accel hvf \
-cpu cortex-a72 \
-smp 4,cores=4 \
-m 4096 \
-bios "/Applications/ACVM.app/Contents/Resources/QEMU_EFI.fd" \
-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="$HOME/UbuntuVM/Ubuntu.qcow2",if=virtio,cache=writethrough
You should get the Ubuntu (ARM architecture) VM running on your Mac M1 machine.
NOTE: You can also try to run the machine using the ACVM app again (just drop in the main image, leave the CD image one empty and press start). But when I did that, I would always face some kind of issues, mostly my screen would stay black for a very long time.
These steps should work for all macOS machines with the M1 chip (MacBook Air, MacBook Pro, Mac Mini and the upcoming iMacs).