From 21b7fe45ce9ec028a84e9519768e5e952815f2fd Mon Sep 17 00:00:00 2001 From: Nicolas MASSE Date: Sat, 3 Apr 2021 21:31:21 +0200 Subject: [PATCH] windows 10 unattended install --- .gitmodules | 3 + windows/packer/.gitignore | 6 + windows/packer/Autounattend.xml | 303 ++++++++++++++++++++++++++++++++ windows/packer/floppy | 1 + windows/packer/packer-windows | 1 + windows/packer/scripts | 1 + windows/packer/windows_10.json | 100 +++++++++++ 7 files changed, 415 insertions(+) create mode 100644 .gitmodules create mode 100644 windows/packer/.gitignore create mode 100644 windows/packer/Autounattend.xml create mode 120000 windows/packer/floppy create mode 160000 windows/packer/packer-windows create mode 120000 windows/packer/scripts create mode 100644 windows/packer/windows_10.json diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..2cb0989 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "windows/packer/packer-windows"] + path = windows/packer/packer-windows + url = https://github.com/StefanScherer/packer-windows.git diff --git a/windows/packer/.gitignore b/windows/packer/.gitignore new file mode 100644 index 0000000..2f91828 --- /dev/null +++ b/windows/packer/.gitignore @@ -0,0 +1,6 @@ +packer_cache +windows_10-qemu +virtio-win.iso +build.hwm +build.pwd +build.pwi diff --git a/windows/packer/Autounattend.xml b/windows/packer/Autounattend.xml new file mode 100644 index 0000000..1a6ef76 --- /dev/null +++ b/windows/packer/Autounattend.xml @@ -0,0 +1,303 @@ + + + + + + + + + + E:\viostor\w10\amd64 + + + + E:\NetKVM\w10\amd64 + + + + E:\Balloon\w10\amd64 + + + + E:\pvpanic\w10\amd64 + + + + E:\qemupciserial\w10\amd64 + + + + E:\qxldod\w10\amd64 + + + + E:\vioinput\w10\amd64 + + + + E:\viorng\w10\amd64 + + + + E:\vioscsi\w10\amd64 + + + + E:\vioserial\w10\amd64 + + + + + + + + + + 1 + Primary + true + + + + + false + NTFS + C + 1 + 1 + + + + 0 + true + + OnError + + + true + Vagrant + Vagrant + + + + + 2FMYP-QCY43-QR9VK-WTVCK + Never + + + + + + 0 + 1 + + OnError + false + + + /IMAGE/NAME + Windows 10 Enterprise Evaluation + + + + + + + + en-US + + en-US + en-US + en-US + en-US + en-US + + + + + false + + + + + en-US + en-US + en-US + en-US + + + + + vagrant + true</PlainText> + </AdministratorPassword> + <LocalAccounts> + <LocalAccount wcm:action="add"> + <Password> + <Value>vagrant</Value> + <PlainText>true</PlainText> + </Password> + <Description>Vagrant User</Description> + <DisplayName>vagrant</DisplayName> + <Group>administrators</Group> + <Name>vagrant</Name> + </LocalAccount> + </LocalAccounts> + </UserAccounts> + <OOBE> + <HideEULAPage>true</HideEULAPage> + <HideWirelessSetupInOOBE>true</HideWirelessSetupInOOBE> + <NetworkLocation>Home</NetworkLocation> + <ProtectYourPC>1</ProtectYourPC> + </OOBE> + <AutoLogon> + <Password> + <Value>vagrant</Value> + <PlainText>true</PlainText> + </Password> + <Username>vagrant</Username> + <Enabled>true</Enabled> + </AutoLogon> + <FirstLogonCommands> + <SynchronousCommand wcm:action="add"> + <CommandLine>cmd.exe /c powershell -Command "Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force"</CommandLine> + <Description>Set Execution Policy 64 Bit</Description> + <Order>1</Order> + <RequiresUserInput>true</RequiresUserInput> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>C:\Windows\SysWOW64\cmd.exe /c powershell -Command "Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force"</CommandLine> + <Description>Set Execution Policy 32 Bit</Description> + <Order>2</Order> + <RequiresUserInput>true</RequiresUserInput> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>cmd.exe /c reg add "HKLM\System\CurrentControlSet\Control\Network\NewNetworkWindowOff"</CommandLine> + <Description>Network prompt</Description> + <Order>3</Order> + <RequiresUserInput>true</RequiresUserInput> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>cmd.exe /c C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File a:\fixnetwork.ps1</CommandLine> + <Description>Fix public network</Description> + <Order>4</Order> + <RequiresUserInput>true</RequiresUserInput> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File a:\disable-winrm.ps1</CommandLine> + <Description>Disable WinRM</Description> + <Order>5</Order> + <RequiresUserInput>true</RequiresUserInput> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%SystemRoot%\System32\reg.exe ADD HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\ /v HideFileExt /t REG_DWORD /d 0 /f</CommandLine> + <Order>6</Order> + <Description>Show file extensions in Explorer</Description> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%SystemRoot%\System32\reg.exe ADD HKCU\Console /v QuickEdit /t REG_DWORD /d 1 /f</CommandLine> + <Order>7</Order> + <Description>Enable QuickEdit mode</Description> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%SystemRoot%\System32\reg.exe ADD HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\ /v Start_ShowRun /t REG_DWORD /d 1 /f</CommandLine> + <Order>8</Order> + <Description>Show Run command in Start Menu</Description> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%SystemRoot%\System32\reg.exe ADD HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\ /v StartMenuAdminTools /t REG_DWORD /d 1 /f</CommandLine> + <Order>9</Order> + <Description>Show Administrative Tools in Start Menu</Description> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%SystemRoot%\System32\reg.exe ADD HKLM\SYSTEM\CurrentControlSet\Control\Power\ /v HibernateFileSizePercent /t REG_DWORD /d 0 /f</CommandLine> + <Order>10</Order> + <Description>Zero Hibernation File</Description> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%SystemRoot%\System32\reg.exe ADD HKLM\SYSTEM\CurrentControlSet\Control\Power\ /v HibernateEnabled /t REG_DWORD /d 0 /f</CommandLine> + <Order>11</Order> + <Description>Disable Hibernation Mode</Description> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>cmd.exe /c wmic useraccount where "name='vagrant'" set PasswordExpires=FALSE</CommandLine> + <Order>12</Order> + <Description>Disable password expiration for vagrant user</Description> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%SystemRoot%\System32\reg.exe ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultPassword /t REG_SZ /d "vagrant" /f</CommandLine> + <Order>13</Order> + <Description>Enable AutoLogon</Description> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%SystemRoot%\System32\reg.exe ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoAdminLogon /t REG_SZ /d 1 /f</CommandLine> + <Order>14</Order> + <Description>Enable AutoLogon</Description> + </SynchronousCommand> + <!-- WITHOUT WINDOWS UPDATES --> + <SynchronousCommand wcm:action="add"> + <CommandLine>cmd.exe /c C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File a:\enable-winrm.ps1</CommandLine> + <Description>Enable WinRM</Description> + <Order>99</Order> + </SynchronousCommand> + <!-- END WITHOUT WINDOWS UPDATES --> + <!-- WITH WINDOWS UPDATES --> + <!-- + <SynchronousCommand wcm:action="add"> + <CommandLine>cmd.exe /c a:\microsoft-updates.bat</CommandLine> + <Order>98</Order> + <Description>Enable Microsoft Updates</Description> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>cmd.exe /c C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File a:\disable-screensaver.ps1</CommandLine> + <Description>Disable Screensaver</Description> + <Order>99</Order> + <RequiresUserInput>true</RequiresUserInput> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>cmd.exe /c C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File a:\win-updates.ps1</CommandLine> + <Description>Install Windows Updates</Description> + <Order>100</Order> + <RequiresUserInput>true</RequiresUserInput> + </SynchronousCommand> + --> + <!-- END WITH WINDOWS UPDATES --> + </FirstLogonCommands> + <ShowWindowsLive>false</ShowWindowsLive> + </component> + </settings> + <settings pass="specialize"> + <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> + <OEMInformation> + <HelpCustomized>false</HelpCustomized> + </OEMInformation> + <!-- Rename computer here. --> + <ComputerName></ComputerName> + <TimeZone>Romance Standard Time</TimeZone> + <RegisteredOwner/> + </component> + <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-Security-SPP-UX" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> + <SkipAutoActivation>true</SkipAutoActivation> + </component> + </settings> + <cpi:offlineImage xmlns:cpi="urn:schemas-microsoft-com:cpi" cpi:source="catalog:d:/sources/install_windows 7 ENTERPRISE.clg"/> +</unattend> diff --git a/windows/packer/floppy b/windows/packer/floppy new file mode 120000 index 0000000..02794f4 --- /dev/null +++ b/windows/packer/floppy @@ -0,0 +1 @@ +packer-windows/floppy \ No newline at end of file diff --git a/windows/packer/packer-windows b/windows/packer/packer-windows new file mode 160000 index 0000000..1912952 --- /dev/null +++ b/windows/packer/packer-windows @@ -0,0 +1 @@ +Subproject commit 1912952db758fbf7be83b5a82bfbb43a3d4b950e diff --git a/windows/packer/scripts b/windows/packer/scripts new file mode 120000 index 0000000..30e42f7 --- /dev/null +++ b/windows/packer/scripts @@ -0,0 +1 @@ +packer-windows/scripts \ No newline at end of file diff --git a/windows/packer/windows_10.json b/windows/packer/windows_10.json new file mode 100644 index 0000000..35f18c5 --- /dev/null +++ b/windows/packer/windows_10.json @@ -0,0 +1,100 @@ +{ + "builders": [ + { + "accelerator": "kvm", + "boot_wait": "6m", + "communicator": "winrm", + "cpus": "2", + "disk_size": "{{user `disk_size`}}", + "floppy_files": [ + "{{user `autounattend`}}", + "./floppy/WindowsPowershell.lnk", + "./floppy/PinTo10.exe", + "./scripts/fixnetwork.ps1", + "./scripts/disable-screensaver.ps1", + "./scripts/disable-winrm.ps1", + "./scripts/enable-winrm.ps1", + "./scripts/microsoft-updates.bat", + "./scripts/win-updates.ps1" + ], + "headless": true, + "iso_checksum": "{{user `iso_checksum`}}", + "iso_url": "{{user `iso_url`}}", + "memory": "{{user `memory`}}", + "output_directory": "windows_10-qemu", + "qemu_binary": "/usr/libexec/qemu-kvm", + "qemuargs": [ + [ + "-drive", + "file=windows_10-qemu/{{ .Name }},if=virtio,cache=writeback,discard=ignore,format=qcow2,index=1" + ], + [ + "-drive", + "file={{ user `iso_url` }},media=cdrom,index=2" + ], + [ + "-drive", + "file={{ user `virtio_win_iso` }},media=cdrom,index=3" + ] + ], + "shutdown_command": "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"", + "type": "qemu", + "vm_name": "{{user `vm_name`}}", + "winrm_password": "vagrant", + "winrm_timeout": "{{user `winrm_timeout`}}", + "winrm_username": "vagrant" + } + ], + "provisioners": [ + { + "execute_command": "{{ .Vars }} cmd /c \"{{ .Path }}\"", + "remote_path": "/tmp/script.bat", + "scripts": [ + "./scripts/enable-rdp.bat" + ], + "type": "windows-shell" + }, + { + "scripts": [ + "./scripts/vm-guest-tools.ps1", + "./scripts/debloat-windows.ps1" + ], + "type": "powershell" + }, + { + "restart_timeout": "{{user `restart_timeout`}}", + "type": "windows-restart" + }, + { + "scripts": [ + "./scripts/set-powerplan.ps1", + "./scripts/docker/disable-windows-defender.ps1" + ], + "type": "powershell" + }, + { + "execute_command": "{{ .Vars }} cmd /c \"{{ .Path }}\"", + "remote_path": "/tmp/script.bat", + "scripts": [ + "./scripts/pin-powershell.bat", + "./scripts/compile-dotnet-assemblies.bat", + "./scripts/set-winrm-automatic.bat", + "./scripts/uac-enable.bat", + "./scripts/dis-updates.bat", + "./scripts/compact.bat" + ], + "type": "windows-shell" + } + ], + "variables": { + "autounattend": "Autounattend.xml", + "disk_size": "61440", + "memory": "2048", + "iso_checksum": "sha256:f1a4f2176259167cd2c8bf83f3f5a4039753b6cc28c35ac624da95a36e9620fc", + "iso_url": "https://software-download.microsoft.com/download/pr/19041.264.200511-0456.vb_release_svc_refresh_CLIENTENTERPRISEEVAL_OEMRET_x64FRE_en-us.iso", + "restart_timeout": "5m", + "virtio_win_iso": "virtio-win.iso", + "vm_name": "windows_10", + "winrm_timeout": "6h" + } +}