Using QEMU on x86_64 macOS

Setting up a virtual machine (VM) on Linux using open source software is the standard way of doing things, but on macOS it usually involves VMware Fusion or Boot Camp. QEMU is my favorite hypervisor and wanted to use it when I have to use macOS as well.

First, install a package manager like brew, then run brew install qemu.

On Linux, QEMU is typically used in conjunction with the KVM framework. This is a Linux kernel specific framework that is not implemented on macOS, but it has a somewhat functionally equivalent called Hypervisor.Framework, which is implemented using the hvf code from Veertu Inc.[1] This can be used using the following flag: -accel=hvf. It is missing some features, as documented on the QEMU wiki[2]

Sharing files (but not clipboard)

For exchanging files, support for 9p file system was packaged in 2022 for Homebrew[3], so we can use this for exchanging files between the host and the guest operating system using the following configuration:

mount -t 9p -o trans=virtio Downloads /tmp/shared -oversion=9p2000.L,poxiacl,msize=104857600,cache=none

Ideally, this should be done using an entry in /etc/fstab

Clipboard sharing would be convient but I have disabled this for security reasons because my personal purpose for this VM is CTF usage and running untrusted binaries. I use a shared file as a clipboard, which works fine for me personally.

Networking

Somehow I was unable to get bridged networking interfaces working, but I have not debugged this problem in depth. Using an adapter with NAT, accessing the internet works fine. This is done using the following flag: -nic vmnet-shared,ifname=em0

Keyboard

On a macOS keyboard, the titlebar of QEMU VMs are a bit confusing. It says “press ctrl + alt + g to release Mouse”, but in practice this is control + option + g. Using a Linux VM on a MacBook is still very confusing to me when it comes to shortcuts.

[1] https://github.com/qemu/qemu/tree/40eab4d95939c47f5bf6e664868c172090856244/target/i386/hvf

[2] https://wiki.qemu.org/Features/HVF

[3] https://github.com/Homebrew/homebrew-core/commit/a70f2f6967e4459a921a947ab5060d3af8034853