Thomas James Just a geek.

Technology, Gadgetry, Photography and Software Development

Create a windows base box for vagrant


Using puppet on windows, one thing has been missing for me, being able to iterate quickly with vagrant. There are a number of articles out there that detail a the steps required to create your own windows base box for vagrant, but unfortunately they’re a whole bunch of manual steps, which doesn’t gel too well with working with an automated environment. So this is my attempt to distil down the steps into as few manual ones as possible.

This has all been tested using the publicly available Windows Server 2008 R2 evaluation VHD for Hyper-V.

The end goal being a vagrant base box that:

  • Includes puppet
  • Has all the necessary setup performed via powershell
  • vagrant up works as expected

You will need the latest versions of the following installed as well:

The Hyper-V VHD unfortunately doesn’t work as-is with the default VirtualBox setting used when creating a new VM, so use the following bash script to setup the needed VirtualBox VM. The main change required is connecting the VHD to an IDE Controller not the default SATA one the wizard will create.



Save the gist locally as in the directory you want to use as your working folder, the gist will do the following:

  • Boot VM via ./ script (note, only tested on a mac)
  • Login as Administrator/Pass@word1
  • Allow installation to complete, consent to the reboot
  • Login as Administrator/Pass@word1
  • Set the Timezone
  • Install the VirtualBox Guest Additions
  • Run the vagrant_prepare.ps1 gist from the command shell
@powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString(''))"

Once the preparation script is complete:

  • Activate Windows for 180 days of use.
  • Reset password expiry on administrator
  • Shutdown the VM so that a vagrant base box can be created

Back in the terminal window where was run from, execute the following, it will take a while:

NAME=$(basename -s .vhd *.vhd)
VBOX=$(VBoxManage showvminfo "$NAME" | grep "Config file" | cut -d : -f 2 -s | sed 's/^ *//g')
vagrant package --base "${VBOX}" --output
vagrant box add windows-server-2008-r2-eval

If you are rebuilding an earlier box, you’ll need to remove the exiting one before running the above commands:

vagrant box remove windows-server-2008-r2-eval

To create your new windows vagrant instance:

vagrant init windows-server-2008-r2-eval
# alter Vagrant file according to
vagrant up

You now have a fully functioning vagrant controlled windows box for the next 180 days, with the puppet provisioner baked in.



comments powered by Disqus
  • profile for Thomas James on Stack Exchange, a network of free, community-driven Q&A sites

4g android appharbor apple atrix aws barcamp beer blog brew-smith coding conferencing deployfu docpad ec2 engineering fusion-garage grid10 homebrew hp-mini information insertdatahere ipad joojoo kernel knowroaming leadership linux macbook-air moncai mono n900 ndc netduino netmf open-source opinion pcengines-apu poor-experience professional public-speaking rant ravendb reflection router singapore talks travel ubuntu unconference vagrant vps wifi windows yubikey