WSLC vhdx very heavy #41518
Replies: 1 comment
|
Two different things can produce "I pruned but the vhdx didn't shrink", and the fix is opposite in each case. Worth finding out which one you're in before trying more compaction. First, check whether the file is sparse: # find the actual path
Get-ChildItem HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss |
Get-ItemProperty | Select-Object DistributionName, BasePath
# then, against the vhdx it reports
fsutil sparse queryflag "C:\Users\<you>\AppData\Local\wsl\{guid}\ext4.vhdx"If it reports "This file is set as sparse"That is why diskpart did nothing. Diskpart refuses sparse VHDs outright:
It fails at the The good news is you probably have nothing to reclaim. On a sparse VHD, WSL punches holes as the guest discards blocks, so the space goes back to Windows within a few seconds of the delete. What does not change is the file's logical size — 39 GB is what Explorer's "Size" field shows, while the actual allocation is much smaller. Right-click the vhdx → Properties and compare Size against Size on disk. If "Size on disk" is close to your real usage, nothing is wrong and there is nothing to compact. If it reports "This file is NOT set as sparse"Then compaction is the right move, and it needs the disk fully detached — WSL must be shut down, and the attach must be read-only: wsl --shutdownThen from an elevated prompt, Missing The part that catches most peoplePruning inside the guest never shrinks the host file on its own. WSL virtual disks only ever grow; deleting data marks blocks free inside the ext4 filesystem, but the vhdx keeps its allocation until something either compacts it or punches holes in it. So the sequence has to be: clean up inside first, then compact from the Windows side. Doing only the first half looks exactly like your symptom.
One caveat specific to your case: I've verified this against regular WSL distro vhdx files, not the wslc-dedicated disk, so I don't know for certain that wslc registers its disk under |
Uh oh!
There was an error while loading. Please reload this page.
I just found that the vhdx dedicated for wslc has grown to 39GB.
I don't have many images and the ones that are, are below 10GB in total.
I tried pruning things, but the disk wasn't resized. I also tried to compact it using diskpart but it didn't do anything.
Is there any way to reduce the virtual disk size?
All reactions