Stark & Wayne
  • by Quintessence Anx

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.

My Setup

The following instructions are heavily borrowed from frdmn's notes blog with additional notes added as needed.

Creating the Mac OS X Disk Image

  1. Install iesd, to customize OS X InstallESD:
    gem install iesd
  2. Turn install image into base system:
    iesd -i "/Applications/Install OS X" -o yosemite.dmg -t BaseSystem
  3. Convert into UDSP (sparse image) format:
    hdiutil convert yosemite.dmg -format UDSP -o yosemite.sparseimage
  4. Mount the InstallESD:
    hdiutil mount "/Applications/Install OS X"
  5. Mount the sparse image:
    hdiutil mount yosemite.sparseimage
  6. Copy the base system into the sparse image:
    cp "/Volumes/OS X Install ESD/BaseSystem."* "/Volumes/OS X Base System/"
  7. Unmount InstallESD:
    hdiutil unmount "/Volumes/OS X Install ESD/"
  8. Unmount the sparse image:
    hdiutil unmount "/Volumes/OS X Base System/"
  9. 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)
  1. Convert back to the UDZO compressed image format:
    hdiutil convert yosemite.sparseimage -format UDZO -o yosemitevagrantbox.dmg

Common Error

What to do if you encounter the this error on the last step:
hdiutil: detach failed - No such file or directory

  1. Remount the sparse image file. One way do to this is to open Finder and double click on the sparse image file.
  2. Use hdiutil detach instead of hdiutil unmount:
    hdiutil detach /Volumes/OS\ X\ Base\ System/
  3. Re-run hdiutil convert command.

Creating the VM in VirtualBox

  1. Click "New" or ctrl+N/cmd+N to create a new VM
  2. Give it a name, select Type: Mac OS X and 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.
  3. 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.
  1. If you do not already have a virtual hard drive leave the default selection and click "create".
  2. I used VDI, click Continue.
  3. I left the disk as dynamically allocated. Click Continue.
  4. I left the default 20 GB. Click Create.
  5. 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.
  6. "Right" click on the new VM and click "Start".
  7. Select the disk image as an "optical disk":
    Select disk image
  1. Wait a few minutes while the installer runs. Grab a coffee?
  2. Once the installer starts go ahead and select your language.
  3. Go into Disk Utility and create a formatted partition. Instructions for how to do this are in the "Creating a formatted partition..." section below.
  4. When prompted, install on the partition you created in the previous step.
  5. 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

  1. Start Disk Uility:
    Start Disk Utility
  2. Select 1 Parition:

  3. Name & Apply the partition+format:

  4. Click Partition:

Make sure to use the partition for the install:

Install Partition

What next?

Enjoy your test VM! Create and destroy at will! Muhahahhaaha.

Find more great articles with similar tags author-qanx vagrant mac-vm