Jump to content

Insanely fast virtual Mac (QEMU, OVMF, Clover and native graphics)


  • Please log in to reply
509 replies to this topic

#1
waschbenzin

waschbenzin

    InsanelyMac Protégé

  • Members
  • PipPip
  • 68 posts
tl;dr Below is my virtual setup, but it's running way too fast (probably due to a wrong busspeed). It is fixed now with newer Clover versions. Read the whole thread to know how it's done. This is not a guide (yet)
 
Hardware:
--------------
CPU: i7-4790K
Board: Gigabyte Z97-UD5H
GPU: nVidia GTX 770
 
Software:
--------------
Ubuntu: 15.10 (no special kernel)
QEMU: 2.3.0 (as provided by ubuntu)
OVMF: compiled from source (on 2015-10-20)
Clover: 2.3 (something around 3292)
 
Installation:
--------------- 
Download El Capitan from the App Store
- Create an ISO according to http://anadoxin.org/...-iso-image.html
- Install ISO in VirtualBox
- Install Clover to virtual USB-Drive (for UEFI-Boot)
 
Configuration:
--------------
Bios:
VT-d enabled
 
Linux:
UEFI-Boot, IOMMU enabled
 
Graphics:
Needs to be disabled within Linux.  Blacklist nvidia module and assign to pci_stub.
 
Clover:
DSDT: q35-acpi-dsdt.aml (available from QEMU-repo)
Fixes: FixSBUS, NewWay, FixRegions, FIX_RTC, FIX_TMR, DeleteUnused, FIX_ADP1, AddPNLF, FIX_S3D, FIX_ACST
Boot-args: -v kex-dev-mode=1 rootless=0, debug=0x08 (<- serial logging)
SMBIOS: MacPro2,1
No Kexts
 
Running:
--------------
 
QEMU:
qemu-system-x86_64 \
# Use KVM for cpu virtualization
-enable-kvm \
# Use 8GB of Ram
-m 8192 \
# Fake a core2duo , disable kvm identification (nVidia need this on Windows)
-cpu core2duo,kvm=off,vendor=GenuineIntel \
# Use 3 cores with 2 threads each -> 6 threads
-smp 6,sockets=1,cores=3,threads=2 \
# Use QEMU's Q35 machine
-M q35 \
# disable regular VGA emulation
-vga none \
# use OVMF instead of standard SeaBios
-bios OVMF.fd \
# enable VM usb
-usb \
-smbios type=2 \
-net none \
# the emulated usb-bus ... might acually not really be used
-device piix4-usb-uhci,id=usbbus \
# attach the clover usb drive
-usbdevice disk:CloverDrive.dd \
# attach the el capitan image
-usbdevice disk:ElCapitanFromVirtualBox.dd \
# emulate apple's copyright device thingy
-device isa-applesmc,osk="AppleCopyrightsWhatYouHaveToPutHereToProtectTheirOS" \
# attach the graphics card to the vm
-device vfio-pci,host=01:00.0,bus=pcie.0,multifunction=on \
-device vfio-pci,host=01:00.1,bus=pcie.0 \
#enable serial logging
-serial stdio 
 
The usb drives should probably be replaced by something faster, but that's something I'll save for later. Probably some options should be cleaned up
 
Current Problems:
--------------
OSX detects a busspeed of 100MHz and seems to multiply it by 4 and thus assumes the cpu is running at 400MHz. Therefore it runs 10 times too fast (one can hardly enter text since the key repeation is kicking in too quickly, the clock counts up one minute every 6 secounds, animations too fast, ...). I tried to increase the BusRatioKHz to 1GHz, but that didn't work. On reddit someone suggested 490MHz which reduces the speed to twice the normal speed. I'm pretty sure this is a Clover issue, since an alternative boot method works for Mavericks (which unfortunatelly doesn't work for ElCapitan, Clover is too fast with Mavericks as well). Unfortunately I'm failing to compile Clover to provide a patch to fix this...
 
Any help is welcome :)


#2
uruviel2001

uruviel2001

    InsanelyMac Protégé

  • Members
  • Pip
  • 8 posts

Interesting! Looks like you're going for a similar set-up as I was planning, could you point me to the lines that needed to be changed? Maybe I can get it to compile.

 

