Howto: Mac OSX on KVM
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.
To Alexander Graf ( http://alex.csgraf.de/ ) Author of Virtualizing an x86 Mac OS X Project and of all KVM patches that make this possible.
- BACKUP EVERYTHING, before TRYING ANYTHING. If it's important you definitely don't want to lose it.
- Read the MANUAL PAGES for the commands you are going to use, to make sure that I haven't made a mistake.
- 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.
Gentoo 2.6.34 amd64 Kernel
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: http://download.opensuse.org/repositories/Virtualization:/KVM/openSUSE_Factory/src/
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
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,
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
quilt -v setup kvm_nosuse.spec
Copy bios directory:
cp -a kvm/bios kvm/bios-mac
Apply The pacthes
quilt push -a -v
cd kvm/bios-mac make cd ../..
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 wget http://alex.csgraf.de/qemu/boot 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 (http://alex.csgraf.de/qemu/getkey) 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.
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.
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.