Use UTM instead

The information contained on this page is outdated. It was written at a time when Qemu did not implement the Apple’s Hypervisor. Things have changed since then. Also, UTM is there which can do the same stuff in a more friendly way. It is basically a frontend to Qemu with some extra goodies. It is a great open source application and worth a try.

At the time of writing this Blog Post, Apple Silicon’s first series of machines are out (the M1 SoC chip equipped MacBook Air, Macbook Pro 13-inch and Mac Mini). Docker is not yet fully stable (still in Tech Preview mode), there is no VMware Fusion for M1 and a lot of apps on Mac are still only targeted for x86_64 machines as of now. There is a Parallels Desktop release in Tech Preview mode which allows you to install Ubuntu but does not allow you to set the resolution of the resulting machine beyond 1024×768 pixels. There is no single blog/tutorial which guides you on how to make a Ubuntu (preferably 20.04) VM run on the M1 machines. I scoured the internet and put some pieces together to make it finally work.

Installing Ubuntu on a machine with M1 chip

There is a great article here about how to patch the Qemu source code and build it to get the binary but the link to the path which actually gets the job done is either broken or the patch has been deleted or it has been merged into the main branch of QEMU (which doesn’t seem to be the case).

Remember that if you install qemu via brew, it will not work because it does not know how to talk to the new Hypervisor Framework by Apple which is needed for virtualization on M1 machines. Also, this exercise was done on a Macbook Air with M1 processor but should work with other machines with the same chip. Let’s start:

Step 1 - Get the ACVM App

Get the ACVM app. The source code is here and you can compile it if you want but I just used the pre-built binary from this release though. So head to the release page and download the zip file and unzip it (if it doesn’t get automatically unzipped). I moved the app to /Applications but you can actually run it from anywhere you want. The commands in this post will assume that you have the ACVM app in /Applications folder.

Step 2 - Download Ubuntu for ARM

Download the Ubuntu Focal Desktop image for ARM machines. You can see the entire list of images here. Make sure you download the one named focal-desktop-arm64.iso. Note that you have to download the arm64 image, not the amd64 one.

You can also download the server image for ARM architecture from here and install the GUI later if needed.

Step 3 - Create target disk image

Create the disk image. For this you should run following commands:

cd /Applications/ACVM.app/Contents/Resources
mkdir $HOME/UbuntuVM
./qemu-img create -f qcow2 $HOME/UbuntuVM/Ubuntu.qcow2 40G

This will create a 40 GB disk image which will be used as the primary disk for the VM that you want to create. Replace 40G with a size of your choice.

Step 4 - Launch ACVM

At this point of time, you already have everything you need:

  1. Qemu is available in the contents of the ACVM app.
  2. Your target disk is created and ready.
  3. You have the ISO file to install the VM from.

Now launch the ACVM app by double-clicking it in Finder. You should see this window:

{% include figure image_path=“/assets/images/posts/ubuntu-focal-on-apple-silicon-m1/acvm-app-ready-to-boot-ubuntu.png” alt=“ACVM app” caption=“ACVM App Main Window - The main image is your target disk image where you want to install Ubuntu and CD image is for the Ubuntu ISO image you downloaded.” %}

Fill in the numbers and start the app:

  1. Enter the number of CPUs and RAM as you would like. I recommend you stick to the defaults of 4 CPUs and 4 GB RAM. They are enough to get started (you can change them later after the VM is installed).
  2. Drag and drop the Ubuntu.qcow2 file you created from Finder to the “Main Image” section.
  3. Darg and drop your ISO file you downloaded into the “CD Image (Optional)” section.
  4. Press “Start” button.

You should see a Window open up:

QEMU Bootup Screen

Qemu Bootup screen

The window should quickly change to this:

Ubuntu Boot Menu via Qemu

Step 5 - Install Ubuntu

I recommend that you choose the “Install Ubuntu” option. While the “Try Ubuntu without installing” works, the window size is a little small for the install window to fit in (I could not increase the resolution in that “Trial” mode to fit the installer window).

Once your installation is over, you should get the Reboot or Continue Testing window in your Ubuntu. I recommend you press the “Continue Testing” button and then “Power Off” the VM from the menu inside your Ubuntu.

NOTE: It is possible that the machine still stays on in a hung state. Press Cmd+Q on your Mac to force close Qemu. There is no harm in it at this point.

Step 6 - Boot up installed Ubuntu

Now you need to boot the machine. Ensure that you are still in the /Applications/ACVM.app/Contents/Resources directory and enter the following command:

./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

NOTES:

  1. Remember to replace the paths in the command above according to where your ACVM app is and where your target disk is.
  2. The line -smp 4,cores=4 asks Qemu to create a 4-core machine. Changing only one of the numbers didn’t work for me. Make sure you match the numbers.
  3. The line -m 4096 represents the amount of memory (RAM) available to the VM in Megabytes. Change according to your needs.
  4. All this hassle to using the ACVM app is to ensure that the line -accel hvf works. If you install qemu via brew, it will not recognise the hvf hypervisor (because it is still not there), which is the Apple’s Virtualisation Framework hypervisor.

This should launch your VM and you should get the following window:

Ubuntu first boot on Apple Silicon M1 via Qemu

Ubuntu starts on Apple Macbook Air M1 via Qemu!

Of course the username will be what you had put in.

NOTE: If you press Control+C on the terminal where you ran the launch command, the machine will die suddenly (as if power was lost). Make sure you shutdown the VM from within the VM window itself (or you can put an & at the end of the command and send it into background when launching the machine).

Result

Ubuntu working successfully on Apple Silicon M1 via Qemu

Ubuntu working successfully on Apple Macbook Air M1 via Qemu!

Problems

Yes, there are problems that you will face even after doing all of that.

  1. Sometimes the VM’s display gets stuck. Going to fullscreen and exiting it helped.
  2. Command key might get mapped to Control inside the VM – this happened with me in the first launch after install and never happened again.
  3. In the same session (the first run after install), the VM behaved as if the Control key was pressed down all the time while the VM was running. This too never happened again.
  4. The resolutions that worked best for me (13-inch MacBook Air) were:
    • 1360×768 – in Windowed mode.
    • 1440×900 – in FullScreen mode.
  5. Running sudo apt update && sudo apt upgrade followed by a reboot solves a number of other problems (which I don’t remember as I am writing this) too.

Summary

Yes, the above mentioned Qemu-based solution is not flawless but it is way better than what I got with Parallel’s Desktop Technical Preview and the VM runs faster with Qemu in my observation as well. While you don’t have the fancy GUIs, Snapshotting feature and launching the VM can be a little verbose, this is the best solution you can have at this time. But then, you can always create good launch scripts to make life easier.

That’s all for now. Hope this post helped you!

PS: Apologies for any typos. I wrote this right after the experiment and staying up all night.