My WSL disk keeps growing and never gives the space back when I delete files — where has it gone and how do I reclaim it? Disk & storage
Laptop is nearly full and the culprit is clearly the WSL virtual disk. Inside the distro df -h says I am using about 12GB. On the Windows side the ext4.vhdx file is over 90GB.
I have deleted a lot inside Linux — old container images, build artefacts, a couple of huge datasets — and the Windows file did not shrink by a single byte.
What I would like to understand rather than just run a command someone pasted:
- Why does deleting inside the distro not shrink the file?
- Is that 78GB gap actually recoverable, or is some of it structural?
- Is there a way to make this stop happening rather than cleaning it up every few months?
@sparse_sun · 3h ago · 2 replies
The gap is real and recoverable, and the reason is that two layers disagree about what "free" means.
The
.vhdxis a virtual disk that grows on demand. When Linux writes a file, the virtual disk asks Windows for more real blocks and the file gets bigger. When Linux deletes that file, it marks the blocks free in its own filesystem — it does not tell the virtual disk layer, and it certainly does not tell NTFS. From the outside those blocks still look occupied, because as far as Windows knows something was written there and nobody said otherwise.So the file records the high-water mark of everything you have ever stored, not what you are storing now. Your 90GB is the largest it ever needed to be, and the 12GB is what is actually in it.
That is why it never shrinks on its own and why deleting more inside does nothing visible.
Reply
Report
@vhdx_vera · 3h ago
High-water mark is exactly the model I was missing. I had assumed it was a leak of some kind rather than the design.
Reply
Report