macOS is a proprietary graphical operating systems developed by Apple Inc. since 2001. It is the primary OS for Apple’s Mac computers. It is the second most widely used desktop OS, after Microsoft Windows. In this article, we’ll look at how you can run or install macOS on QEMU, accelerated by KVM.

For this setup, we’ll use the macOS-Simple-KVM project code available in Github to run macOS on KVM / QEMU. For you to be able to run macOS on QEMU / KVM, you need a Linux system with qemu, python3, pip and the KVM modules enabled.

Step 1: Environment preparation

Let’s begin by ensuring we have the dependencies installed and service required to run macOS on KVM working.

Ubuntu / Debian based Linux:

sudo apt update
sudo apt -y install qemu-kvm libvirt-daemon qemu-system qemu-utils python3 python3-pip bridge-utils virtinst libvirt-daemon-system virt-manager

Ensure the vhost_net module is loaded and enabled.

$ sudo modprobe vhost_net 
$ lsmod | grep vhost
vhost_net              24576  0
tun                    49152  1 vhost_net
vhost                  49152  1 vhost_net
tap                    28672  1 vhost_net

$ echo vhost_net | sudo teaa -a /etc/modules 

Fedora Linux:

sudo dnf -y install git bridge-utils libvirt virt-install qemu-kvm qemu qemu-img python3 python3-pip virt-manager

Start KVM:

sudo systemctl start libvirtd
sudo systemctl enable libvirtd
sudo dnf -y install virt-manager

After installation, verify that Kernel modules are loaded

$ lsmod | grep kvm
kvm_intel 233472 0
kvm 737280 1 kvm_intel

I recommend you configure virt-manager as a non-root user so you can use it for other purposes without sudo.

Arch Linux / Manjaro:

sudo pacman -S qemu virt-manager virt-viewer dnsmasq vde2 bridge-utils openbsd-netcat python python-pip ebtables iptables

Once the installation is done, start and enable libvirtd service to start at boot:

sudo systemctl enable libvirtd.service
sudo systemctl start  libvirtd.service

Step 2: Download installation media for macOS

Make sure you have git installed.

--- Ubuntu / Debian ---
$ sudo apt -y install git

--- Fedora ---
$ sudo dnf -y install git

Then clone the project code on github.

git clone https://github.com/foxlet/macOS-Simple-KVM.git

Change to the downloaded directory.

cd macOS-Simple-KVM

Run the installer script to download installation media for macOS (internet required).

./jumpstart.sh --catalina

The default installation uses Catalina, but you can choose which version to get by adding either –high-sierra, –mojave, or –catalina.

Sample installation output:

........
dmg2img v1.6.7 (c) vu1tur ([email protected])

/var/home/jkmutai/Downloads/macos/macOS-Simple-KVM/tools/FetchMacOS/BaseSystem/BaseSystem.dmg --> /var/home/jkmutai/Downloads/macos/macOS-Simple-KVM/BaseSystem.img


decompressing:
opening partition 0 ...             100.00%  ok
opening partition 1 ...             100.00%  ok
opening partition 2 ...             100.00%  ok
opening partition 3 ...             100.00%  ok
opening partition 4 ...             100.00%  ok
opening partition 5 ...             100.00%  ok
opening partition 6 ...             100.00%  ok
opening partition 7 ...             100.00%  ok

Archive successfully decompressed as /var/home/jkmutai/Downloads/macos/macOS-Simple-KVM/BaseSystem.img

The directory will contents like this:

$ ls -l
total 2.1G
-rw-------. 1 jkmutai jkmutai 2.0G Mar 20 17:15 BaseSystem.img
-rwx------. 1 jkmutai jkmutai 1.1K Mar 20 17:10 basic.sh
drwx------. 2 jkmutai jkmutai 4.0K Mar 20 17:10 docs
-rw-------. 1 jkmutai jkmutai  13M Mar 20 17:10 ESP.qcow2
drwx------. 2 jkmutai jkmutai 4.0K Mar 20 17:10 firmware
-rwx------. 1 jkmutai jkmutai 1.5K Mar 20 17:10 headless.sh
-rwx------. 1 jkmutai jkmutai  874 Mar 20 17:10 jumpstart.sh
-rwx------. 1 jkmutai jkmutai  732 Mar 20 17:10 make.sh
-rw-------. 1 jkmutai jkmutai 3.0K Mar 20 17:10 README.md
drwx------. 4 jkmutai jkmutai 4.0K Mar 20 17:10 tools
-rwx------. 1 jkmutai jkmutai  946 Mar 20 17:10 virtio.sh

Step 3: Start machine and install macOS

We need to create an empty hard disk for macOS system using qemu-img.

$ qemu-img create -f qcow2 macOS.qcow2 50G
Formatting 'macOS.qcow2', fmt=qcow2 size=53687091200 cluster_size=65536 lazy_refcounts=off refcount_bits=16

Modify the basic.sh file and add below lines to the end.

-drive id=SystemDisk,if=none,file=macOS.qcow2 
-device ide-hd,bus=sata.4,drive=SystemDisk 

We can now run the command:

./basic.sh 

Click on macOS icon to install macOS Base System.

<img alt="" data-ezsrc="https://kirelos.com/wp-content/uploads/2020/03/echo/install-macos-on-qemu-kvm-01-1024×492.png" data-ez ezimgfmt="rs rscb8 src ng ngcb8 srcset" src="data:image/svg xml,”>

The installer will start in a few seconds.

<img alt="" data-ezsrc="https://kirelos.com/wp-content/uploads/2020/03/echo/install-macos-on-qemu-kvm-02-1024×561.png" data-ez ezimgfmt="rs rscb8 src ng ngcb8 srcset" src="data:image/svg xml,”>

Select “Disk Utility” in the next screen.

<img alt="" data-ezsrc="https://kirelos.com/wp-content/uploads/2020/03/echo/install-macos-on-qemu-kvm-03.png" data-ez ezimgfmt="rs rscb8 src ng ngcb8 srcset" src="data:image/svg xml,”>

Format the disk you had created for installing macOS base system.

<img alt="" data-ezsrc="https://kirelos.com/wp-content/uploads/2020/03/echo/install-macos-on-qemu-kvm-04-1024×484.png" data-ez ezimgfmt="rs rscb8 src ng ngcb8 srcset" src="data:image/svg xml,”>

The disk should show size and partition type after formating.

<img alt="" data-ezsrc="https://kirelos.com/wp-content/uploads/2020/03/echo/install-macos-on-qemu-kvm-05-1024×546.png" data-ez ezimgfmt="rs rscb8 src ng ngcb8 srcset" src="data:image/svg xml,”>

Close Disk utility and choose “Reinstall macOS“.

<img alt="" data-ezsrc="https://kirelos.com/wp-content/uploads/2020/03/echo/install-macos-on-qemu-kvm-06.png" data-ez ezimgfmt="rs rscb8 src ng ngcb8 srcset" src="data:image/svg xml,”>

Confirm OS installation by hitting the “Continue” button.

<img alt="" data-ezsrc="https://kirelos.com/wp-content/uploads/2020/03/echo/install-macos-on-qemu-kvm-07-1024×757.png" data-ez ezimgfmt="rs rscb8 src ng ngcb8 srcset" src="data:image/svg xml,”>

Select the disk partitioned previously.

<img alt="" data-ezsrc="https://kirelos.com/wp-content/uploads/2020/03/echo/install-macos-on-qemu-kvm-08-1024×723.png" data-ez ezimgfmt="rs rscb8 src ng ngcb8 srcset" src="data:image/svg xml,”>

Be patient as the installation starts – it may take a long time depending on the internet speed.

<img alt="" data-ezsrc="https://kirelos.com/wp-content/uploads/2020/03/echo/install-macos-on-qemu-kvm-09.png" data-ez ezimgfmt="rs rscb8 src ng ngcb8 srcset" src="data:image/svg xml,”>

Step 4: Import the setup into Virt-Manager

Instead of QEMU, you’d like to import the setup into Virt-Manager for further configuration, just run:

sudo ./make.sh --add

After running the command above, add macOS.qcow2 as storage in the properties of the newly added entry for VM.

To fine-tune the system and improve performance, read the projects docs for more information. Here are the direct links.

We will be uploading more content on macOS and its administration. Check more guides to check out.

Run Ansible Playbook with Vagrant up

How To Optimize Linux System Performance with tuned-adm

Best Linux Books for Beginners & Experts

Install / Run Fedora CoreOS (FCOS) on KVM / OpenStack