The time has come to look at OS X VMs. I’d put this off for a while as the amount of development I’d have to do on OS X didn’t warrant the effort. But curiosity, easier management of upgrades and the need to learn new things has spurred me on this path of learning.
So without attempting to chew too much in one go my first attempt is to create a VM image using Packer.
Why Packer? From one config you can create images for different platforms – like VMware, VirtualBox, AWS etc.
For my own learnings I was creating images for VMware.
Have packer installed. If using homebrew simply run <pre class="lang:sh decode:true">brew install packer</pre>
- Have VMware Fusion or Fusion Pro installed
- Clone the os-x-vm-template project
- Have the installation file of OS X available. If you don’t you can download it as follows:
- Open App Store
- Search for the OS – in my case I looked for ‘os x yosemite’
- Click download. It’ll download to /Applications
Creating the image
- Go to wherever you cloned the os-x-vm-template project.
- Run the prepare_iso.sh script <pre class="lang:sh decode:true">sudo prepare_iso/prepare_iso.sh /Applications/Install\ OS\ X\ Yosemite.app output</pre>
This will finish and chuck out some output similar to: <pre class="lang:sh decode:true">-- Fixing permissions.. -- Checksumming output image.. -- MD5: 35a19a9a6462229d203aaa63ef848960 -- Done. Built image is located at output/OSX_InstallESD_10.10.4_14E46.dmg. Add this iso and its checksum to your template.</pre>
Copy the template.json file in the packer directory <pre>cp packer/template.json packer/osx-template-vmware-iso.json</pre>
- Open the osx-template-vm-ware-iso.json file and:
- Remove the builder entries for parallels-iso and virtualbox-iso.
- Modify the iso_checksum and iso_url variable values to match the ones spat out in Step 2. E.g.: <pre class="lang:sh decode:true">… “iso_checksum”: “35a19a9a6462229d203aaa63ef848960”, “iso_url”: “/Users/deline/Desktop/packer/osx-vm-templates/output/OSX_InstallESD_10.10.4_14E46.dmg”, …</pre>
Validate that your config file looks okay: <pre class="lang:sh decode:true">cd packer packer validate osx-template-vmware-iso.json</pre>
- If your template is all good the next step is to create the image <pre class="lang:sh decode:true">packer build osx-template-vmware-vmx.json</pre>
This step will take a while as it’ll create a new VM, install and configure OS X then export it as a new vm. The output will be created in a folder of the same name prefixed with output – e.g. output-vmware-iso.</li> </ol> Next up I’ll look at using this image as the image as the base source image to create other more specific images. Why do I want to do this? I want the ability to easy trash and recreate OS X environments but I want this to occur fairly quickly. By keeping a base source image I won’t need to sit through the OS X installation each time I need to start with a ‘fresh’ VM.