Vagrant – Create a Windows Box

Previous post : Create a Linux Box

In this post we will create our own Windows box. So far we worked with Linux Debian systems. Windows requires a different knowledge and procedure. Here are the steps:

1. Install or use an installed version of windows on Virtualbox. (This may not work on windows versions older than Windows 7)

2. Install Virtualbox addons.

3. Create a user named vagrant and make its password vagrant. Assign it to the administrator group.

4. Open ?Control Panel?. Write UAC in the search box. Change ?User Account Control Settings? and set it to ?Never Notify?

Create a Windows Box

5. Enable RDP: Right click My Computer and click ?Properties?. In the window click ?Remote Settings?
Make sure ?Allow Remote Assistance connections to this computer? checked. ?Allow connection from computers running any version of remote desktop? selected.
Click select users and add user vagrant.

windows box vagrant

6. Start service winrm and set it start automatically.

vagrant windows box

7. Disable windows firewall for all profiles: Domain, Private, Public (Also make your connection profile either home or work.)

8. Open powershell as administrator. Check winrm running.

C:\> get-service winrm

windows winrm

9. Enable powershell for remoting

C:\> Enable-PSRemoting ?force 

10. Open command prompt as admin and execute the commands below:

winrm quickconfig -q  
winrm set winrm/config/winrs @{MaxMemoryPerShellMB="512"}    winrm set winrm/config @{MaxTimeoutms="1800000"}   
winrm set winrm/config/service @{AllowUnencrypted="true"}  
winrm set winrm/config/service/auth @{Basic="true"}

11. If you will use puppet for provisioning download and install puppet from this URL Install puppet agent with default settings. Now windows settings are complete.

12. Switch back to command prompt or terminal in your host machine. To create the box write the command “vagrant package –base virtualmachinename –output boxname”. Example below:

$ vagrant package --base windows7en --output

13. To add the new box to your vagrant: “vagrant box add –name newboxname boxfile”

$ vagrant box add --name windows7

14. Vagrant config example for Windows box:

  config.vm.define "win1" do |win1| = "windows7"
    win1.vm.hostname = "win1"
    win1.vm.communicator = "winrm" "forwarded_port", guest: 3389, host: 3389
    win1.vm.provider "virtualbox" do |vb| = "Windows 7"
      vb.customize ["modifyvm", :id, "--memory", "2048"]
      vb.customize ["modifyvm", :id, "--cpus", "2"]

15. Now test it. You can connect with command “vagrant rdp“.

$ vagrant up
$ vagrant rdp

— The end of post —