Virtualizing OS X is a thing that can today be done very easily, with VMware and VirtualBox fully supporting it under OS X hosts. But what about virtualizing it using a bare metal hypervisor and QEMU? Under Linux? Finally I've got Mavericks fully working under QEMU (with no extra kexts(!)) and it wasn't easy.

Credits

Lots of credit for this goes to Gabriel L. Somlo who got the prelimary work for this completed, however I could not get any version of OS X Mavericks to boot from a clean install from his guide, so I adapted it here.

Why?

OS X in the cloud. This was a project for fun to see if I could get OS X virtualized on a dedicated server, and it succeeded! Note this was for educational purposes and it is not recommended - there is no guarantee of stability, and it may be against Apple's EULA.

Requirements

To complete this you will need:

  • Machine capable of running KVM

  • Basic knowledge of a bash shell

  • Mavericks .ISO (generated with this shell script)

  • Mountain Lion .ISO (generated with this shell script)

  • git

  • build-essential (gcc, make, iasl, your linux kernel headers)

The same shell script works for both versions of OS X.

Installing KVM with OS X support

First you need to grab the latest KVM code from their git repo (this is required since the patches for OS X are not shipped with KVM that is in the latest apt or yum repositories). You also need the kvm-kmod code from their git repo, you can get these and build them with the following commands:

Installing the latest QEMU with OS X support

We grab the latest QEMU and latest SeaBIOS which are patched to support OS X from their git repository:

Chameleon bootloader to boot into the installer and OS X

You can install Chameleon to the disk after you have installed OS X but for convenience we can pass a binary file to QEMU to boot chameleon.

Download this binary and put it in the same directory as all the other folders you've just downloaded.

Installing Mountian Lion

Before we can install Mavericks, we must first install Mountian Lion and then do an upgrade (this is due to the fact QEMU will just hang on a clean install of Mavericks).

Make sure you have your Mountain Lion and Mavericks .ISOs in the same directory right now, I'm referring to them from now on as MountainLion.iso and Mavericks.iso.

We now need to create a flat file to install OS X to (dd can be used to copy this to an LVM or partition later but unfortunately I haven't got the installer to boot when a partition is used):

qemu-img create -f qcow2 osx.img 30G

To boot the guest we can use the following command:

You will need to insert a key there which you can retrieve from a Apple Mac computer with the first piece of code here.

You may need to replace the path of ./share/qemu/bios-mac.bin with your own path (this should be in a ./share or ./usr/share to your current path).

This will start up a VNC session on localhost:5901 which you can connect to and boot into the installer!

-smp here defines the number of cores available to the guest. I have used 4 and that functions well, however OS X will quite happily perform fine on just 1 core too.

Install OS X normally and then continue to the next section.

Upgrading to Mavericks

This is pretty much the same as above, start the same guest with the following command:

In Chameleon, make sure to boot to "OS X Base System" (your .iso) and not your HDD. Then install Mavericks as normal to the same partition making sure not the format the partition.

After this you will have a fully working Mavericks system!

No Kexts?

This is a fully native system and requires no kext modifications, not even FakeSMC. I have not tested it with FakeSMC but it should all work.

Networking

Now, the default network driver with QEMU does not work so it is recommeded to use virtio. You can download it with the following command:

Then append the following commands to your above command, start the guest and install the .pkg from the FAT drive that will be mounted and then reboot and networking will work!

Contact

You can contact me at will@will3942.com or @Will3942.

Feel free to join in the discussion on Hacker News here.