File tree Expand file tree Collapse file tree 2 files changed +39
-1
lines changed
Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change 1+ # This script will search for WSL's VHDX files for and compact them
2+
3+ # ENSURE:
4+ # 1. You can run scripts:
5+ # Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
6+ # 2. You have Hyper-V management tools:
7+ # Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All -All -NoRestart
8+
9+
10+ # Define the base folder path using the LOCALAPPDATA environment variable
11+ $baseFolderPath = Join-Path - Path $env: LOCALAPPDATA - ChildPath " Packages"
12+
13+ # Search for all VHDX files matching the pattern
14+ $vdiskFiles = Get-ChildItem - Path $baseFolderPath - Recurse - Filter " ext4.vhdx"
15+
16+ Write-Host " Shutting down WSL..."
17+ wsl -- shutdown
18+ Start-Sleep - Seconds 5 # Wait a few seconds to ensure WSL is fully shut down
19+ Write-Host " WSL shut down successfully."
20+
21+ # Loop through each VHDX file found
22+ foreach ($vdisk in $vdiskFiles ) {
23+ Write-Host " Processing VHD/VHDX: $ ( $vdisk.FullName ) "
24+
25+ # Mount the VHD/VHDX file
26+ Mount-VHD - Path $vdisk.FullName - PassThru | Out-Null
27+ Write-Host " VHD mounted: $ ( $vdisk.Name ) "
28+
29+ # Compact the VHD/VHDX file to reclaim unused space
30+ Optimize-VHD - Path $vdisk.FullName - Mode Full
31+ Write-Host " VHD compacted: $ ( $vdisk.Name ) "
32+
33+ # Dismount the VHD
34+ Dismount-VHD - Path $vdisk.FullName
35+ Write-Host " VHD dismounted: $ ( $vdisk.Name ) "
36+ }
37+
38+ Write-Host " VHD/VHDX compression complete."
Original file line number Diff line number Diff line change @@ -90,7 +90,7 @@ Windows.
9090### To free up space
9191
9292To free up space you can use the clean.bat/clean.sh scripts under
93- /src/SDK/Utilities .
93+ /devops\install .
9494
9595For Windows
9696``` cmd
You can’t perform that action at this time.
0 commit comments