Installing QEMU on macOS
On macOS systems, QEMU must be built from source. Based on the availability of the latest version, I recommend using Homebrew for this purpose.
Please note that I do not have an Apple system on which to test, and Apple goes out of their way to make macOS so that it will not run inside a virtual machine on other systems (nor will they license it for that purpose). Also, Apple sometimes wildly changes internals of the macOS operating system from release to release. Consequently, you may need to do some searching to determine the proper steps for your particular system.
Installing via Homebrew
Follow the instructions at the Homebrew website if you do not already have Homebrew installed. Note that you might need to install Xcode to get Homebrew working.
Once you have Homebrew working, it should be possible to install QEMU using:
brew install qemu
Firmware Files
Firmware files (e.g. for UEFI booting) are located in the share/qemu directory of your installation. This location varies depending upon whether you have an Intel or Apple silicon (Arm-based) Mac.
- On Intel Macs, look under /usr/local/share/qemu for the firmware files.
- On Apple silicon, look under /opt/homebrew/share/qemu for the firmware files.
Optional: Hardware Acceleration
By default, QEMU should work with the “tcg” (Tiny Code Generator) accelerator, which is actually a dynamic recompiler and not an accelerator. For a sufficiently modern host system and a sufficiently lightweight guest system, the performance of this approach might be acceptable. However, increased performance can be realized when virtualizing guests that have the same architecture as the host CPU by using the “hvf” (Hypervisor.Framework) accelerator with QEMU.
Unfortunately, Apple’s slow but steady march toward making macOS a walled garden that can only run approved applications1 creates an additional headache that must be overcome to make hvf available to QEMU. It is necessary to grant the requisite QEMU program (qemu-system-x86_64 on Intel machines, or qemu-system-aarch64 on Apple silicon) permission to use the hypervisor framework. This process is intentionally cumbersome and requires creating an XML file by hand and then running the codesign command.
See this blog post for instructions. Once the framework is enabled, QEMU can be instructed to use it by changing “-accel tcg” to “-accel hvf” when virtualizing a guest system that has the same architecture as the host. Some features have not yet been implemented for HVF acceleration,2 so revert to tcg if you run into problems with a guest.
References and Further Reading
-
Kyle Wagner. Apple Developer IDs Bring Us One Brick Closer to an OS X Walled Garden. Gizmodo. February 27, 2012. ↩
-
QEMU Wiki. Features/HVF. ↩