This tutorial will show you how to create a Ubuntu Desktop virtual machine and run it on macOS with QEMU and hardware acceleration.
Before we begin, I suggest you create a folder on your Mac to store the virtual machine disk image, the Ubuntu ISO and startup script. You don’t have to do this but it will make following this tutorial easier.
I’ll be storing everything in
Step 1: Install QEMU
We’re gonna use Homebrew to install QEMU, so if you haven’t got Homebrew installed on your machine. You’ll need to do that first by following the Homebrew installation guide.
With Homebrew installed, run the following command to install QEMU.
brew install qemu
Once the install is finished, run the following command to make sure QEMU is installed and ready for the next steps:
QEMU emulator version 6.2.0 Copyright (c) 2003-2021 Fabrice Bellard and the QEMU Project developers
As you can see, as of writing, the latest version is 6.2.0
Step 2: Download Ubuntu ISO
Go to the Ubuntu website and download the Ubuntu Desktop ISO. Move the ISO to the
~/QEMU folder as it will make the QEMU command easier.
Step 3: Create a Disk Image
Run the following command to create an 10 GB hard disk (or adjust to your needs) for the virtual machine.
qemu-img create -f qcow2 ~/QEMU/ubuntu-desktop-18.04.qcow2 10G
You should now have a folder containing the Ubuntu ISO and the hard disk which Ubuntu will be installed on.
ls -l ~/QEMU/ ubuntu-18.04.3-desktop-amd64.iso ubuntu-desktop-18.04.qcow2
Step 4: Create a start script
Add the following contents to
qemu-system-x86_64 \ -m 8G \ -vga virtio \ -display default,show-cursor=on \ -usb \ -device usb-tablet \ -machine type=q35,accel=hvf \ -smp 2 \ -cdrom ubuntu-18.04.3-desktop-amd64.iso \ -drive file=ubuntu-desktop-18.04.qcow2,if=virtio \ -cpu host
Note: you might need to change the
-cpu option to a model that matches your hardware. Run
sysctl -n machdep.cpu.brand_string to see what CPU you have in your machine and
qemu-system-x86_64 -cpu help to see a list of supported options that can be specified to QEMU.
Step 5: Launch QEMU with Ubuntu ISO attached
Run the following command to launch a QEMU virtual machine with the Ubuntu ISO and hard disk we created in the previous step attached.
Change into the
QEMU directory and make the script executable:
cd ~/QEMU sudo chmod +x start.sh
Run the script:
Step 6: Install Ubuntu
Hopefully if everything went to plan with the above command you should be presented with the Ubuntu installer. Click on Install Ubuntu.