Skip to content

Instantly share code, notes, and snippets.

@rrotter
Last active July 20, 2017 01:07
Show Gist options
  • Save rrotter/c2bf32fb4c613143a8331eb0303164d2 to your computer and use it in GitHub Desktop.
Save rrotter/c2bf32fb4c613143a8331eb0303164d2 to your computer and use it in GitHub Desktop.
LaunchAgent to fix dev paths in vmdk for "Boot Camp" disk on hackintosh

vmdkcheck

LaunchAgent to fix dev paths in vmdk for "Boot Camp" disk on hackintosh. If your motherboard can't enumerate disk consistantly this will help VMware find your Windows partition.

  1. Put the ruby script somewhere.
  2. Put your own UUID and VMDK paths in the script.
  3. Install the plist in /Library/LaunchAgents
  4. Fix the path in the plist to match where your script is.
<?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>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/brew/bin:/usr/local/sbin</string>
</dict>
<key>Label</key>
<string>com.reddit.hackintosh.vmdkcheck</string>
<key>ProgramArguments</key>
<array>
<string>/Users/Shared/VMware/bin/vmdk_check.rb</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
#!/usr/bin/env ruby
# Fixes partition dev node path in VMDK. Assumes you are using full disk, not a
# partition (like disk2, not disk2s4).
# Path to a your rawdisk vmdk file (generated by vmware-rawdiskCreator)
# VMDK_PATH = "/Users/$USER/Documents/VMWare Virtual Machines.localized/Boot Camp.vmwarevm/Virtual Disk.vmdk"
# VMDK_PATH = "/Users/Shared/VMware/Boot Camp.vmwarevm/Virtual Disk.vmdk"
VMDK_PATH = "/Path/To/VM.vmwarevm/VM.vmdk"
# UUID of physical partition of your Windows install.
# Get this w/ `diskutil info /dev/diskXsY`
# note that this is the a partition and not the full disk
# we want the full disk, but it doesn't have a UUID
PART_UUID = "ENTER-UUID-HERE"
def get_disk_dev(cmd)
r=`#{cmd}`
raise "#{$0}: Reading current status of VMDK failed. Aborting." if($?!=0)
m = r.match(/\/dev\/disk\d+/)
raise "#{$0}: Reading current status of VMDK failed. Aborting." if(!m)
m.to_s
end
vmdk_dev = get_disk_dev("grep dev '#{VMDK_PATH}'|grep -v '^#'")
proper_dev = get_disk_dev("diskutil info #{PART_UUID} | grep 'Device Node'")
if(vmdk_dev != proper_dev)
replacement_file = ""
File.open(VMDK_PATH, "r") do |f|
f.each_line do |line|
if(line.match(/^RW \d+ FLAT "\/dev\/disk\d+" /))
replacement_file += "# "+line
replacement_file += line.sub(/\/dev\/disk\d+/,proper_dev)
else
replacement_file += line
end
end
end
File.write(VMDK_PATH, replacement_file)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment