From 3dd65ec23b3c3281611050fe0bd544d2a28107a9 Mon Sep 17 00:00:00 2001 From: Matt Wrock Date: Tue, 29 Sep 2015 15:26:17 -0700 Subject: [PATCH 1/6] initial windows nano commit --- scripts/windows/Autounattend.xml | 158 ++++++++++++++++++++++++++++++ scripts/windows/SetupComplete.cmd | 5 + scripts/windows/nano_cleanup.ps1 | 37 +++++++ scripts/windows/nano_create.ps1 | 39 ++++++++ scripts/windows/postunattend.xml | 49 +++++++++ windows-nano-tp3.json | 51 ++++++++++ 6 files changed, 339 insertions(+) create mode 100644 scripts/windows/Autounattend.xml create mode 100644 scripts/windows/SetupComplete.cmd create mode 100644 scripts/windows/nano_cleanup.ps1 create mode 100644 scripts/windows/nano_create.ps1 create mode 100644 scripts/windows/postunattend.xml create mode 100644 windows-nano-tp3.json diff --git a/scripts/windows/Autounattend.xml b/scripts/windows/Autounattend.xml new file mode 100644 index 000000000..044f1af44 --- /dev/null +++ b/scripts/windows/Autounattend.xml @@ -0,0 +1,158 @@ + + + + + + en-US + + en-US + en-US + en-US + en-US + en-US + + + + + + + Primary + 1 + 350 + + + 2 + Primary + 15360 + + + 3 + Primary + true + + + + + true + NTFS + + 1 + 1 + + + NTFS + + E + 2 + 2 + + + NTFS + + C + 3 + 3 + + + 0 + true + + + + + + + /IMAGE/NAME + Windows Server 2012 R2 SERVERDATACENTERCORE + + + + 0 + 3 + + + + + + OnError + + true + Vagrant + Vagrant + + + + + + 1 + + + false + false + + + + + en-US + en-US + en-US + en-US + + + + true + true + true + true + true + Home + 1 + + UTC + + + vagrant + true</PlainText> + </AdministratorPassword> + <LocalAccounts> + <LocalAccount wcm:action="add"> + <Password> + <Value>vagrant</Value> + <PlainText>true</PlainText> + </Password> + <Group>administrators</Group> + <DisplayName>Vagrant</DisplayName> + <Name>vagrant</Name> + <Description>Vagrant User</Description> + </LocalAccount> + </LocalAccounts> + </UserAccounts> + <AutoLogon> + <Password> + <Value>vagrant</Value> + <PlainText>true</PlainText> + </Password> + <Enabled>true</Enabled> + <Username>vagrant</Username> + </AutoLogon> + <FirstLogonCommands> + <SynchronousCommand wcm:action="add"> + <CommandLine>cmd.exe /c C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File a:\nano_create.ps1</CommandLine> + <Order>1</Order> + </SynchronousCommand> + </FirstLogonCommands> + </component> + </settings> + <settings pass="specialize"> + <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-ServerManager-SvrMgrNc" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> + <DoNotOpenServerManagerAtLogon>true</DoNotOpenServerManagerAtLogon> + </component> + <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-IE-ESC" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> + <IEHardenAdmin>false</IEHardenAdmin> + <IEHardenUser>false</IEHardenUser> + </component> + <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-OutOfBoxExperience" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> + <DoNotOpenInitialConfigurationTasksAtLogon>true</DoNotOpenInitialConfigurationTasksAtLogon> + </component> + </settings> +</unattend> diff --git a/scripts/windows/SetupComplete.cmd b/scripts/windows/SetupComplete.cmd new file mode 100644 index 000000000..08755b5c2 --- /dev/null +++ b/scripts/windows/SetupComplete.cmd @@ -0,0 +1,5 @@ +REG ADD HKLM\Software\Microsoft\Windows\CurrentVersion\WSMAN\Service /v allow_unencrypted /t REG_DWORD /d 1 /f +REG ADD HKLM\Software\Microsoft\Windows\CurrentVersion\WSMAN\Service /v auth_basic /t REG_DWORD /d 1 /f +REG ADD HKLM\Software\Microsoft\Windows\CurrentVersion\WSMAN\Client /v auth_basic /t REG_DWORD /d 1 /f + +cmd.exe /c C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command . c:\windows\setup\scripts\nano_cleanup.ps1 > c:\windows\setup\scripts\cleanup.txt \ No newline at end of file diff --git a/scripts/windows/nano_cleanup.ps1 b/scripts/windows/nano_cleanup.ps1 new file mode 100644 index 000000000..b8d976b25 --- /dev/null +++ b/scripts/windows/nano_cleanup.ps1 @@ -0,0 +1,37 @@ +Import-Module C:\windows\system32\windowspowershell\v1.0\Modules\Microsoft.PowerShell.Utility\Microsoft.PowerShell.Utility.psd1 +Import-Module C:\windows\system32\windowspowershell\v1.0\Modules\Microsoft.PowerShell.Management\Microsoft.PowerShell.Management.psd1 +Import-Module C:\windows\system32\windowspowershell\v1.0\Modules\Storage\Storage.psd1 + +$partition = Get-Partition -DriveLetter C +$c_size = $partition.size +$partition = Get-Partition -DriveLetter D +$d_size = $partition.size + +Remove-Partition -DriveLetter D -Confirm:$false +Resize-Partition -DriveLetter C -Size ($c_size + $d_size) + +Optimize-Volume -DriveLetter C + +$FilePath="c:\zero.tmp" +$Volume= Get-Volume -DriveLetter C +$ArraySize= 64kb +$SpaceToLeave= $Volume.Size * 0.05 +$FileSize= $Volume.SizeRemaining - $SpacetoLeave +$ZeroArray= new-object byte[]($ArraySize) + +$Stream= [io.File]::OpenWrite($FilePath) +try { + $CurFileSize = 0 + while($CurFileSize -lt $FileSize) { + $Stream.Write($ZeroArray,0, $ZeroArray.Length) + $CurFileSize +=$ZeroArray.Length + } +} finally { + if($Stream) { + $Stream.Close() + } +} + +Del $FilePath + +shutdown /s /t 0 \ No newline at end of file diff --git a/scripts/windows/nano_create.ps1 b/scripts/windows/nano_create.ps1 new file mode 100644 index 000000000..306ec3333 --- /dev/null +++ b/scripts/windows/nano_create.ps1 @@ -0,0 +1,39 @@ +start-transcript -path $env:temp\transcript0.txt -noclobber + +mkdir c:\NanoServer +cd c:\NanoServer +xcopy /s d:\NanoServer\*.* . +. .\new-nanoserverimage.ps1 +$adminPassword = ConvertTo-SecureString "Pass@word1" -AsPlainText -Force + +New-NanoServerImage ` + -MediaPath D:\ ` + -BasePath .\Base ` + -TargetPath .\Nano ` + -ComputerName Nano ` + -OEMDrivers ` + -ReverseForwarders ` + -AdministratorPassword $adminPassword + +Mount-DiskImage -ImagePath "c:\NanoServer\nano\Nano.vhd" + +Copy-Item ` + -Path "F:\*" ` + -Destination "E:\" ` + -Force ` + -Recurse ` + -Exclude "System Volume Information" ` + -ErrorAction SilentlyContinue + +mkdir E:\Windows\setup\scripts +copy-item a:\postunattend.xml E:\Windows\Panther\unattend.xml -Force +copy-item a:\SetupComplete.cmd E:\Windows\setup\scripts\SetupComplete.cmd -Force +copy-item a:\nano_cleanup.ps1 E:\Windows\setup\scripts\nano_cleanup.ps1 -Force + +bcdedit /set "{current}" device "partition=E:" +bcdedit /set "{current}" osdevice "partition=E:" +bcdedit /set "{current}" path \windows\system32\boot\winload.exe + +winrm set winrm/config/client/auth '@{Basic="true"}' +winrm set winrm/config/service/auth '@{Basic="true"}' +winrm set winrm/config/service '@{AllowUnencrypted="true"}' diff --git a/scripts/windows/postunattend.xml b/scripts/windows/postunattend.xml new file mode 100644 index 000000000..e5189cc9d --- /dev/null +++ b/scripts/windows/postunattend.xml @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="utf-8"?> +<unattend xmlns="urn:schemas-microsoft-com:unattend"> + <settings pass="generalize"> + <component name="Microsoft-Windows-Security-SPP" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <SkipRearm>1</SkipRearm> + </component> + <component name="Microsoft-Windows-PnpSysprep" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <PersistAllDeviceInstalls>false</PersistAllDeviceInstalls> + <DoNotCleanUpNonPresentDevices>false</DoNotCleanUpNonPresentDevices> + </component> + </settings> + <settings pass="oobeSystem"> + <component name="Microsoft-Windows-International-Core" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <InputLocale>en-US</InputLocale> + <SystemLocale>en-US</SystemLocale> + <UILanguage>en-US</UILanguage> + <UserLocale>en-US</UserLocale> + </component> + <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <OOBE> + <HideEULAPage>true</HideEULAPage> + <ProtectYourPC>1</ProtectYourPC> + <NetworkLocation>Home</NetworkLocation> + <HideWirelessSetupInOOBE>true</HideWirelessSetupInOOBE> + </OOBE> + <TimeZone>UTC</TimeZone> + <UserAccounts> + <AdministratorPassword> + <Value>vagrant</Value> + <PlainText>true</PlainText> + </AdministratorPassword> + <LocalAccounts> + <LocalAccount wcm:action="add"> + <Password> + <Value>vagrant</Value> + <PlainText>true</PlainText> + </Password> + <Group>administrators</Group> + <DisplayName>Vagrant</DisplayName> + <Name>vagrant</Name> + <Description>Vagrant User</Description> + </LocalAccount> + </LocalAccounts> + </UserAccounts> + </component> + </settings> + <settings pass="specialize"> + </settings> +</unattend> diff --git a/windows-nano-tp3.json b/windows-nano-tp3.json new file mode 100644 index 000000000..7f8c5cf1b --- /dev/null +++ b/windows-nano-tp3.json @@ -0,0 +1,51 @@ +{ + "builders": [{ + "disk_size": 61440, + "type": "virtualbox-iso", + "vboxmanage": [ + [ "modifyvm", "{{.Name}}", "--natpf1", "guest_winrm,tcp,,55985,,5985" ], + [ "modifyvm", "{{.Name}}", "--memory", "2048" ], + [ "modifyvm", "{{.Name}}", "--vram", "36" ], + [ "modifyvm", "{{.Name}}", "--cpus", "2" ], + [ "modifyvm", "{{.Name}}", "--hardwareuuid", "02f110e7-369a-4bbc-bbe6-6f0b6864ccb6" ] + ], + "guest_os_type": "Windows2012_64", + "headless": "{{ user `headless` }}", + "iso_url": "{{ user `iso_url` }}", + "iso_checksum": "{{ user `iso_checksum` }}", + "iso_checksum_type": "{{user `iso_checksum_type`}}", + "communicator": "winrm", + "output_directory": "packer-{{user `template`}}-virtualbox", + "virtualbox_version_file": ".vbox_version", + "vm_name": "{{ user `template` }}", + "winrm_username": "vagrant", + "winrm_password": "vagrant", + "winrm_timeout": "2h", + "guest_additions_mode": "disable", + "shutdown_command": "shutdown /r /t 10 /f /d p:4:1 /c \"Packer Shutdown\"", + "shutdown_timeout": "15m", + "floppy_files": [ + "scripts/Autounattend.xml", + "scripts/nano_create.ps1", + "scripts/nano_cleanup.ps1", + "scripts/SetupComplete.cmd", + "scripts/postunattend.xml" + ] + }], + "post-processors": [ + { + "type": "vagrant", + "keep_input_artifact": true, + "output": "builds/{{user `box_basename`}}.{{.Provider}}.box", + "vagrantfile_template": "vagrantfile-windows-nano.template" + } + ], + "variables": { + "box_basename": "windows-nano", + "headless": "", + "iso_checksum": "7003c2a4f9abe672c570ff018fbf3a27", + "iso_checksum_type": "md5", + "iso_url": "iso/10514.0.150808-1529.TH2_RELEASE_SERVER_OEMRET_X64FRE_EN-US.ISO", + "template": "windows-nano-tp3" + } +} From f908183dc54d33fa9cd7961fa422f6e41e3c37c7 Mon Sep 17 00:00:00 2001 From: Matt Wrock <matt@mattwrock.com> Date: Tue, 29 Sep 2015 16:24:27 -0700 Subject: [PATCH 2/6] ready to try on linux --- vagrantfile_templates/windows-nano.rb | 17 +++++++ windows-nano-tp3.json | 68 ++++++++++++++++++--------- 2 files changed, 63 insertions(+), 22 deletions(-) create mode 100644 vagrantfile_templates/windows-nano.rb diff --git a/vagrantfile_templates/windows-nano.rb b/vagrantfile_templates/windows-nano.rb new file mode 100644 index 000000000..92426e380 --- /dev/null +++ b/vagrantfile_templates/windows-nano.rb @@ -0,0 +1,17 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +Vagrant.configure(2) do |config| + config.vm.guest = :windows + config.vm.communicator = "winrm" + + config.vm.provider "virtualbox" do |vb| + vb.customize ["modifyvm", :id, "--hardwareuuid", "02f110e7-369a-4bbc-bbe6-6f0b6864ccb6"] + vb.gui = true + vb.memory = "1024" + end + + config.vm.provider 'hyperv' do |hv| + hv.ip_address_timeout = 240 + end +end diff --git a/windows-nano-tp3.json b/windows-nano-tp3.json index 7f8c5cf1b..f6999b370 100644 --- a/windows-nano-tp3.json +++ b/windows-nano-tp3.json @@ -1,43 +1,67 @@ { "builders": [{ + "communicator": "winrm", "disk_size": 61440, - "type": "virtualbox-iso", - "vboxmanage": [ - [ "modifyvm", "{{.Name}}", "--natpf1", "guest_winrm,tcp,,55985,,5985" ], - [ "modifyvm", "{{.Name}}", "--memory", "2048" ], - [ "modifyvm", "{{.Name}}", "--vram", "36" ], - [ "modifyvm", "{{.Name}}", "--cpus", "2" ], - [ "modifyvm", "{{.Name}}", "--hardwareuuid", "02f110e7-369a-4bbc-bbe6-6f0b6864ccb6" ] + "floppy_files": [ + "scripts/windows/Autounattend.xml", + "scripts/windows/nano_create.ps1", + "scripts/windows/nano_cleanup.ps1", + "scripts/windows/SetupComplete.cmd", + "scripts/windows/postunattend.xml" ], + "guest_additions_mode": "disable", "guest_os_type": "Windows2012_64", "headless": "{{ user `headless` }}", "iso_url": "{{ user `iso_url` }}", "iso_checksum": "{{ user `iso_checksum` }}", "iso_checksum_type": "{{user `iso_checksum_type`}}", - "communicator": "winrm", "output_directory": "packer-{{user `template`}}-virtualbox", + "shutdown_command": "shutdown /r /t 10 /f /d p:4:1 /c \"Packer Shutdown\"", + "shutdown_timeout": "15m", + "type": "virtualbox-iso", + "vboxmanage": [ + [ + "modifyvm", + "{{.Name}}", + "--natpf1", + "guest_winrm,tcp,,55985,,5985" + ], + [ + "modifyvm", + "{{.Name}}", + "--memory", + "2048" + ], + [ + "modifyvm", + "{{.Name}}", + "--vram", + "36" + ], + [ + "modifyvm", + "{{.Name}}", + "--cpus", + "2" + ], + [ + "modifyvm", + "{{.Name}}", + "--hardwareuuid", + "02f110e7-369a-4bbc-bbe6-6f0b6864ccb6" + ] + ], "virtualbox_version_file": ".vbox_version", "vm_name": "{{ user `template` }}", - "winrm_username": "vagrant", "winrm_password": "vagrant", "winrm_timeout": "2h", - "guest_additions_mode": "disable", - "shutdown_command": "shutdown /r /t 10 /f /d p:4:1 /c \"Packer Shutdown\"", - "shutdown_timeout": "15m", - "floppy_files": [ - "scripts/Autounattend.xml", - "scripts/nano_create.ps1", - "scripts/nano_cleanup.ps1", - "scripts/SetupComplete.cmd", - "scripts/postunattend.xml" - ] + "winrm_username": "vagrant" }], "post-processors": [ { "type": "vagrant", - "keep_input_artifact": true, "output": "builds/{{user `box_basename`}}.{{.Provider}}.box", - "vagrantfile_template": "vagrantfile-windows-nano.template" + "vagrantfile_template": "vagrantfile_templates/windows-nano.rb" } ], "variables": { @@ -45,7 +69,7 @@ "headless": "", "iso_checksum": "7003c2a4f9abe672c570ff018fbf3a27", "iso_checksum_type": "md5", - "iso_url": "iso/10514.0.150808-1529.TH2_RELEASE_SERVER_OEMRET_X64FRE_EN-US.ISO", + "iso_url": "http://care.dlservice.microsoft.com/dl/download/7/3/C/73C250BE-67C4-440B-A69B-D0E8EE77F01C/10514.0.150808-1529.TH2_RELEASE_SERVER_OEMRET_X64FRE_EN-US.ISO", "template": "windows-nano-tp3" } } From 8721898cddf4614e46d72a0e87f45fa5300bfa27 Mon Sep 17 00:00:00 2001 From: Matt Wrock <matt@mattwrock.com> Date: Tue, 29 Sep 2015 19:22:43 -0700 Subject: [PATCH 3/6] extending timeout to zap disk --- windows-nano-tp3.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/windows-nano-tp3.json b/windows-nano-tp3.json index f6999b370..3728cc82c 100644 --- a/windows-nano-tp3.json +++ b/windows-nano-tp3.json @@ -17,7 +17,7 @@ "iso_checksum_type": "{{user `iso_checksum_type`}}", "output_directory": "packer-{{user `template`}}-virtualbox", "shutdown_command": "shutdown /r /t 10 /f /d p:4:1 /c \"Packer Shutdown\"", - "shutdown_timeout": "15m", + "shutdown_timeout": "1h", "type": "virtualbox-iso", "vboxmanage": [ [ From fa1805331aa8e4f1e699a2a24809d27a1eea1778 Mon Sep 17 00:00:00 2001 From: Matt Wrock <matt@mattwrock.com> Date: Tue, 29 Sep 2015 19:38:40 -0700 Subject: [PATCH 4/6] adding missing vars --- windows-nano-tp3.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/windows-nano-tp3.json b/windows-nano-tp3.json index 3728cc82c..2b740494c 100644 --- a/windows-nano-tp3.json +++ b/windows-nano-tp3.json @@ -66,10 +66,14 @@ ], "variables": { "box_basename": "windows-nano", + "build_timestamp": "{{isotime \"20060102150405\"}}", + "git_revision": "__unknown_git_revision__", "headless": "", "iso_checksum": "7003c2a4f9abe672c570ff018fbf3a27", "iso_checksum_type": "md5", "iso_url": "http://care.dlservice.microsoft.com/dl/download/7/3/C/73C250BE-67C4-440B-A69B-D0E8EE77F01C/10514.0.150808-1529.TH2_RELEASE_SERVER_OEMRET_X64FRE_EN-US.ISO", - "template": "windows-nano-tp3" + "metadata": "floppy/dummy_metadata.json", + "template": "windows-nano-tp3", + "version": "1.0.TIMESTAMP" } } From 8d211ef5ae324e0c5cd1e756f7bd268dad51ac7c Mon Sep 17 00:00:00 2001 From: Matt Wrock <matt@mattwrock.com> Date: Tue, 29 Sep 2015 19:54:15 -0700 Subject: [PATCH 5/6] use the latest version of packer that supports winrm --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 601321a13..c0399649c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ rvm: - 2.2 -before_install: wget --no-check-certificate https://dl.bintray.com/mitchellh/packer/packer_0.7.5_linux_amd64.zip && unzip -d packer packer_0.7.5_linux_amd64.zip +before_install: wget --no-check-certificate https://dl.bintray.com/mitchellh/packer/packer_0.8.6_linux_amd64.zip && unzip -d packer_0.8.6_linux_amd64.zip before_script: export PATH=$PATH:$PWD/packer script: ./bin/bento normalize From 27d5471b509fbfbb33cf35de85285be24566336f Mon Sep 17 00:00:00 2001 From: Matt Wrock <matt@mattwrock.com> Date: Tue, 29 Sep 2015 19:59:20 -0700 Subject: [PATCH 6/6] fixing unzip --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c0399649c..cde67abd7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ rvm: - 2.2 -before_install: wget --no-check-certificate https://dl.bintray.com/mitchellh/packer/packer_0.8.6_linux_amd64.zip && unzip -d packer_0.8.6_linux_amd64.zip +before_install: wget --no-check-certificate https://dl.bintray.com/mitchellh/packer/packer_0.8.6_linux_amd64.zip && unzip -d packer packer_0.8.6_linux_amd64.zip before_script: export PATH=$PATH:$PWD/packer script: ./bin/bento normalize