Would setting the cpu to host help?



#3
aphex6b

aphex6b

    InsanelyMac Geek

  • Members
  • PipPipPip
  • 123 posts
  • Gender:Male

does it make any sense to use qemu's ACPI table loading feature or is that for i386 arch only? The fsb / qpi going crazy is that perhaps related to other timing based settings such as HPET tsc or the like?



#4
waschbenzin

waschbenzin

    InsanelyMac Protégé

  • Members
  • PipPip
  • 68 posts
Thanks for the offering uruviel2001, but I updated to the latest svn revision of edk2 and now Clover compiles happily. The revision given in the building instructions (http://clover-wiki.z...org/Development) is missing VarCheckLib (or something like that).
 
So I checked for the changes I had to make to the code to allow different BusSpeeds. I stumpled across a hidden setting. It's called "QEMU", so I think I'm not the first person to have this kind of problem. When setting QEMU to true, a differnt BusSpeed logic applies. 
 
I'm now running at normal speed (at least as far as I could tell from a short test) with the following settings:
 
 
    <key>CPU</key>
    <dict>
        <key>BusSpeedkHz</key>
        <string>1000000</string>
        <key>QEMU</key>
        <true/>
    </dict>
 
 
Warning: Using CloverConfigurator this setting is lost when saving :-(
 
 
@aphex6b: As far as I understood the Busspeed determins how values from the TSC are interpreted. Before using the above setting the mavericks kernel got me this (serial debugging):
EFI_FSB_frequency: read FSBFrequency value: 100000000
EFI_FSB_frequency: read InitialTSC value: 4000078008
 BUS: Frequency =    100.000000MHz, cvtt2n = 0000000A.00000000, cvtn2t = 00000000.19999999
 TSC: Frequency =    400.000000MHz, cvtt2n = 00000002.80000000, cvtn2t = 00000000.66666666, gran = 4
Now I get:
 
EFI_FSB_frequency: read FSBFrequency value: 1000000000
EFI_FSB_frequency: read InitialTSC value: 4000076222
 BUS: Frequency =   1000.000000MHz, cvtt2n = 00000001.00000000, cvtn2t = 00000000.FFFFFFFF
 TSC: Frequency =   4000.000000MHz, cvtt2n = 00000000.40000000, cvtn2t = 00000003.FFFFFFFF, gran = 4

These Messages are coming from this source (maybe another version): http://www.opensourc...sfmk/i386/tsc.c...

gran is the TSC granularity which is read from MSR (https://en.wikipedia...ecific_register) which I needed to disable to get my virtual mac booting. See http://www.contrib.andrew.cmu.edu/~somlo/OSXKVM/ )

I'm not sure whether setting the Bus Frequency to this pretty high value is the best solution, but it works for now...

 
Next up: Trying different methods to connect the virtual hard disk to improve the speed (currently its connected to a virtual usb2.0 controller)


#5
uruviel2001

uruviel2001

    InsanelyMac Protégé

  • Members
  • Pip
  • 8 posts

Nice! Good to hear, once my parts come in may try and replicate your setup!

 

How are you planning on providing things like network and audio?



#6
waschbenzin

waschbenzin

    InsanelyMac Protégé

  • Members
  • PipPip
  • 68 posts

Would setting the cpu to host help?

I can't boot with that setting.

 

I'm using the following settings for now to deal with the hard drive and network:

-netdev user,id=usr0,net=192.168.76.0/24,dhcpstart=192.168.76.9 \
-device e1000-82545em,netdev=usr0,id=vnet0,bus=pcie.0,addr=5 \
-drive id=MacHDD,if=none,file=ElCapitan.dd  \
-device ide-drive,bus=ide.2,drive=MacHDD \
-device ahci,id=hdbus,bus=pcie.0 \
-drive id=Clover,if=none,file=/raid/vm/mac/clover-boot.dd  \
-device ide-drive,bus=hdbus.0,drive=Clover \
So regarding networking, I'm just following http://www.contrib.a.../~somlo/OSXKVM/.  I assign the drives to different busses to avoid Mac OSX complaining about disk identifiers. For Sound I'm using an USB sound card, which works pretty fine. 
 
I've been playing with the system for a few hours now and I didn't notice any problems with the timing setting. I can watch 60 fps videos without stutter. Reboots work most of the time and I was even able to upgrade to 10.11.1 without changing anything :-).


#7
nexx892

nexx892

    InsanelyMac Protégé

  • Members
  • Pip
  • 23 posts

Could you upload your clover img? I'm having problems making a proper one.

 

 

Thanks for your work, seems like KVM + GPU passthrough is the way to go right now to solve skylake woes.



#8
evilsephiroth

evilsephiroth

    InsanelyMac Protégé

  • Members
  • Pip
  • 34 posts
Well It's time to upgrade my virtual setup... I am using vfio with i915 patch for qemu / q35/ chameleon /non Uefi setup...
I'll try your ovmf setup...(currently using ovmf for Windows 8.1)... Mind sharing a guide to compile correctly clover and ovmf?
Ovmf latest Svn? I saw that clover requires a specific version of ovmf...

Clover smbios settings? (Macpro3,1?)


And another thing... Is it possible to compile clover on linux?

#9
waschbenzin

waschbenzin

    InsanelyMac Protégé

  • Members
  • PipPip
  • 68 posts

@nexx892: I'm not comfortable sharing the image (I have no idea what licenses are involved...hope you can respect that :-\... and if I shared it I would feel obligated to support it...). I'm really just creating a virtual hd, partition it,  installing clover with the standard installer (install in ESF, completely UEFI with drivers DataHub, EmuVariables, Partitions) and apply the settings mentioned above.

 

@evilsephiroth

I'm not compiling clover any more since I discovered the hidden setting. (Would just raise the maintainance on my side ;-) ). 

 

I'm using the latest OVMF version, because the prebuild binary is from 2014 and doesn't support USB3 (I'm passing my USB controller to the VM as well...). I just followed https://wiki.ubuntu.com/UEFI/EDK2using:

 TOOL_CHAIN_TAG = GCC49
 TARGET_ARCH    = X64 

to build the RELEASE versions of MdeModulePkg and finally OvmfPkgX64.dsc.

 

I prefer the OVMF+Clover to the chameleon+SeaBios, because it saves the trouble of dealing with the VGA patches (as you seem to be aware of :-) ). 

 

 

I'm using MacPro2,1 in smbios. I just guess this setting. Is it relevant? Any information on what works better (and why?).



#10
evilsephiroth

evilsephiroth

    InsanelyMac Protégé

  • Members
  • Pip
  • 34 posts

@nexx892: I'm not comfortable sharing the image (I have no idea what licenses are involved...hope you can respect that :-\... and if I shared it I would feel obligated to support it...). I'm really just creating a virtual hd, partition it,  installing clover with the standard installer (install in ESF, completely UEFI with drivers DataHub, EmuVariables, Partitions) and apply the settings mentioned above.

 

@evilsephiroth

I'm not compiling clover any more since I discovered the hidden setting. (Would just raise the maintainance on my side ;-) ). 

 

I'm using the latest OVMF version, because the prebuild binary is from 2014 and doesn't support USB3 (I'm passing my USB controller to the VM as well...). I just followed https://wiki.ubuntu.com/UEFI/EDK2using:

 TOOL_CHAIN_TAG = GCC49
 TARGET_ARCH    = X64 

to build the RELEASE versions of MdeModulePkg and finally OvmfPkgX64.dsc.

 

I prefer the OVMF+Clover to the chameleon+SeaBios, because it saves the trouble of dealing with the VGA patches (as you seem to be aware of :-) ). 

 

 

I'm using MacPro2,1 in smbios. I just guess this setting. Is it relevant? Any information on what works better (and why?).

so basically, you downloaded clover version 3292, modified the hidden parameter,installed in the virtual usb drive and built from source ovmf... Didn't kraxel have prebuilt ovmf binary up to date ?

 

https://www.kraxel.o...s/jenkins/edk2/Latest binary is from yesterday... Or these 2 modules(  MdeModulePkg and finally OvmfPkgX64.dsc) should be compiled with GCC49 ?



#11
waschbenzin

waschbenzin

    InsanelyMac Protégé

  • Members
  • PipPip
  • 68 posts

I didn't know about kraxel. Just tested it, works fine ( OVMF-pure-efi.fd ), though it seems to start a bit slower (seem to be the debug version since it's 2MB). Thanks for the hint. 



#12
evilsephiroth

evilsephiroth

    InsanelyMac Protégé

  • Members
  • Pip
  • 34 posts

I didn't know about kraxel. Just tested it, works fine ( OVMF-pure-efi.fd ), though it seems to start a bit slower (seem to be the debug version since it's 2MB). Thanks for the hint. 

 

Well, if this is working with pure ovmf, I should thank you :D I hate not having DRI on my host using i915 patch qemu + chameleon... Time to go UEFI.

 

I'm posting results later... Downloading El Capitan from my macbook air :D 

 

If all works without problems, I think I'll  write a guide for the setup and also converting the qemu commandline in a libvirt xml vm (here and also on Archlinux Wiki that is my distro :D)



#13
waschbenzin

waschbenzin

    InsanelyMac Protégé

  • Members
  • PipPip
  • 68 posts

I also wanted to get rid of the kernel patches and switch to a completely UEFI system :-).

 

BTW: You don't need to go the way around installing in VirtualBox first. I successfully installed a version from a virtual hard disk I created using the createinstallmedia command inside the El Capitan.app. No modifications necessary :). After the first restart, just launch the installer again and it will resume the installation.



#14
evilsephiroth

evilsephiroth

    InsanelyMac Protégé

  • Members
  • Pip
  • 34 posts

I also wanted to get rid of the kernel patches and switch to a completely UEFI system :-).

 

BTW: You don't need to go the way around installing in VirtualBox first. I successfully installed a version from a virtual hard disk I created using the createinstallmedia command inside the El Capitan.app. No modifications necessary :). After the first restart, just launch the installer again and it will resume the installation.

