Skip to content

Instantly share code, notes, and snippets.

@dragon788
Last active November 23, 2019 04:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dragon788/60d1a9c97e8bf6417a1e04c143f9ebfc to your computer and use it in GitHub Desktop.
Save dragon788/60d1a9c97e8bf6417a1e04c143f9ebfc to your computer and use it in GitHub Desktop.
"Quickly" getting a Windows VM setup for dev and testing using free tools and evaulation licenses

Modern.ie is behind the times, Microsoft/EdgeOnWindows on the VagrantUp box site is WAY out of date, what's a guy to do? Build your own!

Now to build these you'll need Packer and the virtualization tool you are building the box for, Virtualbox or VMware Workstation (or Parallels on Mac). Packer is written in Go and doesn't really require any external dependencies. If you are on Linux you can possibly find Packer in your package management tool, but it is best to grab the latest binary from https://packer.io and extract it to /usr/local/bin/ as packer or put it in ~/.local/bin/ if you have that in your PATH variable. On macOS use Homebrew from https://brew.sh to install with brew install packer. On W

curl -L https://releases.hashicorp.com/packer/1.4.5/packer_1.4.5_linux_amd64.zip -o ~/Downloads/packer.zip
unzip packer.zip
sudo install -m 755 packer /usr/local/bin/ # Allows any user to run it
sudo apt install virtualbox # or grab it from the https://virtualbox.org website

Go grab the excellent Bento templates courtesy of Chef and their amazing collection that they use themselves for testing Chef (an excellent configuration management tool) and ensuring it works on as many platforms as possible. https://github.com/chef/bento

git clone https://github.com/chef/bento
cd bento
cd packer_templates/windows
packer build --only=virtualbox-iso windows-10.json
# This takes ages, but that is because it installs a lot of Windows Updates
# You can monitor the progress and see if anything got stuck by opening the Virtualbox Manager application

Once this rather long process completes, you should have a windows-10-virtualbox.box maybe in this same directory. Now you'll need Vagrant from https://vagrantup.com. You might use a package manager like Homebrew for macOS or Chocolatey for Windows, but for Linux I'd recommend avoiding apt-get and just grabbing it from the site, because some distributions have a really old version that will just cause you grief.

vagrant box add --name MyWin10 windows-10-virtualbox.box
cd $HOME
mkdir my-win10-vagrant
cd my-win10-vagrant
vagrant init MyWin10
# open Vagrantfile in your favorite editor and uncomment the provider.virtualbox and corresponding end line, and the vb.gui = true line
vagrant up # we'll need to tweak the Vagrantfile, but always worth trying to see if Chef/Hashicorp have made magic

If your vagrant up complained about a timeout trying to communicate with the box while it was starting, you'll need to check the port forwards and communication methods. There are a lot of posts on StackOverflow about this, as well as the Vagrant and Packer user groups, but I've found it sometimes easiest to look at other Vagrantfile configs out on GitHub that include windows in the code.

Once you have gotten your box booting, you will see that it has a triggered a countdown, and will self destruct in ~90 days!!! Well sort of, after 90 days the evaulation version of Windows expires, so it will only run for an hour at a time, and you'll need to export any data you want before you delete and recreate it. The beauty of how we built it, is that we can easily add some scripts to the Vagrantfile that will only execute on the first boot of the box to provision it, and this will allow us to automate some of the boring stuff like installing software and tweaking the Windows settings to be a little more useful to power users.

Funny enough, developers working at Microsoft have encountered the same pain, so they have a repository for doing this setup easily at https://github.com/microsoft/windows-dev-box-setup-scripts and they use the same tooling I would suggest, which is Chocolatey and Boxstarter and a little bit of Powershell.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment