Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gordonturner/2a2e5ecde5e7860b52e2 to your computer and use it in GitHub Desktop.
Save gordonturner/2a2e5ecde5e7860b52e2 to your computer and use it in GitHub Desktop.

KVM OSX Guest 10.11 (El Capitan) with Clover

  • Ubuntu 15.10
  • kvm and qemu packages installed
  • VM images and resources in /vm/

Step 1 OVMF

  • On Linux kvm host, download OVMF:

http://www.tianocore.org/ovmf/

  • Create an OVMF BIOS directory for OSX:
sudo mkdir /vm/osx-ovmf-bios
sudo mv ~/Downloads/OVMF.fd /vm/osx-ovmf-bios/bios.bin

Step 2 Get Apple SMC osk Value

Step 3 Create Install USB Drive

  • On an Apple computer running OS X, create install USB drive.

  • Run Disk Utilty

  • Select the USB device (not a partition of the device) in the left pane

  • If on 10.11 or later:

    • Click Partition tab, ensure there is a single partition
    • Set Name to Untitled, Format to OS X Extended (Journaled)
    • Click Apply button
    • Confirm Partition Map is set to GUID Partition Map
  • If on 10.10 or earler, confirm Partition Map is set to GUID Partition Map

    • Click Partition tab
    • In Partition Layout, select 1 Partition in the
    • Click Options button, select GUID Partition Table, click OK
    • Change Name to Untitled
    • Change Format type to Mac OS Extended (Journaled)
    • Click Apply, then Partition
  • Once partitioning is complete, click Done

  • Close Disk Utility

  • For El Capitan, default Application location:

sudo /Applications/Install\ OS\ X\ El\ Capitan.app/Contents/Resources/createinstallmedia \
--volume /Volumes/Untitled \
--applicationpath /Applications/Install\ OS\ X\ El\ Capitan.app \
--nointeraction
  • For El Capitan, after Application moved and renamed:
sudo /Users/USERNAME/Documents/Disk\ Images/Apple\ OS\ X/10.11\ El\ Capitan/Install\ OS\ X\ El\ Capitan.app/Contents/Resources/createinstallmedia \
--volume /Volumes/Untitled \
--applicationpath /Users/USERNAME/Documents/Disk\ Images/Apple\ OS\ X/10.11\ El\ Capitan/Install\ OS\ X\ El\ Capitan.app \
--nointeraction

Step 4: Run Clover on Install USB drive

  • On an Apple computer running OS X, download Clover_v2.3k_r3330.pkg from:

http://sourceforge.net/projects/cloverefiboot/files/?source=typ_redirect

  • Run Clover_v2.3k_r3330.pkg

  • Click Continue until Installation Type screen

  • On Installation Type screen, click Change Install Location...

  • On Destination Select screen, select the Install USB drive as destination, click Continue

  • Back on Installation Type screen, click Customize

  • On Custom Install on "..." screen select Install for UEFI booting only

    • This should automatically select Install Clover in the ESP
    • This should automatically unselect Bootloader, Don't update MBR and PBR sectors
    • This should automatically unselect CloverEFI, CloverEFI 64-bits SATA
  • On Custom Install on "..." screen select Themes

  • On Custom Install on "..." screen select Drivers64UEFI, OsxAptioDrv-64

Step X Configure Clover

  • TODO: Complete seciton

  • Mount the EFI partition (if not mounted):

diskutil list
[...]
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *15.6 GB    disk2
   1:                        EFI EFI                     209.7 MB   disk2s1
   2:                  Apple_HFS Install OS X El Capitan 15.3 GB    disk2s2
diskutil mount /dev/disk2s1
  • On the EFI partition edit /EFI/CLOVER/configur.plist to configure Clover to include:
    • qemu cpu flag
    • HFS efi driver

Step 5 Insert Install USB drive

  • Remove install USB drive from Apple computer running OS X and plug in to Linux kvm host.
  • Determine usb device
  • After plug in, run dmesg:
dmesg
[1129574.519912] kvm: zapping shadow pages for mmio generation wraparound
[1129718.445605] kvm [27208]: vcpu0 ignored rdmsr: 0x199
[1129718.446369] kvm [27208]: vcpu0 ignored rdmsr: 0x199
[1129752.993074] kvm [27208]: vcpu0 ignored rdmsr: 0x199
[1129752.993818] kvm [27208]: vcpu0 ignored rdmsr: 0x199
[1129766.396092] kvm [27208]: vcpu0 ignored rdmsr: 0x199
[1129766.396841] kvm [27208]: vcpu0 ignored rdmsr: 0x199
[1129826.468043] kvm: zapping shadow pages for mmio generation wraparound
[1129870.277371] kvm [27218]: vcpu0 ignored rdmsr: 0x199
[1129870.278097] kvm [27218]: vcpu0 ignored rdmsr: 0x199
[1130438.919198]  sdb: sdb1 sdb2
  • Add to qemu startup, where /dev/sdb is device:
-hdb /dev/sdb
  • Reference:

http://www.linux-kvm.org/page/USB_Host_Device_Assigned_to_Guest http://unix.stackexchange.com/questions/37779/how-do-i-boot-from-a-liveusb-using-qemu-kvm

Step 6 Create Disk and Set Parameters

  • On Linux kvm host, create a disk image:
sudo qemu-img create -f qcow2 /vm/osx-disk0.qcow2 200G
  • Ignore MSR readout on host by VM:
sudo su -
echo 1 > /sys/module/kvm/parameters/ignore_msrs

Step 7 qemu Start

  • On Linux kvm host, start qemu:
cd /vm/
sudo qemu-system-x86_64 \
-enable-kvm \
-m 8192 \
-cpu core2duo,kvm=off,vendor=GenuineIntel \
-smp 6,sockets=1,cores=3,threads=2 \
-vga std \
-bios /vm/osx-ovmf-bios/bios.bin \
-usb \
-smbios type=2 \
-net none \
-device isa-applesmc,osk="LOOK-IT-UP" \
-device piix4-usb-uhci,id=usbbus \
-usb -usbdevice disk:format=raw:/dev/sdb \
-device ahci,id=ide \
-device ide-drive,bus=ide.2,drive=MacHDD \
-drive id=MacHDD,if=none,file=/vm/demo1-disk0.qcow2 \
-monitor stdio -S \
-vnc :1 

Step 8 Clover Start

  • Connect a VNC client to Linux kvm host
  • Tunnel 5901 over ssh:
ssh -L 5910:127.0.0.1:5901 KVM_HOST
  • Connect a VNC client to 127.0.0.1 5710

  • At boot, type:

"KernelBooter_kexts"="Yes" "CsrActiveConfig"="103"
  • At Clover boot screen, choose Boot OS X Install from OS X Install OS X El Capitan

  • NOTE: Black screen, no progress.

Copy link

ghost commented Jan 29, 2016

Please ensure you have at least EFI/CLOVER/drivers64UEFI/DataHubDxe-64.efi in your clover image
By adding this driver, the KVM internal error should dissapear

@gordonturner
Copy link
Author

Thanks @marco-st, that was indeed the issue, updated.

@jakgra
Copy link

jakgra commented Mar 10, 2016

Thanks for the great tutorial. Works like a charm.

For better mouse positioning you can use the spice protocol instead of vnc:
Just replace -vnc :1 with -spice port=5930,disable-ticketing in the qemu start command and then connect to the guest with the command remote-viewer spice://localhost:5930 .
The remote-viewer from the previous command is part of the virt-manager package in most linux distributions or you can download it from here: https://virt-manager.org/download/ (protocol home page: http://www.spice-space.org/download.html). There is also a binary for windows available.

To get a 1920x1080 resolution you can change the resolution in the OVMF fake bios:

  1. replace the 800x600 resolution in EFI/EFI/CLOVER/config.plist with 1920x1080,
  2. when you get to clover select Restart computer,
  3. then while the TianoCore screen is shown press a key (most keys will work) to enter the fake bios,
  4. in the fake bios set Device Manager -> OVMF Platform Configuration -> Change Preferred Resolution for Next Boot to 1920x1080, then commit changes and exit, continue to boot.
  5. when you get to clover select Restart computer again, this time the TianoCore will have the right resolution of 1920x1080 and when you boot to OSX the screen won't get distorted.

