forked from joefitzgerald/packer-windows
-
Notifications
You must be signed in to change notification settings - Fork 430
Open
Description
I'm experiencing problems with packer failing with a Failed to send shutdown command error after reaching the "shutdown_command" step at the end when building new images. The a:/sysprep.bat script configured as "shutdown_command" seem to run as expected, and triggers the VM to shut down with no visible problems. Still, packer responds with an error.
I suspect that the problem might be caused by the sysprep.exe /shutdown ... call in a:/sysprep.bat is somehow prematurely disconnecting the WinRM connection before shutting down. Replacing the sysprep call with shutdown /s /t 10 /f /d p:4:1 /c Packer_Provisioning_Shutdown does at least make the problem go away.
Steps to reproduce
- Edit
answer_files\2025\Autounattend.xmlto disable windows updates - Run
packer build --only hyperv-iso -var 'hyperv_switchname=Ethernet' .\windows_2025.json - Observe that image building seem to work as expected, and the VM is automatically shut down when reaching the
Gracefully halting virtual machine...stage. - Observe that packer afterwards reacts with
Failed to send shutdown commanderror which fails the build.
Tested with Packer v1.14.3.
Build log
C:\Dev\packer-windows>packer build --only hyperv-iso -var 'hyperv_switchname=Ethernet' .\windows_2025.json
Warning: Warning when preparing build: "hyperv-iso"
For nested virtualization, when virtualization extension is enabled, mac
spoofing should be allowed.
Warning: Warning when preparing build: "hyperv-iso"
For nested virtualization, when virtualization extension is enabled, there
should be 4GB or more memory set for the vm, otherwise Hyper-V may fail to start
any nested VMs.
hyperv-iso: output will be in this color.
==> hyperv-iso: Creating build directory...
==> hyperv-iso: Retrieving ISO
==> hyperv-iso: Trying https://software-static.download.prss.microsoft.com/dbazure/888969d5-f34g-4e03-ac9d-1f9786c66749/26100.1742.240906-0331.ge_release_svc_refresh_SERVER_EVAL_x64FRE_en-us.iso
==> hyperv-iso: Trying https://software-static.download.prss.microsoft.com/dbazure/888969d5-f34g-4e03-ac9d-1f9786c66749/26100.1742.240906-0331.ge_release_svc_refresh_SERVER_EVAL_x64FRE_en-us.iso?checksum=sha256%3Ad0ef4502e350e3c6c53c15b1b3020d38a5ded011bf04998e950720ac8579b23d
==> hyperv-iso: https://software-static.download.prss.microsoft.com/dbazure/888969d5-f34g-4e03-ac9d-1f9786c66749/26100.1742.240906-0331.ge_release_svc_refresh_SERVER_EVAL_x64FRE_en-us.iso?checksum=sha256%3Ad0ef4502e350e3c6c53c15b1b3020d38a5ded011bf04998e950720ac8579b23d => C:\Dev\packer-windows\packer_cache\45173890bb9e0fc063f71cfb6d5ec40a0210e2d9.iso
==> hyperv-iso: Creating floppy disk...
==> hyperv-iso: Copying files flatly from floppy_files
==> hyperv-iso: Copying file: ./answer_files/2025/Autounattend.xml
==> hyperv-iso: Copying file: ./scripts/disable-screensaver.ps1
==> hyperv-iso: Copying file: ./scripts/disable-winrm.ps1
==> hyperv-iso: Copying file: ./scripts/enable-winrm.ps1
==> hyperv-iso: Copying file: ./scripts/microsoft-updates.bat
==> hyperv-iso: Copying file: ./scripts/unattend.xml
==> hyperv-iso: Copying file: ./scripts/sysprep.bat
==> hyperv-iso: Copying file: ./scripts/win-updates.ps1
==> hyperv-iso: Done copying files from floppy_files
==> hyperv-iso: Collecting paths from floppy_dirs
==> hyperv-iso: Resulting paths from floppy_dirs : []
==> hyperv-iso: Done copying paths from floppy_dirs
==> hyperv-iso: Copying files from floppy_content
==> hyperv-iso: Done copying files from floppy_content
==> hyperv-iso: Creating switch 'Ethernet' if required...
==> hyperv-iso: switch 'Ethernet' already exists. Will not delete on cleanup...
==> hyperv-iso: Creating virtual machine...
==> hyperv-iso: Enabling Integration Service...
==> hyperv-iso: Mounting os dvd drive C:\Dev\packer-windows\packer_cache\45173890bb9e0fc063f71cfb6d5ec40a0210e2d9.iso ...
==> hyperv-iso: Mounting floppy drive...
==> hyperv-iso: Skipping mounting Integration Services Setup Disk...
==> hyperv-iso: Mounting secondary DVD images...
==> hyperv-iso: Configuring vlan...
==> hyperv-iso: Determine Host IP for HyperV machine...
==> hyperv-iso: Host IP for the HyperV machine: 192.168.10.110
==> hyperv-iso: Attempting to connect with vmconnect...
==> hyperv-iso: Starting the virtual machine...
==> hyperv-iso: Waiting 10s for boot...
==> hyperv-iso: Typing the boot command...
==> hyperv-iso: Waiting for WinRM to become available...
==> hyperv-iso: WinRM connected.
==> hyperv-iso: Connected to WinRM!
==> hyperv-iso: Provisioning with windows-shell...
==> hyperv-iso: Provisioning with shell script: ./scripts/enable-rdp.bat
==> hyperv-iso:
==> hyperv-iso: C:\Users\vagrant>netsh advfirewall firewall add rule name="Open Port 3389" dir=in action=allow protocol=TCP localport=3389
==> hyperv-iso: Ok.
==> hyperv-iso:
==> hyperv-iso:
==> hyperv-iso: C:\Users\vagrant>reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f
==> hyperv-iso: The operation completed successfully.
==> hyperv-iso: Provisioning with Powershell...
==> hyperv-iso: Provisioning with powershell script: ./scripts/vm-guest-tools.ps1
==> hyperv-iso: Provisioning with powershell script: ./scripts/debloat-windows.ps1
==> hyperv-iso: Skip debloat steps in Hyper-V build
==> hyperv-iso: Restarting Machine
==> hyperv-iso: Waiting for machine to restart...
==> hyperv-iso: A system shutdown is in progress.(1115)
==> hyperv-iso: A system shutdown is in progress.(1115)
==> hyperv-iso: vagrant-2025 restarted.
==> hyperv-iso: Machine successfully restarted, moving on
==> hyperv-iso: Provisioning with windows-shell...
==> hyperv-iso: Provisioning with shell script: ./scripts/pin-powershell.bat
==> hyperv-iso:
==> hyperv-iso: C:\Users\vagrant>rem https://connect.microsoft.com/PowerShell/feedback/details/1609288/pin-to-taskbar-no-longer-working-in-windows-10
==> hyperv-iso:
==> hyperv-iso: C:\Users\vagrant>copy "A:\WindowsPowerShell.lnk" "C:\Users\vagrant\AppData\Local\Temp\Windows PowerShell.lnk"
==> hyperv-iso: The system cannot find the file specified.
==> hyperv-iso: 'A:\PinTo10.exe' is not recognized as an internal or external command,
==> hyperv-iso:
==> hyperv-iso: C:\Users\vagrant>A:\PinTo10.exe /PTFOL01:'C:\Users\vagrant\AppData\Local\Temp' /PTFILE01:'Windows PowerShell.lnk'
==> hyperv-iso: operable program or batch file.
==> hyperv-iso:
==> hyperv-iso: C:\Users\vagrant>exit /b 0
==> hyperv-iso: Provisioning with shell script: ./scripts/set-winrm-automatic.bat
==> hyperv-iso:
==> hyperv-iso: C:\Users\vagrant>echo Set WinRM start type to auto
==> hyperv-iso: Set WinRM start type to auto
==> hyperv-iso:
==> hyperv-iso: C:\Users\vagrant>sc config winrm start= auto
==> hyperv-iso: [SC] ChangeServiceConfig SUCCESS
==> hyperv-iso: Provisioning with shell script: ./scripts/uac-enable.bat
==> hyperv-iso:
==> hyperv-iso: C:\Users\vagrant>reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /f /v EnableLUA /t REG_DWORD /d 1
==> hyperv-iso: The operation completed successfully.
==> hyperv-iso: Provisioning with shell script: ./scripts/compile-dotnet-assemblies.bat
==> hyperv-iso:
==> hyperv-iso: C:\Users\vagrant>if "AMD64" == "AMD64" goto 64BIT
==> hyperv-iso:
==> hyperv-iso: C:\Users\vagrant>C:\WINDOWS\microsoft.net\framework\v4.0.30319\ngen.exe update /force /queue 1>NUL
==> hyperv-iso:
==> hyperv-iso: C:\Users\vagrant>C:\WINDOWS\microsoft.net\framework64\v4.0.30319\ngen.exe update /force /queue 1>NUL
==> hyperv-iso:
==> hyperv-iso: C:\Users\vagrant>C:\WINDOWS\microsoft.net\framework\v4.0.30319\ngen.exe executequeueditems 1>NUL
==> hyperv-iso:
==> hyperv-iso: C:\Users\vagrant>C:\WINDOWS\microsoft.net\framework64\v4.0.30319\ngen.exe executequeueditems 1>NUL
==> hyperv-iso:
==> hyperv-iso: C:\Users\vagrant>exit 0
==> hyperv-iso: Provisioning with shell script: ./scripts/dis-updates.bat
==> hyperv-iso:
==> hyperv-iso: C:\Users\vagrant>rem http://www.windows-commandline.com/disable-automatic-updates-command-line/
==> hyperv-iso:
==> hyperv-iso: C:\Users\vagrant>reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update" /v AUOptions /t REG_DWORD /d 1 /f
==> hyperv-iso: The operation completed successfully.
==> hyperv-iso:
==> hyperv-iso: C:\Users\vagrant>rem remove optional WSUS server settings
==> hyperv-iso:
==> hyperv-iso: C:\Users\vagrant>reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" /f
==> hyperv-iso: The operation completed successfully.
==> hyperv-iso:
==> hyperv-iso: C:\Users\vagrant>rem even harder, disable windows update service
==> hyperv-iso:
==> hyperv-iso: C:\Users\vagrant>rem sc config wuauserv start= disabled
==> hyperv-iso:
==> hyperv-iso: C:\Users\vagrant>rem net stop wuauserv
==> hyperv-iso:
==> hyperv-iso: C:\Users\vagrant>set logfile=C:\Windows\Temp\win-updates.log
==> hyperv-iso:
==> hyperv-iso: C:\Users\vagrant>if exist C:\Windows\Temp\win-updates.log (
==> hyperv-iso: echo Show Windows Updates log file C:\Windows\Temp\win-updates.log
==> hyperv-iso: dir C:\Windows\Temp\win-updates.log
==> hyperv-iso: type C:\Windows\Temp\win-updates.log
==> hyperv-iso: rem output of type command is not fully shown in packer/ssh session, so try PowerShell
==> hyperv-iso: rem but it will hang if log file is about 22 KByte
==> hyperv-iso: rem powershell -command "Get-Content C:\Windows\Temp\win-updates.log"
==> hyperv-iso: echo End of Windows Updates log file C:\Windows\Temp\win-updates.log
==> hyperv-iso: )
==> hyperv-iso: Provisioning with shell script: ./scripts/compact.bat
==> hyperv-iso:
==> hyperv-iso: C:\Users\vagrant>if "hyperv" == "hyperv" (
==> hyperv-iso: echo "Skip compact steps in Hyper-V build."
==> hyperv-iso: goto :eof
==> hyperv-iso: )
==> hyperv-iso: "Skip compact steps in Hyper-V build."
==> hyperv-iso: Gracefully halting virtual machine...
==> hyperv-iso: Failed to send shutdown command: unknown error Post "http://192.168.10.123:5985/wsman": read tcp 192.168.10.110:58495->192.168.10.123:5985: wsarecv: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
==> hyperv-iso: Provisioning step had errors: Running the cleanup provisioner, if present...
==> hyperv-iso: Disconnecting from vmconnect...
==> hyperv-iso: Cleanup floppy drive...
==> hyperv-iso: Clean up os dvd drive...
==> hyperv-iso: Unregistering and deleting virtual machine...
==> hyperv-iso: Deleting output directory...
==> hyperv-iso: Deleting build directory...
Build 'hyperv-iso' errored after 46 minutes 10 seconds: Failed to send shutdown command: unknown error Post "http://192.168.10.123:5985/wsman": read tcp 192.168.10.110:58495->192.168.10.123:5985: wsarecv: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels