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

  • 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
@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