You have to repeat steps 2-5 every time you start your qemu virtual machine which is pretty anoying. The real solution would be to patch ovmf to change the default to 1920x1080 (or the resolution you need)(TODO)

@jakgra
Copy link

jakgra commented Mar 10, 2016

I have patched ovmf to have only one fixed resolution and it works well (I have a custom fixed default resolution without the need to reboot ... ). The patch file code is pasted below. Copy it and save it to a file named qemu_fixed_resolution.patch .

From 558a0bb34cd1066e6a7ffb6becf2b0bdd661723c Mon Sep 17 00:00:00 2001
From: Meee <[email protected]>
Date: Thu, 10 Mar 2016 14:25:56 +0100
Subject: [PATCH] Fixed resolution for qemu


---
 OvmfPkg/QemuVideoDxe/Initialize.c | 38 +-------------------------------------
 1 file changed, 1 insertion(+), 37 deletions(-)

diff --git a/OvmfPkg/QemuVideoDxe/Initialize.c b/OvmfPkg/QemuVideoDxe/Initialize.c
index 9e0c3aa..8f5797f 100644
--- a/OvmfPkg/QemuVideoDxe/Initialize.c
+++ b/OvmfPkg/QemuVideoDxe/Initialize.c
@@ -209,43 +209,7 @@ QemuVideoCirrusModeSetup (
 /// Table of supported video modes
 ///
 QEMU_VIDEO_BOCHS_MODES  QemuVideoBochsModes[] = {
-  {  640,  480, 32 },
-  {  800,  480, 32 },
-  {  800,  600, 32 },
-  {  832,  624, 32 },
-  {  960,  640, 32 },
-  { 1024,  600, 32 },
-  { 1024,  768, 32 },
-  { 1152,  864, 32 },
-  { 1152,  870, 32 },
-  { 1280,  720, 32 },
-  { 1280,  760, 32 },
-  { 1280,  768, 32 },
-  { 1280,  800, 32 },
-  { 1280,  960, 32 },
-  { 1280, 1024, 32 },
-  { 1360,  768, 32 },
-  { 1366,  768, 32 },
-  { 1400, 1050, 32 },
-  { 1440,  900, 32 },
-  { 1600,  900, 32 },
-  { 1600, 1200, 32 },
-  { 1680, 1050, 32 },
-  { 1920, 1080, 32 },
-  { 1920, 1200, 32 },
-  { 1920, 1440, 32 },
-  { 2000, 2000, 32 },
-  { 2048, 1536, 32 },
-  { 2048, 2048, 32 },
-  { 2560, 1440, 32 },
-  { 2560, 1600, 32 },
-  { 2560, 2048, 32 },
-  { 2800, 2100, 32 },
-  { 3200, 2400, 32 },
-  { 3840, 2160, 32 },
-  { 4096, 2160, 32 },
-  { 7680, 4320, 32 },
-  { 8192, 4320, 32 }
+  { 1920, 1080, 32 }
 };

 #define QEMU_VIDEO_BOCHS_MODE_COUNT \
-- 
2.7.2

To apply it run git apply /PATH/TO/PATCH/qemu_fixed_resolution.patch inside the ~/src/edk2 directory before running OvmfPkg/build.sh -a X64 -t GCC49.
The patch sets the resolution to 1920x1080. If you need another resolution just open the qemu_fixed_resolution.patch in a text editor and change the line + { 1920, 1080, 32 } to + { 1280, 1024, 32 } (for example) before running git apply.

@shawly
Copy link

shawly commented Mar 16, 2016

Great guide! I successfully got El Captain installed on a guest under Proxmox VE 4.1.
The only thing that's troubling me at the moment is the resolution, I change it within the OVMFs fake bios to 1600x900 and then when I'm in the clover screen I press Page Up until I'm also at 1600x900, but when I boot OS X the screen still gets teared up. But it's fine when I connect through OS X' screen sharing VNC, though it's still at 800x600.

I also don't quite understand all the configuration steps in the Clover Configurator and at the end I should override everything within the ACPI dictionary anyway, wut?

Edit: As a temporary fix for the small resolution I found out using the vmware graphics adapter works quite well, but QEMU's integrated VNC for guests only shows a blackscreen now.. But I can access OS X through the screen sharing feature, now with a fixed resolution of 1280x1024, but that's better than 800x600.

@elvanderb
Copy link

I followed this guide step by step, very carefully, but I cannot install El Capitan 10.11.4. The installation is stuck just after the spinning wheel appear. I tried a lot of things but so far, no luck. Any idea?

@apnar
Copy link

apnar commented Mar 29, 2016

Shawly, would you mind sharing the config files you used for Proxmox?

@apiontek
Copy link

apiontek commented Apr 6, 2016

I am also stuck. I'm using Ubuntu Xenial 16.04 installed from beta 2, with QEMU 2.5.0 (Debian 1:2.5+dfsg-5ubuntu6)

Here's the script I'm using to run qemu, and here's a screenshot of where I am stuck with "DSMOS has arrived" as last line printed, and spinning beachball in upper left corner.

I built clover with default 1920x1080 resolution as per jakgra's suggestion (I edited the file myself rather than applying the patch as git said the patch wouldn't apply). The commit I built from is b1bb6f5961d82f30046e39e187a80556250f2bd1