Well, you lost me... :D I thought createinstallmedia targets only device... Did you use a .img file mounted with disk utility?



#15
waschbenzin

waschbenzin

    InsanelyMac Protégé

  • Members
  • PipPip
  • 68 posts

I just wasn't clear. I created the install media using the createinstallmedia command. I than attach that image to the vm and was able to install from that media to another virtual hard disk (using the QEMU, OVMF, Clover VM described above). 



#16
evilsephiroth

evilsephiroth

    InsanelyMac Protégé

  • Members
  • Pip
  • 34 posts

I just wasn't clear. I created the install media using the createinstallmedia command. I than attach that image to the vm and was able to install from that media to another virtual hard disk (using the QEMU, OVMF, Clover VM described above). 

hmm so it's possibile to create an image from createinstallmedia instead of directing writes only to usb? RTFM for me by the way :D



#17
waschbenzin

waschbenzin

    InsanelyMac Protégé

  • Members
  • PipPip
  • 68 posts

I'm not sure... I created a usb drive with createinstallmedia, dumped it, and attached the dump to the vm as a virtual machine to install El Capitan. Hope this resolves any confusion :) .

 

(If you are on a virtual mac already you can probably create a virtual install media to a virtual disk ;-) ) 



#18
evilsephiroth

evilsephiroth

    InsanelyMac Protégé

  • Members
  • Pip
  • 34 posts

I'm not sure... I created a usb drive with createinstallmedia, dumped it, and attached the dump to the vm as a virtual machine to install El Capitan. Hope this resolves any confusion :) .

 

(If you are on a virtual mac already you can probably create a virtual install media to a virtual disk ;-) ) 

 

Ok now it's clear. Create install media, dd to have the raw dump and attached to the vm resulting as usb drive. Perfect. Thanks 



#19
waschbenzin

waschbenzin

    InsanelyMac Protégé

  • Members
  • PipPip
  • 68 posts

I hope it works! :) If you have any trouble just ask and I'll try to help. Looking forward to your explaintion for the libvirt thingy. Might that save me from running my Virtual machine as root? :unsure:



#20
evilsephiroth

evilsephiroth

    InsanelyMac Protégé

  • Members
  • Pip
  • 34 posts

well basically yes... The good thing around libvirt is that is managed with virt-manager... no more scripts, command line but only plain xml edited and viewed with virsh daemon... virsh edit vmName. 

Virt-Manager makes really easy to add devices,controllers,hard disk,cdrom,host device,host usb devices,etc because is graphical... Other than that, libvirt + virt-manager runs as a service so it's possible to run also vm at boot.

 

Compared to qemu scripts it's a cleaner solution...

 

this is the example from my win 8.1 ovmf.

<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
  <name>win8.1</name>
  <uuid>6efc8a3c-5c45-4d51-9fc6-a086d3e267b2</uuid>
  <memory unit='KiB'>4194304</memory>
  <currentMemory unit='KiB'>4194304</currentMemory>
  <vcpu placement='static'>2</vcpu>
  <os>
    <type arch='x86_64' machine='pc-i440fx-2.5'>hvm</type>
    <loader readonly='yes' type='pflash'>/usr/share/edk2.git/ovmf-x64/OVMF_CODE-pure-efi.fd</loader>
    <nvram>/var/lib/libvirt/qemu/nvram/win8.1_VARS.fd</nvram>
    <bootmenu enable='yes'/>
  </os>
  <features>
    <acpi/>
    <apic/>
    <pae/>
    <hyperv>
      <relaxed state='on'/>
      <vapic state='on'/>
      <spinlocks state='on' retries='8191'/>
    </hyperv>
    <kvm>
      <hidden state='on'/>
    </kvm>
  </features>
  <cpu mode='custom' match='exact'>
    <model fallback='allow'>Haswell</model>
  </cpu>
  <clock offset='localtime'>
    <timer name='rtc' tickpolicy='catchup'/>
    <timer name='pit' tickpolicy='delay'/>
    <timer name='hpet' present='no'/>
    <timer name='hypervclock' present='yes'/>
  </clock>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>restart</on_crash>
  <pm>
    <suspend-to-mem enabled='no'/>
    <suspend-to-disk enabled='no'/>
  </pm>
  <devices>
    <emulator>/usr/sbin/qemu-system-x86_64</emulator>
    <disk type='block' device='disk'>
      <driver name='qemu' type='raw' cache='none' io='threads'/>
      <source dev='/dev/mapper/vgSSD-logicSSD'/>
      <target dev='vda' bus='virtio'/>
      <boot order='3'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
    </disk>
    <disk type='block' device='disk'>
      <driver name='qemu' type='raw' cache='none' io='threads'/>
      <source dev='/dev/mapper/vgData-logicVirtual'/>
      <target dev='vdb' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
    </disk>
    <controller type='usb' index='0' model='ich9-ehci1'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x7'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci1'>
      <master startport='0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0' multifunction='on'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci2'>
      <master startport='2'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x1'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci3'>
      <master startport='4'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x2'/>
    </controller>
    <controller type='pci' index='0' model='pci-root'/>
    <controller type='ide' index='0'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
    </controller>
    <interface type='network'>
      <mac address='52:54:00:76:8a:69'/>
      <source network='default'/>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>
    <serial type='pty'>
      <target port='0'/>
    </serial>
    <console type='pty'>
      <target type='serial' port='0'/>
    </console>
    <input type='tablet' bus='usb'/>
    <input type='mouse' bus='ps2'/>
    <input type='keyboard' bus='ps2'/>
    <graphics type='vnc' port='-1' autoport='yes'/>
    <video>
      <model type='vga' vram='16384' heads='1'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
    </video>
    <hostdev mode='subsystem' type='pci' managed='yes'>
      <source>
        <address domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
      </source>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
    </hostdev>
    <hostdev mode='subsystem' type='pci' managed='yes'>
      <source>
        <address domain='0x0000' bus='0x01' slot='0x00' function='0x1'/>
      </source>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
    </hostdev>
    <memballoon model='virtio'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
    </memballoon>
  </devices>
  <qemu:commandline>
    <qemu:arg value='-cpu'/>
    <qemu:arg value='host,hv_vendor_id=deadbeef,kvm=off'/>
  </qemu:commandline>
</domain>







1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users

© 2017 InsanelyMac  |   News  |   Forum  |   Downloads  |   OSx86 Wiki  |   Designed by Ed Gain  |   Logo by irfan  |   Privacy Policy