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.
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 5.1.0
Copyright (c) 2003-2020 Fabrice Bellard and the QEMU Project developers
As you can see, as of writing, the latest version is 5.1.0
Step 2: Download Ubuntu ISO
Go to the Ubuntu website and download the Ubuntu Desktop 18.04 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.Advertisements
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/
Step 4: Create a start script
Add the following contents to
-m 4G \
-vga virtio \
-display default,show-cursor=on \
-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 \
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
-cdrom ubuntu-18.04.3-desktop-amd64.iso \
Note: You can increase or decrease the memory with the -m option. The command above assigns 2 GB to the virtual machine.
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 updateand
sudo apt upgradeto install updates. Restart the system and the screen should then be big enough to increase the resolution in the Devices section of settings. 1440×900 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.
David Miller is a seasoned tech aficionado with a profound expertise in NGINX and Ubuntu. With a career spanning over a decade, David has honed his skills in optimizing web servers and enhancing server performance to perfection. His deep-rooted passion for open-source technologies has led him to become a go-to resource in the field. Whether it’s crafting intricate NGINX configurations or troubleshooting complex Ubuntu server issues, David’s problem-solving prowess shines through.