This tutorial will show you how to create a Ubuntu Desktop 18.04 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.
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:
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.
Select your language and keyboard layout.
Select Minimal installation and then click Continue.
Select Erase disk and install Ubuntu then click Install Now.
Specify your username, machine name and password then click Continue.
Wait for the installation to complete then click Restart Now.
When asked to remove the installation medium, power off the machine and in the next step we’ll adjust the command to power on the VM without the CD-ROM attached.
Step 7: Reboot without Ubuntu ISO attached
Once the machine is powered off. Remove the following line from the start.sh script:
-cdrom ubuntu-18.04.3-desktop-amd64.iso \
Ubuntu should now be installed and it should run fast on macOS since we enabled hardware acceleration by specifying the -accel hvf option.
On first boot after installing Ubuntu, the screen resolution might be too low. Right click on the desktop and open a terminal then run sudo apt update and sudo apt upgrade to install updates. Restart the system and the screen should then be big enough to increase the resolution in the Devices section of settings. 1440x900 works best for my MacBook Pro (2017 13.3-inch 2560 x 1600).
If you need to SSH onto the system, you can add the following settings to the QEMU command: -net user,hostfwd=tcp::2222-:22 -net nic. Then you can connect via ssh user@loclhost -p 2222.
You can enter and leave full screen by pressing Command + F when the mouse cursor is at the very top of the screen.