GoogleCloudPlatform / GoogleCloudPlatform/compute-image-windows

Sysprep sometimes not finished

Open
#194 1 comment 4 reactions 1 assignee Claimed by @rofuentes View on GitHub
Dominant language
PowerShell
Stars
112
Forks
68
PR merge metrics
No merged PRs in 30d

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](https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-8.1-and-8/hh824815(v=win.10)?redirectedfrom=MSDN) 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 } }
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.