Howto: Mac OSX on KVM

From d4wiki

Jump to: navigation, search

This tutorial shows the steps to run a Mac OSX guest under KVM (Kernel-based Virtual Machine) on a Linux System.

If your distribution is an openSUSE 11.0 (IIRC) or later, you have only to install kvm package.

Otherwise you have to follow this tutorial to build and run latest pacthed KVM version.


Special Thanks

To Alexander Graf ( ) Author of Virtualizing an x86 Mac OS X Project and of all KVM patches that make this possible.


Warning: " The author of this guide assumes no responsibility for anything done with this document, nor does he make any warranty, implied or explicit. If you break it, it's not my fault. "

Basic Rules:

  1. BACKUP EVERYTHING, before TRYING ANYTHING. If it's important you definitely don't want to lose it.
  2. Read the MANUAL PAGES for the commands you are going to use, to make sure that I haven't made a mistake.
  3. BEFORE you hit enter, make sure the commands you type MAKES SENSE.


(from Alexander Graf site)

While the EULA clearly states, that running Mac OS X only once and only on Apple hardware is allowed, this does not exclude running it legally in a virtual machine on Apple hardware. This is basically the same approach that Mac-on-Linux took, but this time with the Intel based version of Mac OS X. Of course, as all the hardware Mac OS X runs on with this solution is virtual, the very same approach enables potential users to run it on non-Apple hardware as well, which is illegal though.


Tutorial Environment:
Gentoo 2.6.34 amd64 Kernel

PreBuild Instructions

Build Package Requirements (Debian/Ubuntu) :

sudo apt-get install rpm zlib1g-dev libasound2-dev libpulse-dev libsdl1.2-dev dev86 iasl quilt

Download the latest version of KVM Sources pacthed for OSX at the url:

Go to the directory where you downloaded the .rpm file.

mkdir kvm-src
cd kvm-src

Unpack rpm files.

rpm2cpio ../kvm-*.src.rpm | cpio -id
tar xvvjf qemu-kvm-*.tar.bz2

PrePatch Instructions

For Suse distribution:

quilt -v setup kvm.spec
cd kvm-*/
cp -a bios bios-mac

For NOT Suse distribution:

Modify kvm.spec if you have a distribution different from Suse:

You can edit this manually,

Copy it:

cp kvm.spec kvm_nosuse.spec

and add this line somewhere at the beginning of the kvm_nosuse.spec file:

%define suse_version 1120

and comment out the %suse_kernel_module_package line (if exists):


ore you can do the same by this command:

cat kvm.spec | sed '/Name:/ i\
%define suse_version 1120
'| sed 's/%suse_kernel_module_package/#%suse_kernel_module_package/' > kvm_nosuse.spec

Prepare patches:

quilt -v setup kvm_nosuse.spec

Change directory:

cd qemu-kvm-*/

Copy bios directory:

cp -a kvm/bios kvm/bios-mac

Patch Instructions

Apply The pacthes

quilt push -a -v

Build Instructions

Compile it:


Compile bios-mac:

cd kvm/bios-mac
cd ../..

Install Instructions

Install Official KVM package (optional):

sudo apt-get install kvm

Install new KVM module:

sudo make install

Load new KVM module:

sudo modprobe kvm_intel (or kvm_amd)

Copy MAC BIOS in the correct location:

sudo cp kvm/bios-mac/BIOS-bochs-latest /usr/local/share/qemu-kvm/bios-mac.bin

Download the bootloader:

cd ~
mkdir kvm-osx-bootloader
cd kvm-osx-bootloader
cd ~

Start Up Instructions

If you don't have a OSX partition, you can create a disk image file to use as HD device. Mac OSX Leopard Installation requires at least 11,4 GB free space to setup, more spaces (5,5 GB) are needed for current updates, so the image file for MAC OSX setup should be at least 20 GB.

qemu-img create -f qcow2 $MY_DISK_IMAGE_FILE 20G

Mac OSX contains a binary protection, this means that OSX checks for an hardware key (contained in a dongle on apple machines) to correctly execute itself and the other application. KVM has to emulate that dongle so you have to supply your hardware key. To find your hardware key you can use the getkey script ( from Alexander Graf site or look for OSK0 and OSK1 on google. KVM needs this key as a human-readable ASCII string of 64 chars in -osk parameter.

For OpenSuse:


On Other systems:


Start Mac OSX:

$QEMU_BIN -M mac -kernel ~/kvm-osx-bootloader/boot \
-usb -usbdevice mouse -usbdevice keyboard -hda $MY_DISK_IMAGE_FILE \
-cdrom /dev/cdrom -m 512 -osk $HARDWARE_KEY -serial stdio

To boot from cdrom (useful for OSX setup) you have to press "any key" immediately on BOOT screen and then write down "e0" as hexadecimal boot device code.

Debug Options:
Hit F8 immediately at OSX boot to select kernel options.
You could add "-v" option for verbose mode and "debug=0x8 serial=0x3" for extra debug output.

Personal tools