Skip to content

Commit

Permalink
[Windows] Add WSL2 to Windows-2025 image (#11242)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey-Ayupov authored Dec 30, 2024
1 parent 0a970d8 commit 5e69d9c
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 3 deletions.
4 changes: 2 additions & 2 deletions images/windows/scripts/build/Configure-System.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ $servicesToDisable = @(
'wuauserv'
'DiagTrack'
'dmwappushservice'
'PcaSvc'
$(if(-not (Test-IsWin25)){'PcaSvc'})
'SysMain'
'gupdate'
'gupdatem'
'StorSvc'
$(if(-not (Test-IsWin25)){'StorSvc'})
) | Get-Service -ErrorAction SilentlyContinue
Stop-Service $servicesToDisable
$servicesToDisable.WaitForStatus('Stopped', "00:01:00")
Expand Down
16 changes: 16 additions & 0 deletions images/windows/scripts/build/Install-WSL2.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Write-Host "Install WSL2"

$version = (Get-GithubReleasesByVersion -Repo "microsoft/WSL" -Version "latest").version
$downloadUrl = Resolve-GithubReleaseAssetUrl `
-Repo "microsoft/WSL" `
-Version $version `
-UrlMatchPattern "wsl.*.x64.msi"

Install-Binary -Type MSI `
-Url $downloadUrl `
-ExpectedSHA256Sum "CD3F2A68A1A5836F6A1CC9965A7F5F54DB267CA221EAA87DF29345AB7957AEC4"

Write-Host "Performing wsl --install --no-distribution"
wsl.exe --install --no-distribution

Invoke-PesterTests -TestFile "WindowsFeatures" -TestName "WSL2"
3 changes: 3 additions & 0 deletions images/windows/scripts/docs-gen/Generate-SoftwareReport.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Import-Module (Join-Path $PSScriptRoot "SoftwareReport.VisualStudio.psm1") -Disa
$softwareReport = [SoftwareReport]::new($(Build-OSInfoSection))
$optionalFeatures = $softwareReport.Root.AddHeader("Windows features")
$optionalFeatures.AddToolVersion("Windows Subsystem for Linux (WSLv1):", "Enabled")
if (Test-IsWin25) {
$optionalFeatures.AddToolVersion("Windows Subsystem for Linux (Default, WSLv2):", $(Get-WSL2Version))
}
$installedSoftware = $softwareReport.Root.AddHeader("Installed Software")

# Language and Runtime
Expand Down
4 changes: 4 additions & 0 deletions images/windows/scripts/docs-gen/SoftwareReport.Tools.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,7 @@ function Get-ImageMagickVersion {
function Get-MongoshVersion {
return $(mongosh --version)
}

function Get-WSL2Version {
return $((Get-AppxPackage -Name "MicrosoftCorporationII.WindowsSubsystemForLinux").version)
}
6 changes: 6 additions & 0 deletions images/windows/scripts/tests/WindowsFeatures.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,9 @@ Describe "Windows Updates" {
$State | Should -BeIn $expect
}
}

Describe "WSL2" {
It "WSL status should return zero exit code" {
"wsl --status" | Should -ReturnZeroExitCode
}
}
3 changes: 2 additions & 1 deletion images/windows/templates/windows-2025.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ build {
inline = ["if (-not ((net localgroup Administrators) -contains '${var.install_user}')) { exit 1 }"]
}

provisioner "powershell" {
provisioner "powershell" {
elevated_password = "${var.install_password}"
elevated_user = "${var.install_user}"
inline = ["bcdedit.exe /set TESTSIGNING ON"]
Expand All @@ -256,6 +256,7 @@ build {
"${path.root}/../scripts/build/Configure-WindowsDefender.ps1",
"${path.root}/../scripts/build/Configure-PowerShell.ps1",
"${path.root}/../scripts/build/Install-PowerShellModules.ps1",
"${path.root}/../scripts/build/Install-WSL2.ps1",
"${path.root}/../scripts/build/Install-WindowsFeatures.ps1",
"${path.root}/../scripts/build/Install-Chocolatey.ps1",
"${path.root}/../scripts/build/Configure-BaseImage.ps1",
Expand Down

0 comments on commit 5e69d9c

Please sign in to comment.