May 09, 2017 Following I will outline the process I used to create a Hyper-V Windows 10 Vagrant Box. For more info on how I create my Windows development environment, be sure to visit Creating a Windows Development Environment With Packer, Vagrant & Chocolatey. Installing Hyper-V. To start, we need to install Hyper-V.
This page describes the steps for creating a Windows Server 2012
virtualbox
image for use with vagrant
. The end result is a minimal virtualbox image with Windows Server installed and configured such that vagrant rdp
works as expected.vagrant
uses two protocols to interact with the running Windows VM. It uses winrm on port 5985 to control the box programmatically (e.g., when you rename the box in your Vagrantfile
or when you run provisioning). The second protocol is RDP (port 3389) which is used when you remote to the box via vagrant rdp
. Note that the host may well have both ports open and in use to talk to the host's winrm and RDP services, so our example Vagrantfile
allows both of these to autocorrect.In lieu of winrm and RDP, you could install ssh and proceed as you would for any unix guest. Windows does not natively support ssh, but there are a number of ssh servers that are freely available. I won't cover that path here, but a quick google should provide you with several options.
Prerequisites
To get started, you'll need:
- vagrant 1.6.5 or later
- virtualbox (I used 4.3.10)
- a Windows installation ISO
As of this writing (Sept 2014), vagrant 1.6.5 is the latest and is needed to address a bug that causes
vagrant rdp
to crash. If you're using an earlier version, you'll need to run your local RDP client instead of accessing via the vagrant
command line.The Windows 2012 server ISO is available from several sources. I used the evaluation copy, but MSDN instance or fully licensed would be fine. A 180 day evaluation image can be downloaded from Microsoft here. You need to register in order to download. The 180 days starts from the day of install.
Create the Virtualbox Base Image
Setup the Virtualbox
![Box Box](https://miro.medium.com/max/1764/1*StQlLAimfB77rtbDkNiSYg.png)
From the Virtualbox GUI, create a new machine. I used:
- OS Version: Windows 2012 (64 bit)
- 1024Mb (VBX recommends 2048, but you can increase this with
vagrant
) - Create a new 25Gb drive
- with file type VDI (VirtualBox Disk Image).
- I chose to dynamically allocate the hard drive (default) as this allows me to play with the boxes more easily, but you will probably want to pre-allocate for a given application
- You will not be easily able to modify the size of the attached disk via Vagrant, so choose carefully (though you can resize the disk by hand if need be. See https://www.youtube.com/watch?v=bz1qAjQICsA and http://www.virtualbox.org/manual/ch08.html#vboxmanage-modifyvdi. To-do: add a separate page to describe this.)
- After running the wizard to create the box, modify settings as your needs dictate. I use:
- Network defaults to 1 Host Only Adapter; I add a second Host-Only Adapter to communicate with other VM's on a private network
- System->Processor 1 CPU (this is the default)
- Storage->Controller: IDE -- attach the Windows 2012 downloaded ISO image to the DVD drive
- Audio: Disable audio
Install Windows
Now you're ready to run Windows Setup. Start the machine and with the ISO mounted and Windows Setup will launch.
- Set the language appropriately, and click the 'Install now' button
- When prompted to select the operating system, I chose Windows Server 2012 Standard Evaluation (Server with GUI). The GUI is for convenience. You can disable it later if you wish.
- Accept the terms
- Select 'Custom: Install Windows only (advanced)'
- Install on Drive 0 (should be the only choice)
Once the drive has been selected, setup will slog through the download, install and update process. With the GUI, this took about 6 mins on my laptop.
Complete the setup process:
- Enter a password for Administrator. At this point, the password must conform to the standard complexity requirements. We'll fix that shortly.
Configure Basic Windows Settings
Your machine should now be booted. Press
Right-Ctrl Delete
and login as Administrator using the password from above.- remove password complexity requirement (required for a default
vagrant
config)- start a powershell command prompt
- run
secpol.msc
- under Security Settings -> Account Policies -> Password Policy, set
Password must meet complexity requirements
toDisabled
- change the Administrator password
- Press
ctrl-Esc
to access the Start Screen - Click on Administrative Tools and then Computer Management
- Open System Tools -> Local Users and Groups
- Right click on
Administrator
and selectSet Password
- Press
- set timezone
- in Server Manager, Select
Local Server
from the left panel - in the properties panel, scroll to the right and click on the Time Zone, then Change time zone and select your time zone
- in Server Manager, Select
- Turn off messages about Windows SmartScreen: Go to Control Panel -> System and Security -> Action Center and Click 'Turn off messages about Windows SmartScreen'
- Install Virtualbox Guest Additions
- In the Virtualbox GUI, Select Devices->Insert Guest Additions CD image...
- Select Run VBoxWindowsAddions.exe when prompted to choose what to do with the disk
- When setup is complete, the VM will reboot
For convenience, you may want to perform some of the following (optional) steps:
- Run Windows Update (This took about an hour on my machine)
- disable screen saver: http://blog.scosby.com/post/2012/12/13/Disabling-Windows-Server-2012-Lock-Screen-Timeout.aspx
- disable IE Enhanced Security
- set Server Manager to not open on login
- start iexplore and pin it to the taskbar
- There is a list of Helpful Hints for new Windows 2012 users here
At this point, I usually create a clone to make the
vagrant
customizations. This can be done through the Virtualbox GUI.Configure the VM for Vagrant Use
Add a
vagrant
account with password vagrant
and add them to the admin group.- From Server Manager, Click Tools-> Computer Management
- From Computer Management, Expand Local Users and Groups, then Users in the left panel
- Right click Users and select Add User
- User name: vagrant
- Password: vagrant
- Clear User must change password at next logon
- Select User cannot change password and Password never expires
- Click create and close
- Select Groups in the left panel
- Right click Administrators in the right panel
- Click Add...
- In Enter the object names, type vagrant and click OK
Enable rdp
- from PowerShell prompt, type
systempropertiesremote
- select Allow remote connections to this computer
- clear 'allow only from computers running Remote Desktop with NLA'
Enable winrm
- from cmd prompt (not PowerShell prompt), run the following commands
Install PowerShell 4.0 (Optional)
If you plan to use Desired State Configuration (DSC), you will need to install PowerShell 4.0 or later. You can download the appropriate version here: http://www.microsoft.com/en-us/download/details.aspx?id=40855. This install requires a restart.
Package the Virtualbox as a Vagrant Box
Once you have created an appropriate virtualbox image, the following command will package it up as a vagrant box so you can reference it from a
Vagrantfile
.vagrant package --base <name in virtualboxgui> --output <name for Vagrant to use>
The command above creates a file
<name for Vagrant to use>
in the current directory. You can use this pathin a Vagrantfile
by setting the box_url
. For example: