Tuesday, February 10, 2015

Building an OS X vagrant VMware Fusion VM

Install VMWare Fusion, vagrant, pay money to buy the vagrant vmware plugin.  Follow the instructions in the email to install the plugin and download and install the license, something like:

vagrant plugin install vagrant-vmware-fusion
vagrant plugin license vagrant-vmware-fusion ~/license.lic
This blog has great instructions to build the OS X base box. Boiling it down:
  • Install the base OS in VMWare Fusion with user/pass of vagrant/vagrant. This is fairly easy with modern VMware Fusion and an installer dmg.
  • Install VMWare tools from the VMWare menu.
  • Install all updates:
    sudo softwareupdate --install --all
  • If you want to be able to install and use Homebrew, install the relevant Command Line Tools for XCode from apple (developer account required).
  • If you want to be able to make packages, copy PackageMaker.app to /Applications from the Auxiliary Tools for XCode Late - July 2012 from apple (developer account required).
  • Enable remote logon (i.e. SSH) via System Preferences > Sharing
  • Setup passwordless sudo, vagrant ssh, and ssh config as vagrant recommends.
  • If you created any snapshots during this process, delete them
  • Set the free disk space to zero (not sure this is actually necessary, but the original post claims better compression):
    $ diskutil secureErase freespace 0 Macintosh\ HD
    $ sudo halt
    
  • Defrag and compress as vagrant recommends:
    cd ~/Documents/Virtual Machines.localized/OS X 10.8.vmwarevm
    /Applications/VMware\ Fusion.app/Contents/Library/vmware-vdiskmanager -d Virtual\ Disk.vmdk
    /Applications/VMware\ Fusion.app/Contents/Library/vmware-vdiskmanager -k Virtual\ Disk.vmdk
    
  • Copy the relevant files to a new directory:
    mkdir ~/vagrantbox
    cd ~/vagrantbox/
    cp Virtual\ Disk.vmdk OS\ X\ 10.8.nvram OS\ X\ 10.8.vm* .
    
  • Create a basic metadata.json
    echo '{"provider":"vmware_fusion"}' > metadata.json
    
  • Zip it up:
    tar -cvzf OS_X_10.8.5.box ./*
    
  • Add it to vagrant:
    vagrant box add OS_X_10.8.5 OS_X_10.8.5.box
    
  • Add a config to your Vagrantfile:
      config.vm.define "OS_X_10.8.5" do |box|
        box.vm.box = "OS_X_10.8.5"
        # Random keypair generation and insertion doesn't seem to work on OS X
        box.ssh.insert_key = false
        box.vm.provider "vmware_fusion" do |v|
          v.vmx["memsize"] = "4096"
          v.vmx["numvcpus"] = "2"
        end
      end
    
  • Try it out:
    vagrant up OS_X_10.8.5
If you're seeing this error message you didn't install the vmware fusion vagrant plugin:
The provider 'vmware_fusion' could not be found, but was requested to
back the machine 'OS_X_10.8.5'. Please use a provider that exists.

No comments: