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

fix: remove guest agent before sysprep to run windows cse on hub #273

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions vhd/aib/AKSeImageTemplateWindows.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,19 @@
"inline": [
"[concat('& c:\\akse-cache\\write-release-notes-windows.ps1 -BUILD_NUMBER ',parameters('build_number'),' -BUILD_ID ',parameters('build_id'),' -BUILD_REPO ',parameters('build_repo'),' -BUILD_BRANCH ',parameters('github_branch_name'),' -BUILD_COMMIT ',parameters('git_version'))]"
]
},
{
"type": "PowerShell",
"name": "run sysprep phase1",
"runElevated": true,
"scriptUri": "[uri('https://raw.githubusercontent.com/Azure/aks-engine-azurestack/',concat(parameters('github_branch_name'),'/vhd/packer/sysprep-phase1.ps1'))]"
},
{
"type": "File",
"name": "copy sysprep phase2 script",
"runElevated": true,
"sourceUri": "[uri('https://raw.githubusercontent.com/Azure/aks-engine-azurestack/',concat(parameters('github_branch_name'),'/vhd/packer/sysprep-phase2.ps1'))]",
"destination":"c:\\DeprovisioningScript.ps1"
}
],
"distribute":
Expand Down
2 changes: 1 addition & 1 deletion vhd/packer/configure-windows-vhd-phase2.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function Get-ContainerImages {
# CSE will configure and register containerd as a service at deployment time
Start-Job -Name containerd -ScriptBlock { containerd.exe }
foreach ($image in $imagesToPull) {
& ctr.exe -n k8s.io images pull $image >> $containerdImagePullNotesFilePath
& ctr.exe -n k8s.io images pull $image > $containerdImagePullNotesFilePath
}
Write-Log "Begin listing containerd images"
$imagesList = & ctr.exe -n k8s.io images list
Expand Down
17 changes: 8 additions & 9 deletions vhd/packer/sysprep.ps1 → vhd/packer/sysprep-phase1.ps1
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
$ErrorActionPreference = "Continue"

# Stop and remove Azure Agents to enable use in Azure Stack
# If deploying an Azure VM the agents will be re-added to the VMs at deployment time
Stop-Service WindowsAzureGuestAgent
Stop-Service WindowsAzureNetAgentSvc
# Stop-Service WindowsAzureNetAgentSvc
Stop-Service RdAgent
& sc.exe delete WindowsAzureGuestAgent
& sc.exe delete WindowsAzureNetAgentSvc
# & sc.exe delete WindowsAzureNetAgentSvc
& sc.exe delete RdAgent
Write-Output '>>> Deleted Azure agents complete ...'

# Remove the WindowsAzureGuestAgent registry key for sysprep
# This removes AzureGuestAgent from participating in sysprep
Expand All @@ -26,11 +29,7 @@ $values | ForEach-Object {
}
}

# run Sysprep
if( Test-Path $Env:SystemRoot\\system32\\Sysprep\\unattend.xml ) { Remove-Item $Env:SystemRoot\\system32\\Sysprep\\unattend.xml -Force }
& $env:SystemRoot\\System32\\Sysprep\\Sysprep.exe /oobe /generalize /mode:vm /quit
# Get-ChildItem c:\\WindowsAzure -Force | Sort-Object -Property FullName -Descending | ForEach-Object { try { Remove-Item -Path $_.FullName -Force -Recurse -ErrorAction SilentlyContinue; } catch { } }
# Remove-Item -Path WSMan:\\Localhost\\listener\\listener* -Recurse -ErrorAction SilentlyContinue

# when done clean up
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 } }
Get-ChildItem c:\\WindowsAzure -Force | Sort-Object -Property FullName -Descending | ForEach-Object { try { Remove-Item -Path $_.FullName -Force -Recurse -ErrorAction SilentlyContinue; } catch { } }
Remove-Item -Path WSMan:\\Localhost\\listener\\listener* -Recurse
Write-Output '>>> Sysprep phase1 script complete ...'
17 changes: 17 additions & 0 deletions vhd/packer/sysprep-phase2.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
if( Test-Path $Env:SystemRoot\system32\Sysprep\unattend.xml ) {
Write-Output '>>> Removing Sysprep\unattend.xml ...'
Remove-Item $Env:SystemRoot\system32\Sysprep\unattend.xml -Force
}
if (Test-Path $Env:SystemRoot\Panther\unattend.xml) {
Write-Output '>>> Removing Panther\unattend.xml ...'
Remove-Item $Env:SystemRoot\Panther\unattend.xml -Force
}
Write-Output '>>> Sysprepping VM ...'
& $Env:SystemRoot\System32\Sysprep\Sysprep.exe /oobe /generalize /quiet /quit
while($true) {
$imageState = (Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup\State).ImageState
Write-Output $imageState
if ($imageState -eq 'IMAGE_STATE_GENERALIZE_RESEAL_TO_OOBE') { break }
Start-Sleep -s 5
}
Write-Output '>>> Sysprep complete ...'