Ubuntu 22.04.6 | QEMU KVM installation macOS virtual machine

Reference https://github.com/kholia/OSX-KVM

Update software source

sudo apt-get update

Environmental requirements

  1. A modern Linux distribution. E.g. Ubuntu 22.04 LTS 64-bit or later.
  2. QEMU >= 6.2.0
  3. A CPU with Intel VT-x / AMD SVM support is required (grep -e vmx -e svm /proc/cpuinfo)
  4. A CPU with SSE4.1 support is required for >= macOS Sierra
  5. A CPU with AVX2 support is required for >= macOS Mojave

Install required software packages

  1. Install QEMU and other packages.
sudo apt-get install qemu uml-utilities virt-manager git \
    wget libguestfs-tools p7zip-full make dmg2img tesseract-ocr \
    tesseract-ocr-eng genisoimage -y
  1. Clone OSX-KVM code (virtual machine running macOS)
    First enter the current user directory
cd ~

Then clone the repository code
Overseas (Choose one of the two)

git clone --depth 1 --recursive https://github.com/y141111/OSX-KVM.git

Domestic (Choose one of the two)

git clone --depth 1 --recursive https://gitee.com/y141111/OSX-KVM.git

Enter the cloned code directory

cd OSX-KVM
  1. Get the macOS installation package
./fetch-macOS-v2.py

Convert downloaded dmg file to img file

dmg2img -i BaseSystem.dmg BaseSystem.img

Create a virtual hard disk image into which macOS will be installed. If you change the name of the disk image from to something else, the boot script will need to be updated to point to the new image name. mac_hdd_ng.img

qemu-img create -f qcow2 mac_hdd_ng.img 128G

Installation

  • CLI methods (mainly). Simply run the script to start the installation process. OpenCore-Boot.sh
./OpenCore-Boot.sh

NOTE: This script works on all latest macOS versions.

  • Use the tools in the macOS installer to partition and format the virtual disk attached to the macOS virtual machine. Disk Utility

  • Go ahead and install macOS

  • Tip: It is recommended to use a non-APFS file system.

  • (Optional) Use this macOS VM disk with libvirt (virt-manager/virsh stuff).

    • Edit the macOS-libvirt-Catalina.xml file and change various file paths (search for the CHANGEME string in the file)
      sed "s/CHANGEME/$ USER/g" macOS-libvirt-Catalina.xml > macOS.xml
      virt-xml-validate macOS.xml
      
    • Create the VM by running the following command.
      virsh --connect qemu:///system define macOS.xml
      
    • If needed, grant the necessary permissions to the libvirt-qemu user,
      sudo setfacl -m u:libvirt-qemu:rx /home/$USER
      sudo setfacl -R -m u:libvirt-qemu:rx /home/$USER/OSX-KVM
      
    • Start virt-manager and start the macOS virtual machine.

Headless macOS

Use the provided boot-macOS-headless.sh script.

./boot-macOS-headless.sh

Setting Expectations Right

Nice job on setting up a Virtual Hackintoshsystem! Such a system can be used for a variety of purposes (e.g. software builds, testing, reversing work), and it may be all you need, along with some tweaks documented in this repository.

However, such a system lacks graphical acceleration, a reliable sound sub-system, USB 3 functionality and other similar things. To enable these things, take a look at our notes. We would like to resume our testing and documentation work around this area. Please reach out to us if you are able to fund this area of work.

It is possible to have beyond-native-apple-hw’ performance but it does require work, patience, and a bit of luck (perhaps?).

Post-Installation

  • See networking notes on how to setup networking in your VM, outbound and also inbound for remote access to your VM via SSH, VNC, etc.

  • To passthrough GPUs and other devices, see these notes.

  • Need a different resolution? Check out the notes included in this repository.

  • Trouble with iMessage? Check out the notes included in this repository.

  • Highly recommended macOS tweaks – https://github.com/sickcodes/osx-optimizer

Is This Legal?

The “secret” Apple OSK string is widely available on the Internet. It is also included in a public court document available here. I am not a lawyer but it seems that Apple’s attempt(s) to get the OSK string treated as a trade secret did not work out. Due to these reasons, the OSK string is freely included in this repository.

Please review the Legality of Hackintoshing’ documentation bits from Dortania’s OpenCore Install Guide.

Gabriel Somlo also has some thoughts on the legal aspects involved in running macOS under QEMU/KVM.

You may also find this Announcing Amazon EC2 Mac instances for macOS’ article interesting.

Note: It is your responsibility to understand, and accept (or not accept) the Apple EULA.

Note: This is not legal advice, so please make the proper assessments yourself and discuss with your lawyers if you have any concerns (Text credit: Dortania)

Motivation

My aim is to enable macOS based educational tasks, builds + testing, kernel debugging, reversing, and macOS security research in an easy, reproducible manner without getting invested’ in Apple’s closed ecosystem (too heavily).

These Virtual Hackintoshsystems are not intended to replace the genuine physical macOS systems.

Personally speaking, this repository has been a way for me to ‘exit’ the Apple ecosystem. It has helped me to test and compare the interoperability of Canon CanoScan LiDE 120scanner, and Brother HL- 2250DNlaser printer. And these devices now work decently enough on modern versions of Ubuntu (Yay for free software). Also, a long time back, I had to completely wipe my (then) brand new MacBook Pro (Retina, 15-inch, Late 2013)and install Xubuntu on it – as the OS X kernel kept crashing on it!

Backstory: I was a (poor) student in Canada in a previous life and Apple made my work on cracking Apple Keychains a lot harder than it needed to be. This is how I got interested in Hackintosh systems.