Creating a Windows XP Vagrant box

Vagrant is a great tool to use when creating test boxes. Although it is commonly used with *nix servers, but a lot of the time we may want to test other things such as a Windows box. Because of obvious licensing issues there are NO Windows Vagrant boxes published online.

Vagrant is a great tool to use with VirtualBox, until recently they added VMWare Fusion and Workstation for a price. VirtualBox is free and is an easy tool to get started with when using Vagrant.

Install vagrant-windows plugin

Creating a Base Box

Out of the box the vagrant-windows plugin supports the following Windows Operating Systems:

Windows 7

Windows 8

Windows Server 2008

Windows Server 2008 R2

Windows Server 2012

So setting up XP will take a little more configuration. If you are setting up one of the supported operating systems please follow the guide on the vagrant-windows page.

Install XP

This guide is not created to show you how to create a Windows XP guest on VirtualBox but here are is what I used for creating my guest box.

Name: XP-BASE-BOX (We will need the name to create the base box)

Memory: 512MB

Hard Drive: 20GB (Dynamically Allocated)

You can obviously change these settings as you see fit. But these settings are what we used to hopefully help make the vagrant box as small as possible. Our vagrant box ended up being ~2GB after the fact.

Needed software for XP

Once you have your base box created we need to install a couple things to make it work with Vagrant.

Symbolic Link Driver

The symbolic link driver makes it possible to share folders between your computer and the vagrant box, checkout Vagrant Synced Folders. Once you have downloaded the driver open the .cab file and copy all the files (ln.exe, senable.exe, symlink.sys) to C:\WINDOWS directory. Open up the command prompt and type the following:

> cd C:\WINDOWS
C:\WINDOWS> senable.exe install

Windows 7 came with a utility called mklink that creates symbolic links like ln for *nix type systems. Once again vagrant-windows supports Windows 7 and up so it will be looking for the mklink to create that synced folder. In order to fake mklink for vagrant-window we need to do the following steps.

The Vagrant File

Vagrant loads multiple Vagrantfiles read the following page to understand vagrant file load ordering, Vagrantfile Load Order. We can actually package a Vagrantfile with the box. Anything that is in the Vagrantfile that you package with the box does not need to be in the project directory Vagrantfile. Here’s the Vagrantfile we will be packing with the base box. (I created a XP folder inside my ~/Documents folder on my mac and put the Vagrantfile in it.)

Creating the vagrant box

Breakdown

The --base command takes an argument of VirtualBox machine name to package as a base box.

--output windowsxp.box

The --output command takes an argument to name you newly packaged box. If you don’t use the --output command it defaults to package.box.

--vagrantfile ./Vagrantfile

The --vagrantfile command will package a Vagrantfile with your new base box.

Conclusion

Creating vagrant boxes aren’t that hard to do, especially for operating systems that are still supported. The truth is we are unfortunately still using XP at work and using a vagrant box to test things is a lot quicker than imaging a machine. We use Puppet to manage all our desktops/laptops at work and having a way to test all our platforms using VirtualBox makes it so simple. In a future post I will discuss how we use this vagrant box.