Skip to content

Commit 5e69d9c

Browse files
[Windows] Add WSL2 to Windows-2025 image (#11242)
1 parent 0a970d8 commit 5e69d9c

File tree

6 files changed

+33
-3
lines changed

6 files changed

+33
-3
lines changed

images/windows/scripts/build/Configure-System.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ $servicesToDisable = @(
9393
'wuauserv'
9494
'DiagTrack'
9595
'dmwappushservice'
96-
'PcaSvc'
96+
$(if(-not (Test-IsWin25)){'PcaSvc'})
9797
'SysMain'
9898
'gupdate'
9999
'gupdatem'
100-
'StorSvc'
100+
$(if(-not (Test-IsWin25)){'StorSvc'})
101101
) | Get-Service -ErrorAction SilentlyContinue
102102
Stop-Service $servicesToDisable
103103
$servicesToDisable.WaitForStatus('Stopped', "00:01:00")
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Write-Host "Install WSL2"
2+
3+
$version = (Get-GithubReleasesByVersion -Repo "microsoft/WSL" -Version "latest").version
4+
$downloadUrl = Resolve-GithubReleaseAssetUrl `
5+
-Repo "microsoft/WSL" `
6+
-Version $version `
7+
-UrlMatchPattern "wsl.*.x64.msi"
8+
9+
Install-Binary -Type MSI `
10+
-Url $downloadUrl `
11+
-ExpectedSHA256Sum "CD3F2A68A1A5836F6A1CC9965A7F5F54DB267CA221EAA87DF29345AB7957AEC4"
12+
13+
Write-Host "Performing wsl --install --no-distribution"
14+
wsl.exe --install --no-distribution
15+
16+
Invoke-PesterTests -TestFile "WindowsFeatures" -TestName "WSL2"

images/windows/scripts/docs-gen/Generate-SoftwareReport.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ Import-Module (Join-Path $PSScriptRoot "SoftwareReport.VisualStudio.psm1") -Disa
2121
$softwareReport = [SoftwareReport]::new($(Build-OSInfoSection))
2222
$optionalFeatures = $softwareReport.Root.AddHeader("Windows features")
2323
$optionalFeatures.AddToolVersion("Windows Subsystem for Linux (WSLv1):", "Enabled")
24+
if (Test-IsWin25) {
25+
$optionalFeatures.AddToolVersion("Windows Subsystem for Linux (Default, WSLv2):", $(Get-WSL2Version))
26+
}
2427
$installedSoftware = $softwareReport.Root.AddHeader("Installed Software")
2528

2629
# Language and Runtime

images/windows/scripts/docs-gen/SoftwareReport.Tools.psm1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,3 +318,7 @@ function Get-ImageMagickVersion {
318318
function Get-MongoshVersion {
319319
return $(mongosh --version)
320320
}
321+
322+
function Get-WSL2Version {
323+
return $((Get-AppxPackage -Name "MicrosoftCorporationII.WindowsSubsystemForLinux").version)
324+
}

images/windows/scripts/tests/WindowsFeatures.Tests.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,9 @@ Describe "Windows Updates" {
8282
$State | Should -BeIn $expect
8383
}
8484
}
85+
86+
Describe "WSL2" {
87+
It "WSL status should return zero exit code" {
88+
"wsl --status" | Should -ReturnZeroExitCode
89+
}
90+
}

images/windows/templates/windows-2025.pkr.hcl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ build {
243243
inline = ["if (-not ((net localgroup Administrators) -contains '${var.install_user}')) { exit 1 }"]
244244
}
245245

246-
provisioner "powershell" {
246+
provisioner "powershell" {
247247
elevated_password = "${var.install_password}"
248248
elevated_user = "${var.install_user}"
249249
inline = ["bcdedit.exe /set TESTSIGNING ON"]
@@ -256,6 +256,7 @@ build {
256256
"${path.root}/../scripts/build/Configure-WindowsDefender.ps1",
257257
"${path.root}/../scripts/build/Configure-PowerShell.ps1",
258258
"${path.root}/../scripts/build/Install-PowerShellModules.ps1",
259+
"${path.root}/../scripts/build/Install-WSL2.ps1",
259260
"${path.root}/../scripts/build/Install-WindowsFeatures.ps1",
260261
"${path.root}/../scripts/build/Install-Chocolatey.ps1",
261262
"${path.root}/../scripts/build/Configure-BaseImage.ps1",

0 commit comments

Comments
 (0)