A short how-to on creating a Windows 10 base box for use with Vagrant and VirtualBox.
vagrant
user with password vagrant
The following settings are necessary for managing your VM with Vagrant.
Open the Command Prompt as Admin
and execute:
# disable uac
> C:\Windows\System32\cmd.exe /k %windir%\System32\reg.exe ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d "0x00000000" /f
# disable enhanced security
> C:\Windows\System32\cmd.exe /k %windir%\System32\reg.exe ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v FilterAdministratorToken /t REG_DWORD /d "0x00000001" /f
> C:\Windows\System32\cmd.exe /k %windir%\System32\reg.exe ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\UIPI /ve /t REG_SZ /d "0x00000001" /f
Open the Command Prompt as Admin
and execute:
# enable remote desktop
> C:\Windows\System32\cmd.exe /k %windir%\System32\reg.exe ADD "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f
# open firewall for remote desktop
> C:\Windows\system32\netsh.exe advfirewall firewall set rule group="remote desktop" new enable=Yes
Set network location to Private:
Open secpol.msc
and go to Network List Manager Policies > Network and set Network Location to Private.
Open the Command Prompt as Admin
and execute:
> winrm quickconfig -q
> winrm set winrm/config/winrs @{MaxMemoryPerShellMB="300"}
> winrm set winrm/config @{MaxTimeoutms="1800000"}
> winrm set winrm/config/service @{AllowUnencrypted="true"}
> winrm set winrm/config/service/auth @{Basic="true"}
> sc config WinRM start=auto
Open the PowerShell as Admin
and execute:
# remove all of the metro apps
> Get-AppXPackage -AllUsers | Remove-AppXPackage
# remove log files
> Get-Childitem "C:\Windows\Logs\dosvc" | Remove-Item -Verbose
# disables the system restore feature
> Disable-ComputerRestore c:
# disable hibernation
> powercfg -h off
# allow Powershell scripts to provision
> Set-ExecutionPolicy -Force -ExecutionPolicy Unrestricted
Download SDelete and open the Command Prompt as Admin
and execute:
# remove recents
> del /F /S /Q %APPDATA%\Microsoft\Windows\Recent\*
# clean up disk space
> C:\Windows\System32\cleanmgr.exe /d c:
# zeros out free space
> C:\SDelete\sdelete64.exe -z c:
Now it's time to shutdown windows.
# shutdown windows
> shutdown /s /t 0
Don't forget to remove unnecessary hardware like audio, usb and CD/DVD and set CPU and RAM to the bare minimum.
Create the base box:
# create base box from VM
$ vagrant package --base <windows 10 VM name> --output Win10x64.box
# add box
$ vagrant box add windows/10 Win10x64.box
# check vagrant boxes
$ vagrant box list
Create and run a test project:
# create project folder
$ mkdir ~/test_project && cd ~/test_project
# initialise the Vagrant environment
$ vagrant init windows/10
# edit Vagrantfile
$ vim Vagrantfile
Vagrantfile:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "windows/10"
config.vm.guest = :windows
config.vm.communicator = "winrm"
# windows installs updates during startup and shutdown
# larger timeouts hopefully prevents bricking the vm
config.vm.boot_timeout = 600
config.vm.graceful_halt_timeout = 600
# port forward WinRM and RDP
config.vm.network :forwarded_port, guest: 3389, host: 3389
config.vm.network :forwarded_port, guest: 5985, host: 5985, id: "winrm", auto_correct: true
# optional
# config.winrm.username = "vagrant"
# config.winrm.password = "vagrant"
# config.vm.provider "virtualbox" do |vb|
# # vb.gui = true
# vb.memory = "2048"
# vb.cpus = 2
# vb.name = "Windows_Vagrant"
# end
end
Run and connect:
# start VM
$ vagrant up
# start rdp client
$ vagrant rdp
Done!