Because of this, I also entered String 1920x1080 in Clover Configurator > GUI > ScreenResolution ... then I tried it several other ways, including default 800x600, but I kept having the same problem, so I don't think this was the cause.

I used Clover_v2.3k_r3411 and Configurator 4.27.0 (Vibrant edition). Here's the /media/loop/EFI/CLOVER/config.plist I ended up with on my usb .dd file.

The beachball spins for a while and then stops. If I click in the screen to capture the mouse, I can move it, very poorly, but that's all, and then it freezes after 5-10 minutes

@pashdown
Copy link

Got as far as completing the install, but booting on its own is difficult. Should the contents of the EFI partition be copied to the EFI partition of the install disk?

@dasJ
Copy link

dasJ commented Jun 4, 2016

Got to the Clover splash screen but when I hit enter to the installer, I see a cursor which blinks about one time and then just freezes. Any ideas? I'm passing my GTX 760, but it should at least a kernel panic imo.

@am517
Copy link

am517 commented Jun 19, 2016

Hey, this is a great guide! Thanks for this!

I'm running Ubuntu 16.04 so there are a few changes I thought I'd share.

  • The OVMF version in the default repositories works fine - no need to compile anything anymore.
    apt install qemu-kvm ovmf libvirt-bin bridge-utils
  • To permanently Ignore MSR readout
    nano /etc/modprobe.d/qemu-system-x86.conf
    add options kvm ignore_msrs=1 and restart
  • To permanently set the resolution follow @jakgra steps 3-5, but
    first
    cp /usr/share/OVMF/OVMF_VARS.fd /var/lib/libvirt/images/hackintosh/hackintosh-ovmf-nvram.fd
    remove
    -bios /vm/2016-03-06/bios.bin \
    and replace with something like this
    -drive file=/usr/share/OVMF/OVMF_CODE.fd,if=pflash,format=raw,unit=0,readonly=on \
    -drive file=/var/lib/libvirt/images/hackintosh/hackintosh-ovmf-nvram.fd,if=pflash,format=raw,unit=1 \
    or, if you're using virsh it would look something like
    <os>
    <type arch='x86_64' machine='pc-q35-2.5'>hvm</type>
    <loader readonly='yes' type='pflash'>/usr/share/OVMF/OVMF_CODE.fd</loader>
    <nvram>/var/lib/libvirt/images/hackintosh/hackintosh_nvram.fd</nvram>
    <boot dev='hd'/>
    </os>
  • As a matter of preference I also made the EFI its own disk, mostly because I'm aiming to use a 9p root volume after everything is set up (mac9p)
    first copy your clover efi partition
    dd if=/dev/sdb1 of=/var/lib/libvirt/images/hackintosh/hackintosh-clover-efi.dd
    and then add something like this
    -drive file=/var/lib/libvirt/images/hackintosh/hackintosh-clover-efi.dd,format=raw,if=none,id=drive-sata0-0-0,bus=0,unit=0 \
    -device ide-hd,bus=ide.0,drive=drive-sata0-0-0,id=sata0-0-0,bootindex=1 \
    -drive file=/var/lib/libvirt/images/hackintosh/hackintosh-disk0.qcow2,format=qcow2,if=none,id=drive-sata0-0-1,bus=0,unit=1 \
    -device ide-hd,bus=ide.1,drive=drive-sata0-0-1,id=sata0-0-1 \
    or in virsh
    <disk type='file' device='disk'>
    <driver name='qemu' type='raw'/>
    <source file='/var/lib/libvirt/images/hackintosh/hackintosh-clover-efi.dd'/>
    <target dev='sda' bus='sata'/>
    <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>
    <disk type='file' device='disk'>
    <driver name='qemu' type='qcow2'/>
    <source file='/var/lib/libvirt/images/hackintosh/hackintosh-disk0.qcow2'/>
    <target dev='sdb' bus='sata'/>
    <address type='drive' controller='0' bus='0' target='0' unit='1'/>
    </disk>
    the EFI disk is easily accessed in Ubuntu and the Mac vm without being tied to a particular disk image.
  • One thing that really helped me figure out the correct Qemu commands was to make a new virtual machine with virt-manager, entering as many of the settings as possible. From there virsh edit hackintosh and added what couldn't be added in virt-manager. Finally you can do virsh domxml-to-native qemu-argv hackintosh.xml and you'll have a pretty good idea of what qemu expects!
  • And lastly, I have one question - why did you choose core2duo for the cpu? I am trying to use -cpu host - for the life of me I can't get it to work but if I install OS X directly on the PC it boots with no problem. Maybe KVM still doesn't work with skylake? I have no idea...

@vasyl83
Copy link

vasyl83 commented Jun 26, 2016

@AdamRabbit Mind sharing your final qemu-system-x86_64 command or virsh xml file (you can get it with virsh dumpxml Hackintosh > hackintosh.xml if your vm is called Hackintosh)?

@am517
Copy link

am517 commented Jun 26, 2016

Sure thing @vasyl83 - this is still very much a work in progress. I'm converting a working Hackintosh to a Ubuntu based virtual machine.

  • This boots fine, system updates work, clearly needs video card
  • Some lines were added by virsh but I don't know what they do
  • Still working on vfio-pci for vga passthrough
  • Need to fix clover config (I think) to use cpu host instead of core2duo
  • Haven't tested Mac9p but my hope is to use that for /Users and possibly everything
  • USB passthrough works (mouse,keyboard, bluetooth, webcam).
  • Needs fine tuning
  • I can't convert this into a working virsh xml, if you can please share!

/usr/bin/qemu-system-x86_64
-name hackintosh
-machine pc-q35-2.5,accel=kvm,usb=off,vmport=off
-cpu core2duo,kvm=off,vendor=GenuineIntel
-drive file=/usr/share/OVMF/OVMF_CODE.fd,if=pflash,format=raw,unit=0,readonly=on
-drive file=/var/lib/libvirt/images/hackintosh/hackintosh-ovmf-nvram.fd,if=pflash,format=raw,unit=1
-m 20480
-enable-kvm
-smbios type=2
-realtime mlock=off
-smp 6,sockets=1,cores=3,threads=2
-uuid 278e5cbc-c217-480e-b472-37af1c80b0d4
-rtc base=utc,driftfix=slew
-global kvm-pit.lost_tick_policy=discard
-no-hpet
-no-shutdown
-boot strict=on
-device i82801b11-bridge,id=pci.1,bus=pcie.0,addr=0x1e
-device pci-bridge,chassis_nr=2,id=pci.2,bus=pci.1,addr=0x1
-device ahci,id=sata0,bus=pci.2,addr=0x5
-usb
-device usb-host,vendorid=0x046d,productid=0x082d
-device usb-host,vendorid=0x0a12,productid=0x0001
-device usb-host,vendorid=0x046d,productid=0xc52b
-serial stdio
-drive file=/var/lib/libvirt/images/hackintosh/hackintosh-clover-efi.dd,format=raw,if=none,id=drive-sata0-0-0,bus=0,unit=0
-device ide-hd,bus=ide.0,drive=drive-sata0-0-0,id=sata0-0-0,bootindex=1
-drive file=/var/lib/libvirt/images/hackintosh/hackintosh-disk0.qcow2,format=qcow2,if=none,id=drive-sata0-0-1,bus=0,unit=1
-device ide-hd,bus=ide.1,drive=drive-sata0-0-1,id=sata0-0-1
-netdev user,id=hostnet0
-device e1000-82545em,netdev=hostnet0,id=net0,mac=52:54:00:cd:3f:7c,bus=pci.2,addr=0x1
-spice port=5901,addr=127.0.0.1,disable-ticketing,image-compression=off,seamless-migration=on
-device qxl-vga,id=video0,ram_size=67108864,vram_size=67108864,vgamem_mb=16,bus=pcie.0,addr=0x1
-full-screen
-device isa-applesmc,osk="sosupersecretitsnotevenfunny"

@vasyl83
Copy link

vasyl83 commented Jun 27, 2016

@AdamRabbit
I found another guide for unRAID that can easily be adoptable, actually the second comment in that guide gives you the exact xml and what to change for it to work on any linux with qemu-kvm.

Here is the guide: GUIDE: Mac OS X 10.11 El Capitan – VM on unRAID.

What I like about this guide: creates an iso of El Capitain install so no more need of dd. No need to edit config.plist and no custom dsdt.
What I dislike about this guide: uses direct kernel boot instead of UEFI.

Here is the pastebin of xml that will work on linux (I am using it with Debian Jessie with qemu-system-x86 and qemu-kvm from backports to have version 2.6, required by this guide in order to have a compatible chipset version).

I got it working on the first try, one problem that I am having is the mouse capture on spice, but it is flawless on vnc and mac screen sharing.

@am517
Copy link

am517 commented Jun 27, 2016

Oh, that's great! I'll try again with the XML. I want to stick with the UEFI, but perhaps I can adapt it.

About the mouse, that is not so great indeed. What I've discovered is that passing actual things through is best. For example, I'm happily using spice but use a logitech keyboard and mouse like so

-usb
-device usb-host,vendorid=0x046d,productid=0x082d
-device usb-host,vendorid=0x046d,productid=0xc52b \

You'll need a second keyboard at least but for me this is better than spice and vnc.

Thanks for the pastebin - I'll try that after the kids are asleep and post an update if I'm successful.

@128keaton
Copy link

hi, I'm getting stuck at AppleKeyStore starting. Anyone have this issue?

@128keaton
Copy link

Ok, I figured it out, now to get networking, well, working. Do NOT use q35-acpi-dsdt.aml, it was removed in a recent commit.

@daniloc
Copy link

daniloc commented Sep 28, 2016

Any thoughts on making this work with Sierra? Fantastic writeup, by the way, thanks for sharing it.

@NickRandom
Copy link

NickRandom commented Nov 18, 2016

For Sierra please repeat the same steps as for El Capitan with the Sierra-Installer. For your bootstick please use an actual version of Clover (I tried 3811 or so), in the start-script for the machine replace the core2duo-CPU with Nehalem and delete the "base=2016-01-01T16:01:21"- instruction for setting up the rtc-clock to a special date - then enjoy the Sierra-Installer. These corrections let install me successfully OSX 10.12 in a virtual KVM environment. My only problem now is the clock inside the installed system, which is running about 4 times too slow. Does anyone have an idea to tune up this issue?

@mmhobi7
Copy link

mmhobi7 commented Jan 28, 2017

My Installation iso won't pop up in clover

@chuckremes
Copy link

There's an alternate way to boot and install OS X under QEMU documented here: https://github.com/kholia/OSX-KVM

I used this methodology and found it to be MUCH simpler than the steps outlined above. And the clock runs at the correct rate too. :)

@bikubi
Copy link

bikubi commented Sep 28, 2020

Even simpler alternative: https://github.com/foxlet/macOS-Simple-KVM/
...which doesn't support older versions, but I was able to modify their basic.sh script to accept my Installers of Yosemite & El Capitan. The latter can even be created via an official download (at the time of writing).

@Turretinista
Copy link

Where is this? VM images and resources in /vm/2016-03-06

@gordonturner
Copy link
Author

Where is this? VM images and resources in /vm/2016-03-06

This is a directory you create locally.

(Also this is wildly out of date and there are more current resources out there to do this.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment