Skip to content

Instantly share code, notes, and snippets.

@Fedec96
Last active December 8, 2025 01:48
Show Gist options
  • Select an option

  • Save Fedec96/f0160789188a55db5a2283a4800e8364 to your computer and use it in GitHub Desktop.

Select an option

Save Fedec96/f0160789188a55db5a2283a4800e8364 to your computer and use it in GitHub Desktop.
Combine PowerShell and diskpart to get your storage space back.

Compact WSL Disk

Combine PowerShell and diskpart to get your storage space back.

1. Ensure WSL is off

wsl --shutdown

2. Find the target distro

Sample output: Ubuntu-24.04

wsl --list

3. Find the disk path

Sample output: C:\Users\You\AppData\Local\wsl\{e3facf9c-8b16-3776-a92f-af9e81e751ec}\ext4.vhdx

(Get-ChildItem -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss | Where-Object { $_.GetValue("DistributionName") -eq 'Ubuntu-24.04' }).GetValue("BasePath") + "\ext4.vhdx"

4. Launch diskpart

4.1. Select the disk

select vdisk file="C:\Users\You\AppData\Local\wsl\{e3facf9c-8b16-3776-a92f-af9e81e751ec}\ext4.vhdx"

4.2. Attach, compact, detach

attach vdisk readonly
compact vdisk
detach vdisk

4.3. Done

exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment