Virtualization

How To run macOS on KVM / QEMU

Environment preparation

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

Original content from computingforgeeks.com - post 49107

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 tee-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

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

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.

install macos on qemu kvm 01

The installer will start in a few seconds.

install macos on qemu kvm 02

Select “Disk Utility” in the next screen.

install macos on qemu kvm 03

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

install macos on qemu kvm 04

The disk should show size and partition type after formating.

install macos on qemu kvm 05

Close Disk utility and choose “Reinstall macOS“.

install macos on qemu kvm 06

Confirm OS installation by hitting the “Continue” button.

install macos on qemu kvm 07

Select the disk partitioned previously.

install macos on qemu kvm 08

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

install macos on qemu kvm 09

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.

Related Articles

Virtualization How To Create a Linux Network Bridge on RHEL 8 / CentOS 8 Virtualization How To Install VirtualBox 7.0 on Kali Linux / Linux Mint Featured Using Emacs on Linux and macOS – emac Commands examples Virtualization Enable Hyper-V and Install Vagrant on Windows 11/10

34 thoughts on “How To run macOS on KVM / QEMU”

  1. thanks for the time and effort in the project. when i get to install mac os step , the block for choosing the installation media drive it says.. “this drive is locked”. where have i gone wrong? thanks again

    Reply
  2. Hello, thank you for the great tutorial. I’ve used it many times but I haven’t had any luck adding the setup into Virtual Manager. Is there any way you can elaborate a bit more on the procedure? After creating the make.sh and going into Virt-Man I do see the entry KVM MacOS and get lost at that point. When I click Play it doesn’t go to the MacOs I just installed. It goes straight into the INSTALL macos again. I’m trying to get my idevices recognized on MacOS and there’s no way to get USB passthrough unless I get this setup into the Virt-Man to enable the USB redirect. Appreciate the help. Thank you kindly.

    Reply
    • I believe this is because you haven’t replaced the entry in the VM config with the file we just created for the VM’s HDD. I’m working on this step now.

      Reply
    • You need to reattach the qcow2 image from your install to the .xml. You can do this by adding the qcow storage like you would another qcow image in virt-man. Then, once the qcow image is re-associated to the qemu domain. you can choose to boot from it.

      Reply
  3. when i run the command ./basic.sh it says
    qemu-system-x86_64: -drive: requires an argument
    ./basic.sh: line 29: -device: command not found

    Reply
  4. For anyone confused on how to get from running ./basic.sh to the graphical installer, you need to open a vnc viewer and connect to localhost on port 5900

    Reply
  5. When I type ./basic.sh it says this: Could not access KVM kernel module: Permission denied
    failed to initialize KVM: Permission denied please help

    Reply
  6. Hello and thanks for sharing this tutorial. I’d like to say that I made MacOS X Catalina work pretty easily over Elementary OS 5.1.7 Hera. Actually, the main downside is that I experience a notable lag in general when using the system. I’m not a dev, but it seems that is related to graphics. Do you have any idea about that or it’s just the way Mac Os work over a virtual machine? Thanks!

    Reply
    • You need to passthrough a GPU to get acceleration to work. There is a link at the bottom of the article for it, or I’m sure Simple-KVM’s github documentation covers it. If not, reddit and other threads will most likely be able to help you too on their VT threads.

      I’m gonna setup my dads machine as a VM (Arch distro > Simple-KVM MacOs Catalina). So I’ll be doing a GPU passthrough then, but I got a native GPU (Geforce 710 1GB) to avoid driver issues in Mac OS. Until then I’m of little help, but feel free to ask. I’ve set up multiple hackintoshes and one ran without any issues feeling like a true Mac

      Reply
  7. After booting the OS by adding new disk as SAS from Virtual Machine manager. It is stuck at apple logo and a progress bar showing estimating time remaining from the past 2 hours.

    Reply
  8. Thanks for this write-up. It worked like a champ for me. Now…..how do I share my host wireless printer to my new MacOS VM?

    Reply
  9. I get stuck at Reinstall macOS where it says recovery server could not be contacted
    Im using virt-manager and installing mojave

    Reply
  10. Forgive my ignorance as I am a newbee at Terminal at the virtual machine “stuff”. I am using a 27″ iMac (2020) that came with Catalina (64 bit) pre-installed but also dual booting into Windows 10 via Bootcamp. I am trying to get Mojave (32 bit) installed on it somehow with either a virtual machine (VM) or as an extra partition. I have 32 bit software that I need to use and I already tried Parallels Desktop for Mac but it keeps on crashing the software. I also tried Virtual Box but the script hangs and does not get to the installation interface for macOS. I also tried installing Ubuntu but for some reason I was unsuccessful. I don’t know much about Terminal but I can obviously follow instructions on what command lines to paste. I searched the Web for watched many YouTube clips but nothing solves my quest yet. Within Terminal, it says the Brew is installed but what do I do next? After finding you Instruction, I thought the process may work. My Terminal menu bar says: -zsh. Do I need to change that? Does your method allow for triple booting? And how do I achieve that? Any feedback would be much appreciated.

    Reply
  11. This also happened to me. After running basic.sh, the mouse and keyboard on the guest are not working. The mouse completely disappears if I try to click in the VM. Then I have to Ctl-Alt-G to get it back

    Reply
  12. Having a bit of trouble with this, was wondering if you could suggest a fix. When I attempt to use “basic.sh” to launch the VM directly it works, but the network configuration doesn’t take for some reason so the “reinstall” step fails because it can’t reach the update servers.

    I’ve been a user of Virtual Machine Manager and libvirt on Fedora for many years and I have dozens of other machines running successfully, but when I attempt to import this one via XML and start it wither with Virt Manager or with virsh it fails with a “Permission Denied” error when trying to read the firmware files. It’s definitely not a file access issue because I’ve verified my qemu user can see and access the file – even going as far as to setting 777 access modes on them. I’m missing something but not quite sure what.

    Reply
  13. Hi !
    Thanks for this article.

    I have a problem, and I don’t see the answer.
    When I finished all the steps with no mistakes. I write : “./basic.sh”
    And the error is :
    “Unable to init server: Could not connect : Connection refused
    gtk initalization failed”

    I did some search, and the reason is I don’t have the graphical interface. But when I install this, the virtual machine doesn’t work well because I have one graphic card.

    Have you any ideas to solve my problem ?

    Thanks

    Reply
  14. For a future reader: I found that 50G is too small for a Catalina -> Ventura update. I ended up recreating my VM with 128G to avoid issues.

    Reply
  15. I have a problem, and I don’t see the answer.
    When I finished all the steps with no mistakes. I write : “./basic.sh”
    And the error is :
    “Unable to init server: Could not connect : Connection refused
    gtk initalization failed”

    Have you any ideas to solve this problem ? I have virt-manager on a Linux system, QEMU KVM on another… your jumpstart script assume a local QEMU/KVM instance, correct?

    Reply
  16. Ah! If you have virt-manager on a different system than the hypervisor, run:

    $ sudo ./make.sh –add

    This will import VM domain (XML) file into virt-manager (via the hypervisor system).

    Reply
  17. I got it setup and seems to be working ok! (Got it running using my Arch install). I do have a few questions though. Does anyone else have weird mouse issues with this? It’s almost like the mouse pointer doesn’t align when it captures it. (Hard to explain). Looking at the ‘Readme’ file in the folder, it mentions you can set this up ‘headless’. Has anyone tried that using a VPS / Cloud computing or something similar? If I want to start the Mac VM again, do I just run the ./basic.sh command, and choose the mac partition? That’s how I did it but, not sure if that’s the proper way. Thanks

    Reply

Leave a Comment

Press ESC to close