Mac OS VM

Important repo https://github.com/kholia/OSX-KVM

Clean up unused VM disk space

# on guest with Mac OS
cat /dev/zero > zfile; rm zfile

# shutdown VM

# on host
vmware-vdiskmanager -k </path/to/disk.vmdk>

Run Sierra on qemu-kvm

Note

Press Ctrl+F2 to show panel with utilites button

  1. Run next command:

    echo 1 > /sys/module/kvm/parameters/ignore_msrs
    
  2. Create image where mac will be installed:

    qemu-img create -f qcow2 /path/to/Sierra.qcow2 15g
    
  3. Create template sierra.xml:

    <domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
      <name>Sierra</name>
      <title>Sierra</title>
      <description>echo 1 &gt; /sys/module/kvm/parameters/ignore_msrs</description>
      <memory unit='KiB'>2097152</memory>
      <currentMemory unit='KiB'>2097152</currentMemory>
      <vcpu placement='static'>2</vcpu>
      <os>
        <type arch='x86_64' machine='pc-q35-2.4'>hvm</type>
        <kernel>/mnt/data/qemu/bios/enoch_rev2848_boot</kernel>
      </os>
      <features>
        <acpi/>
        <kvm>
          <hidden state='on'/>
        </kvm>
      </features>
      <cpu mode='custom' match='exact'>
        <model fallback='allow'>Penryn</model>
      </cpu>
      <devices>
        <emulator>/usr/bin/qemu-system-x86_64</emulator>
        <disk type='file' device='disk'>
          <driver name='qemu' type='qcow2'/>
          <source file='/mnt/data/qemu/images/Sierra.qcow2'/>
          <target dev='sda' bus='sata'/>
          <!--<shareable/>-->
          <boot order='1'/>
          <address type='drive' controller='0' bus='0' target='0' unit='0'/>
        </disk>
        <interface type='user'>
          <source network='default'/>
          <model type='e1000-82545em'/>
          <address type='pci' domain='0x0000' bus='0x02' slot='0x02' function='0x0'/>
        </interface>
        <input type='mouse' bus='usb'/>
        <input type='keyboard' bus='usb'/>
        <graphics type='vnc' port='-1' autoport='no' listen='127.0.0.1' keymap='en-us'>
          <listen type='address' address='127.0.0.1'/>
        </graphics>
        <video>
          <model type='vmvga' vram='16384' heads='1'/>
          <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/>
        </video>
        <memballoon model='none'/>
      </devices>
      <qemu:commandline>
        <qemu:arg value='-device'/>
        <qemu:arg value='isa-applesmc,osk=ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc'/>
        <qemu:arg value='-smbios'/>
        <qemu:arg value='type=2'/>
        <qemu:arg value='-k'/>
        <qemu:arg value='en-us'/>
        <qemu:arg value='-cpu'/>
        <qemu:arg value='Penryn,vendor=GenuineIntel'/>
        <!--
        <qemu:arg value='-redir'/>
        <qemu:arg value='tcp:5901::5900'/>
        -->
        <!--
        <qemu:arg value='-device'/>
        <qemu:arg value='ide-drive,bus=ide.1,drive=MacDVD'/>
        <qemu:arg value='-drive'/>
        <qemu:arg value='id=MacDVD,if=none,snapshot=on,file=/mnt/data/iso/mac/Sierra_10_12_3.iso'/>
        -->
      </qemu:commandline>
    </domain>
    
  4. Define domain:

    virsh --connect qemu:///system define alice.xml
    
  5. Autostart Sierra (without press Enter)

Add next file to Sierra HD /Volumes/<Sierra_HD>/Extra/org.chameleon.boot.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Timeout</key>
<string>10</string>
<key>EthernetBuiltIn</key>
<string>Yes</string>
<key>PCIRootUID</key>
<string>1</string>
<key>KernelBooter_kexts</key>
<string>Yes</string>
<key>CsrActiveConfig</key>
<string>103</string>
<key>Graphics Mode</key>
<string>1024x768x32</string>
</dict>
</plist>
  1. Allow usb-tablet device
  1. Add vmware svga driver
  • download and install https://sourceforge.net/projects/vmsvga2 on your Mac

  • add the following to /Extra/org.chameleon.Boot.plist:

    <key>Kernel Flags</key>
    <string>vmw_options_fb=0x06</string>
    
  • add -vga vmware to QEMU parameters.

  1. Allow to install apps:

    sudo spctl --master-disable
    

Install Mac OS Sierra on VMWare

  1. Download and run script to unlock your VMWare for run Mac OS https://github.com/DrDonk/unlocker . P.S. Read readme in repo.

Change VM display resolution:

/Library/Application\ Support/VMware\ Tools/vmware-resolutionSet 1920 1080

Disable Mac OS csrutil (SIP) on VMware VM

  1. Start vmware

  2. Select Mac OS guest and power to firmware

  3. In efi menu, enter setup -> config boot options -> add boot options -> select recovery partition -> select boot.efi

  4. At input file description hit <enter> and type in label e.g. “recovery” -> commit changes and exit

  5. Boot from “recovery” and be patient

  6. Follow prompt until you see OS X Utilities menu

  7. At the very top menu select Utilities -> Terminal

  8. In terminal enter:

    csrutil status
    csrutil disable
    csrutil status
    reboot
    

Run Sierra on VirtualBox

Open VirtualBox and click the “New” button. Name your Virtual Machine “macOS Sierra” and choose “Mac OS X” for the operating system and “Mac OS X (64-bit)” for the version (as of this writing, “macOS Sierra” is not offered, but that’s fine.)

Run next command in console:

cd "C:\Program Files\Oracle\VirtualBox\"
VBoxManage.exe modifyvm "macOS Sierra" --cpuidset 00000001 000306a9 04100800 7fbae3ff bfebfbff
VBoxManage setextradata "macOS Sierra" "VBoxInternal/Devices/efi/0/Config/DmiSystemProduct" "MacBookPro11,3"
VBoxManage setextradata "macOS Sierra" "VBoxInternal/Devices/efi/0/Config/DmiSystemVersion" "1.0"
VBoxManage setextradata "macOS Sierra" "VBoxInternal/Devices/efi/0/Config/DmiBoardProduct" "Mac-2BD1B31983FE1663"
VBoxManage setextradata "macOS Sierra" "VBoxInternal/Devices/smc/0/Config/DeviceKey" "ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc"
VBoxManage setextradata "macOS Sierra" "VBoxInternal/Devices/smc/0/Config/GetKeyFromRealSMC" 1

Change Your Resolution By default, your virtual machine will have a resolution of 1024×768, which is not a lot of room to work with. If you try to change the resolution from within macOS, however, you will see no option to do so. Instead, you need to enter a few commands.

Shut down your Virtual Machine by shutting down macOS: click the Apple in the menu bar, then click “Shut Down.” Next, close VirtualBox entirely (seriously, this step will not work if VirtualBox is still open!) and head back to Windows’ Command Prompt as an admin. You need to run the following two commands:

cd "C:\Program Files\Oracle\VirtualBox\"
VBoxManage setextradata "macOS Sierra" "VBoxInternal2/EfiGopMode" N

In the second command, you need to replace the “N” with a number from one to five, depending on what resolution you want:

1 gives you a resolution of 800×600
2 gives you a resolution of 1024×768
3 gives you a resolution of 1280×1024
4 gives you a resolution of 1440×900
5 gives you a resolution of 1920×1200