Virtual Machines on MacOS With QEMU — Intel based

Oliver Mascarenhas
Code Uncomplicated
Published in
3 min readDec 12, 2022

--

A guide on using QEMU on MacOS to run Virtual Machines

Source: https://www.flickr.com/photos/sandialabs/4155733531/in/photostream/

TL;DR

Commands available here: https://github.com/oliversavio/youtube-vid-code/tree/main/qemu-virtual-machines-macos

For the longest time, my go-to tool for spinning up Virtual Machines (VMs) has been VirtualBox. Yes, it works, but it can be a bit fiddly at times.

Then I came across QEMU, which runs as a command-line application and performed exceptionally well. This is achieved in part due to KVM (Kernel-based Virtual Machine) an open source virtualisation technology that’s built into linux.

QEMU announced support for Apple’s Hypervisor framework (HVF), this enables VMs to run on MacOS with near native performance.

Checkout the Demo in the video below

How to Run a Linux Virtual Machine on MacOS With QEMU

Installing QEMU

The easiest way to install QEMU on MacOS is via HomeBrew or MacPorts.

# Homebrew
brew install qemu

# MacPorts
sudo port install qemu

Create a virtual disk image

Create a virtual disk image onto which the OS will be installed. This is done using the qemu-img command. The format of the disk image is qcow2 and the size of the disk is 15 GB .

qemu-img create -f qcow2 mydisk.qcow2 15G

Install the OS

Now that the virtual disk is ready, the next step is to install the operating system onto it. Since this guide is for Intel based Macs, the command used is qemu-system-x86_64 . The -m and -smp switches specify how much memory and cpu on the host is to be reserved for the guest VM.-cdrom points to the iso image of the operating system that will be installed on the VM and -drive points to the virtual disk created in the first step. The rest of the switches should be left as is.

qemu-system-x86_64 \
-m 8G \
-smp 6 \
-cdrom /Volumes/Samsung_T5/iso/Fedora-Workstation-Live-x86_64-35-1.2.iso \
-drive file=mydisk.qcow2,if=virtio \
-vga virtio \
-display default,show-cursor=on \
-usb \
-device usb-tablet \
-cpu host \
-machine type=q35,accel=hvf \

Once executed, the iso should boot-up. Follow the setup wizard of the OS being installed to complete the installation.

Run the Virtual Machine

Once the setup is done, the virtual machine is ready. The command is similar to the one above, except the -cdrom switch, which is no longer needed.

A point to note is the -machine switch with specifies accel=hvf , this tells qemu to run with Apple’s Hypervisor Framework based acceleration which is responsible for the near native perfomance.

qemu-system-x86_64 \
-m 8G \
-smp 6 \
-drive file=mydisk.qcow2,if=virtio \
-vga virtio \
-display default,show-cursor=on \
-usb \
-device usb-tablet \
-cpu host \
-machine type=q35,accel=hvf

UTM — A GUI based alternative

If using the command line is not something you’re comfortable with, check out UTM. It’s a GUI built around QEMU.

I believe, it also supports running VMs on Apple Silicon based machines, however that’s not something I have tried.

Reference & Links

Support

--

--

Oliver Mascarenhas
Code Uncomplicated

Designing and developing scalable and fault tolerant data pipelines and platforms | https://olivermascarenhas.com/