-
Notifications
You must be signed in to change notification settings - Fork 69
Description
We have noticed lately that some builds with Packer are botched. A rebuild of the exact same .json works.
After some digging into the failed instances (over the SAC on Windows on GCP) we noticed that they weren't sysprepped correctly.
PS C:\Windows\Setup\State> ls
Directory: C:\Windows\Setup\State
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 05-03-2020 20:19 42 State.ini
PS C:\Windows\system32\sysprep> ls
Directory: C:\Windows\system32\sysprep
:1
:1
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 05-03-2020 17:08 ActionFiles
d----- 15-09-2018 11:05 en-US
d----- 12-02-2020 11:00 Panther
-a---- 15-09-2018 09:09 1349120 sysprep.exe
-a---- 05-03-2020 20:17 0 Sysprep_succeeded.tag
The sysprep.ps1 script checks for the sysprep_succeeded.tag file, however the State.ini file is first updated with the correct state 2 minutes after the .tag file is written.
This means that the instance sometimes is shut down before it is finished sysprepping.
This documentation explains where to look for the state. You can either check for it in the registry, or in the State.ini file mentioned above.
For now, the workaround is running GCESysprep with the no_shutdown parameter, checking the registry with a loop like this
while($true) { $imageState = Get-ItemProperty HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup\\State | Select ImageState; if($imageState.ImageState -ne 'IMAGE_STATE_GENERALIZE_RESEAL_TO_OOBE') { Write-Output $imageState.ImageState; Start-Sleep -s 10 } else { break } }