libvirt
and QEMU
three years ago when I wrote a guide on how to virtualize macOS on a Linux system. Today I will be showing the opposite, virtualizing Linux on macOS using the same tools. I was surprised that with so many software developers using MacBooks everyday, nobody has created a guide on how to use libvirt
and QEMU
with macOS.libvirt
and QEMU
better? First of all, it's free and open-source. Unlike Parallels Desktop and VMWare Fusion, you won't need to pay for expensive subscriptions or manage licenses. There does exist an open-source alternative (from Oracle!) called VirtualBox, which works pretty well. However, VirtualBox does not support macOS's Hypervisor.Framework, a virtualization API created to limit kernel modification. This means the installer will ask for admin access to install kernel extensions, a feature Apple is now phasing out for security reasons. QEMU
on the other hand has had support for Hypervisor.Framework since 2018. Just say no to kexts!libvirt
, VMs start headless. Plus, when you shutdown macOS, it sends a shutdown signal to your VMs as well.brew install qemu gcc libvirt
.brew services start libvirt
. It will start after boot as well.vms
folder in your home directory, and generate a disk image. Change 50g
to the size of your prefered disk:ubuntu.xml
file to match your your VM preferences and file paths. Save, then run virsh define ubuntu.xml
followed by virsh start ubuntu
.localhost
. Click the Ctrl+Alt+Del
button to reboot the machine, and quickly press Esc
to get into the boot menu. Press the number that matches the Ubuntu Server image.ssh -p 2222 user@localhost
.virsh shutdown ubuntu
. To force shutdown, run virsh destroy ubuntu
.ssh -p 2222 -L8443:localhost:443 user@localhost
hostfwd
argument so that each VM exposes a different port for SSH, e.g. 2223
instead of 2222
. After you have defined them all, you can get a list of the VMs that are currently running with virsh list
.