Giter VIP home page Giter VIP logo

osx-vm-templates's Introduction

OS X templates for Packer and VeeWee

This is a set of templates and scripts that will prepare an OS X installer media that performs an unattended install for use with Packer and VeeWee. These were originally developed for VeeWee, but support for the VeeWee template has not been maintained since Packer's release and so it is only provided for historical purposes.

The machine is also configured for use with Vagrant, using either the Hashicorp VMware Fusion provider or Vagrant's included VirtualBox provider. Use with the Fusion provider requires Vagrant 1.3.0, and use with the VirtualBox provider requires Packer 0.6.2 (unreleased) and Vagrant 1.6.3 if using the Rsync file sync mechanism. Note that the VeeWee template also does not have any VirtualBox support.

While I'd prefer to keep only a single template.json for now, because the VirtualBox template requires 0.6.2 which is unreleased, the two builders have been split into two templates. They will be merged back together once 0.6.2 is released. The VirtualBox support requires a new template setting; the open pull request is here.

Provisioning steps that are defined in the template via items in the scripts directory:

Preparing the ISO

OS X's installer cannot be bootstrapped as easily as can Linux or Windows, and so exists the prepare_iso.sh script to perform modifications to it that will allow for an automated install and ultimately allow Packer and later, Vagrant, to have SSH access.

Run the prepare_iso.sh script with two arguments: the path to an Install OS X.app or the InstallESD.dmg contained within, and an output directory. Root privileges are required in order to write a new DMG with the correct file ownerships. For example, with a 10.8.4 Mountain Lion installer:

sudo prepare_iso/prepare_iso.sh "/Applications/Install OS X Mountain Lion.app" out

...should output progress information ending in something this:

-- MD5: dc93ded64396574897a5f41d6dd7066c
-- Done. Built image is located at out/OSX_InstallESD_10.8.4_12E55.dmg. Add this iso and its checksum to your template.

Use with Packer

The path and checksum can now be added to your Packer template or provided as user variables. The packer directory contains a template that can be used with the vmware-iso and virtualbox-iso builders. The veewee directory contains a definition, though as mentioned above it is not currently being maintained.

The Packer template adds some additional VM options required for OS X guests. Note that the paths given in the Packer template's iso_url builder key accepts file paths, both absolute and relative (to the current working directory).

Given the above output, we could run then run packer:

cd packer
packer build \
  -var iso_checksum=dc93ded64396574897a5f41d6dd7066c \
  -var iso_url=../out/OSX_InstallESD_10.8.4_12E55.dmg \
  template.json

You might also use the -only option to restrict to either the vmware-iso or virtualbox-iso builders.

Automated installs on OS X

OS X's installer supports a kind of bootstrap install functionality similar to Linux and Windows, however it must be invoked using pre-existing files placed on the booted installation media. This approach is roughly equivalent to that used by Apple's System Image Utility for deploying automated OS X installations and image restoration.

The prepare_iso.sh script in this repo takes care of mounting and modifying a vanilla OS X installer downloaded from the Mac App Store. The resulting .dmg file and checksum can then be added to the Packer template. Because the preparation is done up front, no boot command sequences, attached devices or web server access is required.

More details as to the modifications to the installer media are provided in the comments of the script.

Supported guest OS versions

Currently the prepare script supports Lion, Mountain Lion, and Mavericks.

Automated GUI logins

For some kinds of automated tasks, it may be necessary to have an active GUI login session (for example, test suites requiring a GUI, or Jenkins SSH slaves requiring a window server for their tasks). The Packer templates support enabling this automatically by using the autologin_vagrant_user user variable, which can be set to anything non-zero, for example:

packer build -var autologin_vagrant_user=yes template.json

This was easily made possible thanks to Per Olofsson's CreateUserPkg utility, which was used to help create the box's vagrant user in the prepare_iso script, and which also supports generating the magic kcpassword file with a particular hash format to set up the auto-login.

VirtualBox support

VirtualBox support is thanks entirely to contributions by Matt Behrens (@zigg) to this repo, Vagrant and Packer.

Caveats

Shared folders

Oracle's support for OS X in VirtualBox is very limited, including the lack of guest tools to provide a shared folder mechanism. If using the VirtualBox provider in Vagrant, you will need to configure the shared folder that's set up by default (current folder mapped to /vagrant) to use either the rsync or nfs synced folder mechanisms. You can do this like any other synced folder config in your Vagrantfile:

Vagrant.configure("2") do |config|
  config.vm.provider "virtualbox" do |vb|
    config.vm.synced_folder ".", "/vagrant", type: "rsync"
  end
end

Additional VM configuration for Packer

So far we've seen that the --cpuidset option needs to be passed to modifyvm as a line in the packer template if a Haswell Intel Mac is used to build the VM, at least as of VirtualBox 4.3.12. It seems to cause a VM crash on at least one older Mac, a Core 2 Duo-based 2010 Mac Mini, though did not cause issues on an Ivy Bridge 2013 iMac I tested. If it's missing on a Haswell Mac, however, the VM hangs indefinitely. This behaviour is likely to change over time as Oracle keeps up with support for OS X guests.

      "vboxmanage": [
        ["modifyvm", "{{.Name}}", "--cpuidset", "00000001", "000306a9", "00020800", "80000201", "178bfbff"],
      ]

Box sizes

A built box with CLI tools, Puppet and Chef is over 5GB in size. It might be advisable to remove (with care) some unwanted applications in an additional postinstall script. It should also be possible to modify the OS X installer package to install fewer components, but this is non-trivial. One can also supply a custom "choice changes XML" file to modify the installer choices in a supported way, but from my testing, this only allows removing several auxiliary packages that make up no more than 6-8% of the installed footprint (for example, multilingual voices and dictionary files).

Alternate approaches to VM provisioning

Mads Fog Albrechtslund documents an interesting method for converting unbooted .dmg images into VMDK files for use with ESXi.

osx-vm-templates's People

Contributors

timsutton avatar mattieb avatar grahamgilbert avatar radeksimko avatar bradfeehan avatar rjocoleman avatar

Watchers

franchino avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.