Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 72 You must be signed in to star a gist
  • Fork 22 You must be signed in to fork a gist
  • 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

  • Some notes about this approach:

    • An OSX Installer USB drive for Install OS X El Capitan is created
    • Clover is then installed on the USB drive
    • Clover Configurator is then run on the USB drive
    • The USB drive contents are copied to the VM host
    • VNC is used to connect to the guest UI
    • The qxl virtual video device is used (part of the standard kvm qemu install)
    • No video card PCI passthrough is used
    • At then of the install OSX Screen Sharing is turned on
  • VM Host Ubuntu 15.10 (x86_64) server

  • Standard kvm, qemu packages installed

  • All Ubuntu updates applied (2016-03-06)

  • VM images and resources in /vm/2016-03-06

  • Supporting MacBook Air running OSX 10.11.3 used to create USB drive

  • All OSX updated applied (2016-03-06)

Documentation

  • qemu documentation:

http://wiki.qemu.org/download/qemu-doc.html

  • clover documentation:

http://clover-wiki.zetam.org/Configuration

Screen Resolution

A quick note about screen resolution:

  • OVMF and Clover screen sizes must match otherwise the screen will appear mangeled or distorted.
  • For purposes of these instructions a resolution of 800x600 will be used.

TODO: Change OVMF and Clover resolutions to 1024x768 or 1280x1024

Step 1 OVMF

  • On Linux kvm host, build OVMF, please see:

https://gist.github.com/gordonturner/85dcc321d2099d610e67

  • Copy bios.bin:
sudo cp ./Build/OvmfX64/DEBUG_GCC49/FV/OVMF.fd /vm/2016-03-06/bios.bin

Step 2 Get Apple SMC osk Value

  • On OS X, running on Apple hardare, to get the SMC osk value please see:

https://gist.github.com/gordonturner/c33bcc935e32f9fa6695

  • NOTE: 2016-03-06 The value appears to be a constant string

  • Reference:

http://www.osxbook.com/book/bonus/chapter7/tpmdrmmyth/

Step 3 Create Install USB Drive

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

  • Run Disk Utilty

  • If on 10.11 or later:

    • Select the USB device (not a partition of the device) in the left pane
    • Click Partition tab, ensure there is a single partition, click Cancel or create single partition
    • With the USB device selected, click Erase
    • Set Name to Untitled, Format to OS X Extended (Journaled), Scheme to GUID Partition Map
    • Click Erase button
    • Confirm Partition Map is set to GUID Partition Map
  • If on 10.10 or earler:

    • Select the USB device (not a partition of the device) in the left pane
    • Click Partition tab
    • In Partition Layout, select 1 Partition
    • Confirm Partition Map is set to GUID Partition Map
    • 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, run:

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, if you have moved the Install OS X El Capitan.app (which is common to prevent it being deleted) run:
export MOVED_LOCATION=~/Documents/Disk\ Images/Apple\ OS\ X/10.11\ El\ Capitan
sudo "$MOVED_LOCATION"/Install\ OS\ X\ El\ Capitan.app/Contents/Resources/createinstallmedia \
--volume /Volumes/Untitled \
--applicationpath "$MOVED_LOCATION"/Install\ OS\ X\ El\ Capitan.app \
--nointeraction

Step 4: Run Clover on Install USB drive

  • On an Apple computer running OS X, download Clover from:

https://sourceforge.net/projects/cloverefiboot/files/latest/download

  • NOTE: 2016-03-06 Current download was Clover_v2.3k_r3354.zip

  • Download Clover_v2.3k_r3354.zip

  • Unzip Clover_v2.3k_r3354.zip

  • Run Clover_v2.3k_r3354.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
  • On Custom Install on "..." screen, select Themes, BootCamp (or your theme of choice)

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

  • On Custom Install on "..." screen, click Install

  • Install should take about 3 min on USB 3 device

  • When complete, click Close

  • Two volumes should be mounted when complete:

    • EFI
    • Install OS X El Capitan
  • Leave volumes mounted

Step 5: Download Files

  • Download q35-acpi-dsdt.aml (click View Raw):

https://github.com/qemu/qemu/blob/4f7ab0cdbccfc1d0a3a6d0a7c9a22d8a90d9e2f0/pc-bios/q35-acpi-dsdt.aml

  • Copy to EFI/CLOVER/ACPI/origin on USB boot drive:
cp ~/Downloads/q35-acpi-dsdt.aml /Volumes/ESP/EFI/CLOVER/ACPI/origin/
  • Download HFSPlus.efi (click View Raw):

https://github.com/JrCs/CloverGrowerPro/blob/9fc3991c7a82be1a0d096c3a2179098f35b69264/Files/HFSPlus/X64/HFSPlus.efi

  • Copy to EFI/EFI/CLOVER/drivers64UEFI/ on USB boot drive:
cp ~/Downloads/HFSPlus.efi /Volumes/ESP/EFI/CLOVER/drivers64UEFI/

Step 6 Run Clover Configurator

  • NOTE: No source, license is unclear, free to use
  • Download:

http://mackie100projects.altervista.org/download/

  • NOTE: 2016-03-06 current version is 4.27.0

  • Download CCV.zip

  • Unzip CCV.zip

  • Run Clover Configurator.app and edit: EFI/EFI/CLOVER/config.plist

  • Clover Configurator, Acpi

  • Root/ACPI/DSDT Dictionary

    • NOTE: Select New way

    • Fixes Dictionary

      • NewWay Boolean YES (Default)
      • FixRegions Boolean YES (Default)
      • FIX_RTC Boolean YES (Default)
      • FiX_TMR Boolean YES (Default)
      • AddIMEI Boolean NO (Default)
      • FIX_INTELGFX Boolean NO (Default)
      • DeleteUnused Boolean YES (Default)
      • FIX_ADP1 Boolean YES (Default)
      • AddPNLF Boolean YES (Default)
      • FIX_WAK Boolean NO (Default)
      • FIX_S3D Boolean YES (Default)
      • FIX_ACST Boolean YES (Default)
      • AddHDMI Boolean YES (Default)
    • Debug Boolean YES (Changed)

    • DSDT name String q35-acpi-dsdt.aml (Changed)

    • ReuseFFFF Boolean NO (Deault)

    • Root/ACPI/DropTables Remove all

  • Clover Configurator, Boot

  • Root/Boot/Arguements Dictionary

    • Uncheck all, including kext-dev-mode=1 rootless=0
    • Custom Flags String `` (Default)
  • Root/Boot/

    • Default Boot Volume String OSX (Changed)
    • Legacy String PBR (Default)
    • DefaultLoader String boot.efi (Default)
    • XMPDetection String YES (Changed)
    • Timeout Number 5 (Default)
    • -1 Boolean NO (Default)
    • Fast Boolean NO (Default)
    • Debug Boolean NO (Default)
    • NeverHibernate Boolean NO (Default)
    • CustomLogo String `` (Default)
    • NoEarlyProgress Boolean NO (Default)
  • Root/Boot/Secure Boot

    • Whitelist Empty (Default)
    • Blacklist Empty (Default)
    • Secure Boolean NO (Default)
  • Clover Configurator, Cpu

  • Root/Cpu Dictionary

    • QEMU Boolean YES (Changed)
    • NOTE: All other values default to empty or NO
  • Clover Configurator, Devices

  • Root/Devices/Fake ID Dictionary

    • NOTE: All values default to empty
  • Root/Devices/USB Dictionary (All unchecked)

    • Inject Boolean NO (Changed)
    • Add ClockID Boolean NO (Changed)
    • FixOwnership Boolean NO (Changed)
    • HighCurrent Boolean NO (Default)
    • NOTE: All values set to NO
  • Root/Devices/Audio

    • Inject String `` (Default)
    • AFGlowPoweredState Boolean NO (Default)
    • ResetHDA Boolean NO (Changed)
  • Root/Devices/

    • NOTE: Properties and Add Properties are default to empty or NO
  • Clover Configurator, Disabled Devices

  • NOTE: All default values, nothing configured

  • Clover Configurator, Gui

  • Root/Gui Dictionary

    • Mouse Dictionary
      • DoubleClick Number 500 (Default)
      • Speed Number 8 (Default)
      • Enabled Boolean NO (Default)
      • Mirror Boolean NO (Default)
    • Scan Boolean YES (Default)
    • Language String `` (Default)
    • ScreenResolution String 800x600 (Changed)
    • Console Mode String `` (Default)
    • Theme String bootcamp (Default, set from Clover install)
    • Custom Icons Boolean NO (Default)
    • Text Only Boolean NO (Default)
  • NOTE: All default values, except ScreenResolution

  • Clover Configurator, Graphics

  • NOTE: All default values, nothing selected

  • Clover Configurator, Kernel and Kext Patches

  • Root/KernelAndKextPatches Dictionary

    • Kernel CPU Boolean NO (Default)
    • Kernel LAPIC Boolean NO (Default)
    • Kernel Pm Boolean NO (Default)
    • Kernel HaswellE Boolean NO (Default)
    • Apple RTC Boolean NO (Changed)
    • Asus AICPUPM Boolean NO (Default)
    • Debug Boolean NO (Default)
  • NOTE: All default values, except Apple RTC

  • Clover Configurator, Rt Variables

  • Root/RtVariables Dictionary

    • ROM String UseMacAddr0 (Default)
    • MLB String `` (Changed)
    • BooterConfig String 0x28 (Default)
    • CsrActiveConfig String 0x67 (Default)
  • NOTE: All default values, except MLB

  • Clover Configurator, SMBIOS

  • NOTE: All default values

  • Clover Configurator, System Parameters

  • Root/SystemParameters Dictionary

    • Custom UUID String `` (Default)
    • Backlight Level String `` (Default)
    • Inject Kexts String Detect (Default)
    • No Caches Boolean NO (Default)
    • Inject System ID Boolean YES (Default)
  • NOTE: All default values

  • Save and exit Clover Configrator

  • Manually edit EFI/EFI/CLOVER/config.plist:

    • Paste into Root/ACPI:
<key>ACPI</key>
	<dict>
		<key>DSDT</key>
		<dict>
			<key>Debug</key>
			<false/>
			<key>DropOEM_DSM</key>
			<false/>
			<key>Fixes</key>
			<dict>
				<key>AddPNLF_1000000</key>
				<true/>
				<key>DeleteUnused_400000</key>
				<true/>
				<key>FIX_ACST_4000000</key>
				<true/>
				<key>FIX_ADP1_800000</key>
				<true/>
				<key>FIX_RTC_20000</key>
				<true/>
				<key>FIX_S3D_2000000</key>
				<true/>
				<key>FiX_TMR_40000</key>
				<true/>
				<key>FixRegions_10000000</key>
				<true/>
				<key>FixSBUS_0080</key>
				<true/>
			</dict>
			<key>Name</key>
			<string>q35-acpi-dsdt.aml</string>
			<key>ReuseFFFF</key>
			<false/>
		</dict>
		<key>SSDT</key>
		<dict>
			<key>DropOem</key>
			<false/>
			<key>Generate</key>
			<false/>
		</dict>
	</dict>
	<key>Boot</key>
	<dict>
		<key>Arguments</key>
		<string>-v</string>
  • After complete, eject the USB drive.

Step 7 Linux Copy USB Drive to Disk Image on kvm Host

  • Either dd the USB drive on OSX or use dd on the Linux KVM host, these instructions are for Linux.

  • Login to KVM host and run tail on the kernel log to determine device name:

tail -f /var/log/kern.log
  • Plugin the USB drive
  • Observe the device name:
Feb 20 14:40:58 kvm2 kernel: [13158.166032] usb 4-1.4: new high-speed USB device number 7 using ehci-pci
Feb 20 14:40:58 kvm2 kernel: [13158.261978] usb 4-1.4: New USB device found, idVendor=05dc, idProduct=a833
Feb 20 14:40:58 kvm2 kernel: [13158.261984] usb 4-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Feb 20 14:40:58 kvm2 kernel: [13158.261989] usb 4-1.4: Product: USB Flash Drive
Feb 20 14:40:58 kvm2 kernel: [13158.261992] usb 4-1.4: Manufacturer: Lexar
Feb 20 14:40:58 kvm2 kernel: [13158.261995] usb 4-1.4: SerialNumber: AA7OY8PQBU1UVGRJ
Feb 20 14:40:58 kvm2 kernel: [13158.329307] usb-storage 4-1.4:1.0: USB Mass Storage device detected
Feb 20 14:40:58 kvm2 kernel: [13158.329475] scsi host6: usb-storage 4-1.4:1.0
Feb 20 14:40:58 kvm2 kernel: [13158.329639] usbcore: registered new interface driver usb-storage
Feb 20 14:40:58 kvm2 kernel: [13158.345857] usbcore: registered new interface driver uas
Feb 20 14:41:00 kvm2 kernel: [13159.878847] scsi 6:0:0:0: Direct-Access     Lexar    USB Flash Drive  1100 PQ: 0 ANSI: 6
Feb 20 14:41:00 kvm2 kernel: [13159.879522] sd 6:0:0:0: Attached scsi generic sg1 type 0
Feb 20 14:41:00 kvm2 kernel: [13159.881104] sd 6:0:0:0: [sdb] 31285248 512-byte logical blocks: (16.0 GB/14.9 GiB)
Feb 20 14:41:00 kvm2 kernel: [13159.882187] sd 6:0:0:0: [sdb] Write Protect is off
Feb 20 14:41:00 kvm2 kernel: [13159.882190] sd 6:0:0:0: [sdb] Mode Sense: 22 00 00 00
Feb 20 14:41:00 kvm2 kernel: [13159.883331] sd 6:0:0:0: [sdb] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
Feb 20 14:41:00 kvm2 kernel: [13159.902183]  sdb: sdb1 sdb2
Feb 20 14:41:00 kvm2 kernel: [13159.908483] sd 6:0:0:0: [sdb] Attached SCSI removable disk
  • In this example sdb is the device
  • Run dd, takes about 10 min on USB 3 device:
sudo dd if=/dev/sdb of=/vm/2016-03-06/clover-usb-disk.dd

Step 8 Create Disk and Set Parameters

  • On Linux kvm host, create a disk image:
sudo qemu-img create -f qcow2 /vm/2016-03-06/osx-disk0.qcow2 200G
  • Ignore MSR readout on host by VM:
sudo su -
echo 1 > /sys/module/kvm/parameters/ignore_msrs
  • NOTE: This appears to reset after a hard reboot, may need to be run as part of a script.

Step 9 qemu Start

  • NOTE: Due to expired certificates used to sign the installation packages, it is necessary during installation to set the date back and remove the network card. After installation is complete, the time can be set and network card added back.

  • NOTE: Set the SMB_OSK_VALUE_HERE with the value from Step 2 Get Apple SMC osk Value

  • On Linux kvm host, start qemu:

sudo qemu-system-x86_64 \
\
-rtc clock=vm,base=2016-01-01T16:01:21 \
\
-m 4096 \
-enable-kvm \
-cpu core2duo,vendor=GenuineIntel \
-rtc base=localtime \
-smbios type=2 \
-machine q35,accel=kvm,usb=off,vmport=off \
-bios /vm/2016-03-06/bios.bin \
-smp 4,sockets=1,cores=2,threads=2 \
-device isa-applesmc,osk="SMB_OSK_VALUE_HERE" \
\
-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 \
\
-drive file=/vm/2016-03-06/clover-usb-disk.dd,if=none,id=drive-sata0-0-2,format=raw \
-device ide-hd,bus=ide.2,drive=drive-sata0-0-2,id=sata0-0-2,bootindex=1 \
\
-drive file=/vm/2016-03-06/osx-disk0.qcow2,if=none,media=disk,id=drive-sata0-0-0,format=qcow2 \
-device ide-hd,bus=sata0.0,drive=drive-sata0-0-0,id=sata0-0-0 \
\
-usb \
-device usb-mouse \
-device usb-kbd \
-serial stdio \
-device qxl-vga,id=video0,ram_size=67108864,vram_size=67108864,vgamem_mb=16 \
-vnc :1

Step 9 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 Clover boot screen, choose Boot OS X Install from OS X Install OS X El Capitan

Step 10 Installation

  • During install, first use Disk Utility to configure the QEMU drive.

  • NOTE: Using vnc to perform the install, there is a frustrating bug with vnc and the OS X installer, the mouse.

  • It is possible to use the Tab key to select and Spacebar to select on most of the inputs, but in some situations it becomes a bit of a game to move the mouse in the guest to the button.

  • Once installed and connecting over vnc directly to the guest this is not an issue.

Step 11 Post Installation

  • System Preferences, Sharing, enable Screen Sharing and set password

  • System Preferences, Energy Saving, Computer sleep set to Never

  • System Preferences, Energy Saving, Display sleep set to Never

  • Connect to the guest directly, rather then through the host.

EFI Disk Image Manipulation

  • Rather then constantly editing the USB drive then dd'ing and copying the image around, it is possible to directly edit the disk image

  • First, create a mount points, this step only has to happen once:

sudo mkdir /media/loop
sudo mkdir /media/efi
  • Run fdisk to determine the offset of the efi partition:
parted /vm/clover-usb-disk.dd 
WARNING: You are not superuser.  Watch out for permissions.
GNU Parted 3.2
Using /vm/clover-usb-disk.dd
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) unit                                                             
Unit?  [compact]? B                                                       
(parted) print                                                            
Model:  (file)
Disk /vm/clover-usb-disk.dd: 16018046976B
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start       End           Size          File system  Name                  Flags
 1      20480B      209735679B    209715200B    fat32        EFI System Partition  boot, esp
 2      209735680B  15883808767B  15674073088B  hfs+         Untitled
  • NOTE: The offset, in this case 20480

  • Next, mount the EFI System Partition:

sudo mount -o rw,loop,offset=20480 /vm/clover-usb-disk.dd /media/loop
  • Make changes, ie to edit config.plist:
sudo vi /media/loop/EFI/CLOVER/config.plist
  • Unmount the partition:
sudo umount /media/loop

Using fdisk

  • Run fdisk to determine the offset of the efi partition:
fdisk -l  /vm/clover-usb-disk.dd 
  • Output:
Disk /vm/clover-usb-disk.dd: 14.9 GiB, 16018046976 bytes, 31285248 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 2FAED1FF-5343-4827-8FD8-5477D188EA2D

Device                   Start      End  Sectors  Size Type
/vm/clover-usb-disk.dd1     40   409639   409600  200M EFI System
/vm/clover-usb-disk.dd2 409640 31023063 30613424 14.6G Apple HFS/HFS+

Using parted

  • FYI, possible to run parted on the disk image too:
sudo parted /vm/clover-usb-disk.dd print
  • Output:
Model:  (file)
Disk /vm/clover-usb-disk.dd: 16.0GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name                  Flags
 1      20.5kB  210MB   210MB   fat32        EFI System Partition  boot, esp
 2      210MB   15.9GB  15.7GB  hfs+         Untitled

Verify Disk

hdiutil verify Install\ OS\ X\ El\ Capitan.app/Contents/SharedSupport/InstallESD.dmg
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 <someone@email.com>
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).

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