Recently when working with a client we encountered a situation where it would be beneficial run a Mac VM on our Mac laptops, so I decided to investigate. I was in luck! It turns out this is actually really easy to do.
To get started, download Yosemite from the App Store.
Fair warning: the download is ~5.5GB. It took me about half an hour to download, but depending on your connection speed your mileage may vary.
- 2015 Macbook Pro
- 16 GB RAM
- 2.5 GHz i7
- 512 GB SSD
- VirtualBox v4.3.x
The following instructions are heavily borrowed from frdmn's notes blog with additional notes added as needed.
Creating the Mac OS X Disk Image
iesd, to customize OS X InstallESD:
gem install iesd
- Turn install image into base system:
iesd -i "/Applications/Install OS X Yosemite.app" -o yosemite.dmg -t BaseSystem
- Convert into UDSP (sparse image) format:
hdiutil convert yosemite.dmg -format UDSP -o yosemite.sparseimage
- Mount the InstallESD:
hdiutil mount "/Applications/Install OS X Yosemite.app/Contents/SharedSupport/InstallESD.dmg"
- Mount the sparse image:
hdiutil mount yosemite.sparseimage
- Copy the base system into the sparse image:
cp "/Volumes/OS X Install ESD/BaseSystem."* "/Volumes/OS X Base System/"
- Unmount InstallESD:
hdiutil unmount "/Volumes/OS X Install ESD/"
- Unmount the sparse image:
hdiutil unmount "/Volumes/OS X Base System/"
- Unmount both mounted disks:
diskutil unmountDisk $(diskutil list | grep "OS X Base System" -B 4 | head -1)
diskutil unmountDisk $(diskutil list | grep "OS X Install ESD" -B 4 | head -1)
- If you have difficulty/receive an error, you can also do this in Disk Utility. "Right" click on the disk image (either
yosemite.sparseimage) and then select
Eject Disk Image. Repeat for the other disk as needed.
- Convert back to the UDZO compressed image format:
hdiutil convert yosemite.sparseimage -format UDZO -o yosemitevagrantbox.dmg
What to do if you encounter the this error on the last step:
hdiutil: detach failed - No such file or directory
- Remount the sparse image file. One way do to this is to open Finder and double click on the sparse image file.
hdiutil detachinstead of
hdiutil detach /Volumes/OS\ X\ Base\ System/
Creating the VM in VirtualBox
- Click "New" or
cmd+Nto create a new VM
- Give it a name, select
Type: Mac OS Xand
Version: Mac OS X (64-bit)if these are not populated for you (they will be if you use "Mac" in the name). Click continue.
- Default of 2 GB of RAM is adequate for a quick test, but if you plan on using the VM for more than 5 seconds I recommend 4 GB if you can spare it. Otherwise the lag is really frustrating. In any event, click Continue.
- Note if you change the RAM to 4 GB you will need to change your chipset later.
- If you do not already have a virtual hard drive leave the default selection and click "create".
- I used VDI, click Continue.
- I left the disk as dynamically allocated. Click Continue.
- I left the default 20 GB. Click Create.
- If you upped your RAM, "right" click on the new VM and click "Settings". Then go to System -> Motherboard to change the chipset to PIIX3. Feel free remove "Floppy" from the boot order while you're in there.
- "Right" click on the new VM and click "Start".
- Select the disk image as an "optical disk":
- You do not need to create an ISO, although if you do it will still run normally. If you would like to create an ISO just run this command:
hdiutil convert yosemitevagrantbox.dmg -format UDTO -o yosemitevagrantbox && mv yosemitevagrantbox.cdr yosemitevagrantbox.iso
- Wait a few minutes while the installer runs. Grab a coffee?
- Once the installer starts go ahead and select your language.
- Go into Disk Utility and create a formatted partition. Instructions for how to do this are in the "Creating a formatted partition..." section below.
- When prompted, install on the partition you created in the previous step.
- Go through prompts as normal (iCloud, etc.). I personally didn't sign into iCloud/etc. for a test VM.
Creating a formatted partition with Disk Utility
- Start Disk Uility:
- Name & Apply the partition+format:
- Click Partition:
Make sure to use the partition for the install:
Enjoy your test VM! Create and destroy at will! Muhahahhaaha.