Like many people I am an extensive user of WSL and Linux under Windows in general. It’s the only real option I have at work and it’s quite a reasonable proposition.
That being said though, the WSL vhdx files can grow as you’re doing Linux work and while you can (and should) clean up side the Linux environment it’s not reflected back to windows as free space.
So how do you compact your WSL file?
- Shutdown your WSL system.
wsl.exe --list --verbose # note the verbose is required to get the state
wsl.exe --terminate Ubuntu-24.04
- Shrink the disk using diskpart
diskpart
You need to select the vhdx file for your WSL instance. The VHDX file is typically found in your AppData folder. In my case it was this.
I copy the VHDX file location as a path.
DISKPART>select vdisk file="C:\Users\geoff\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu24.04LTS_79rhkp1fndgsc\LocalState\ext4.vhdx"
- Compact the vdisk
DISKPART>compact vdisk
- The results.
BEFORE
AFTER
As you can see, i’ve freed up nearly 6Gb.