Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Packer stuck at: "Gracefully halting virtual machine" and build gets failed stating time out. #12472

Open
AshTechieDevOps opened this issue Jun 18, 2023 · 4 comments
Labels

Comments

@AshTechieDevOps
Copy link

Packer stuck at: "Gracefully halting virtual machine" and (shutdown_command = "%windir%\system32\sysprep\sysprep.exe /unattend:A:\Autounattend.xml /quiet /generalize /oobe /shutdown /mode:VM") never gets executed then finally packer build gets failed without creating build arctifacts stating timed out issue post "shutdown_timeout"+"winrm_timeout".

I am using latest version of Packer and Hyper-V as my hypervisor and I am successfully above to manully execute "%windir%\system32\sysprep\sysprep.exe /quiet /generalize /oobe /shutdown /mode:VM" but having issue with (shutdown_command = "%windir%\system32\sysprep\sysprep.exe /unattend:A:\Autounattend.xml /quiet /generalize /oobe /shutdown /mode:VM"). Any suggestions.

packer {
required_plugins {
hyperv = {
version = ">= 1.1.0"
source = "github.com/hashicorp/hyperv"
}
}
}

source "hyperv-iso" "autogenerated_1" {
iso_checksum = "sha256:6DAE072E7F78F4CCAB74A45341DE0D6E2D45C39BE25F1F5920A2AB4F51D7BCBB"
iso_url = "C:/AshImages/2019/17763.3650.221105-1748.rs5_release_svc_refresh_SERVER_EVAL_x64FRE_en-us.iso"
output_directory = "C:/CSG/2k19PackerBuild"
skip_export = true
use_fixed_vhd_format = true
vm_name = "windows2019-vhd-packer"
communicator = "none"
skip_compaction = true
winrm_timeout = "5m"
shutdown_timeout = "25m"
shutdown_command = "%windir%\system32\sysprep\sysprep.exe /unattend:A:\Autounattend.xml /quiet /generalize /oobe /shutdown /mode:VM"

floppy_files = [
"C:/CSG-DC/Autounattend.xml"
]

boot_command = [
"",
"",
"D:\setup.exe /unattend:A:\Autounattend.xml",
"",
]
}

build {
sources = ["hyperv-iso.autogenerated_1"]
}

@AshTechieDevOps
Copy link
Author

Even no other command gets executed by shutdown_command during packer build.

@rahul-nits
Copy link

I was creating and deploying images using PackerBuild@1. I was also stuck once a couple of months back with the same issue, however, I was following standard packer build procedure i.e. creating a JSON file for packer having builder and provisioners.

Initially what I was doing is after my provisioner typed "PowerShell" execution i was executing the Sysprep command as you have written. When I included the "windows restart" type in packer JSON before executing the Sysprep cmd, it worked. I checked it by logging into the VM created to modify the Sysprep server needs restarts. That's where I included this block.

{ "type": "windows-restart", "restart_check_command": "powershell -command \"& {Write-Output 'Restarted.'}\"" }

I'm relatively new in Packer, so I thought to share with you guys my experience and workaround. Hope you get some idea from this article.

@saily
Copy link

saily commented Aug 22, 2024

Hi @AshTechieDevOps, pretty sure the issue is a non-successful sysprep process. Please double check the file C:\Windows\System32\Sysprep\Panther\*.log and look for Errors. Alternatively you can use the error-cleanup-provisioner which will allow you to grab the logfiles before the machine is being killed by packer.

See below:

error-cleanup-provisioner "powershell" {
    inline = [
        "Get-ChildItem -Path 'C:/Windows/System32/Sysprep/Panther' -Filter '*.log' | Get-Content",
    ]
    # elevated_user     = "<your-username>"
    # elevated_password = "<your-password>"
}

@saily
Copy link

saily commented Aug 22, 2024

this is most likely not a packer bug, so I'd recommend we close it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants