diff --git a/.travis.yml b/.travis.yml index 601321a13..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.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 packer_0.8.6_linux_amd64.zip before_script: export PATH=$PATH:$PWD/packer script: ./bin/bento normalize 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/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 new file mode 100644 index 000000000..2b740494c --- /dev/null +++ b/windows-nano-tp3.json @@ -0,0 +1,79 @@ +{ + "builders": [{ + "communicator": "winrm", + "disk_size": 61440, + "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`}}", + "output_directory": "packer-{{user `template`}}-virtualbox", + "shutdown_command": "shutdown /r /t 10 /f /d p:4:1 /c \"Packer Shutdown\"", + "shutdown_timeout": "1h", + "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_password": "vagrant", + "winrm_timeout": "2h", + "winrm_username": "vagrant" + }], + "post-processors": [ + { + "type": "vagrant", + "output": "builds/{{user `box_basename`}}.{{.Provider}}.box", + "vagrantfile_template": "vagrantfile_templates/windows-nano.rb" + } + ], + "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", + "metadata": "floppy/dummy_metadata.json", + "template": "windows-nano-tp3", + "version": "1.0.TIMESTAMP" + } +}