If you use WSL2 for any length of time, you've probably noticed this: you delete files, clear caches, even uninstall packages inside your Linux distro — and your Windows C: drive usage doesn't move. This trips up almost everyone, and it's not something you did wrong.
Why this happens
Every WSL2 distro lives inside its own virtual disk file (a .vhdx), usually somewhere under:
C:\Users\YOURNAME\AppData\Local\Packages\CanonicalGroupLimited...\LocalState\ext4.vhdx
These disks are "dynamically expanding" — they grow automatically as you use space inside the distro, but Windows never shrinks them back down on its own, even after you delete files from inside Linux. The freed space becomes available to the distro again, but not back to your Windows C: drive, until you compact the file manually.
Step 1: Shut down WSL completely
wsl --shutdown
Confirm everything actually stopped:
wsl -l -v
Every distro listed should show Stopped.
Step 2: Find your distro's vhdx file
The exact path depends on which distro you're running. For most Linux distros installed from the Microsoft Store, it's under:
%LOCALAPPDATA%\Packages\<DistroFolderName>\LocalState\ext4.vhdx
(If you're specifically dealing with Docker Desktop's disk rather than a Linux distro, the process is nearly identical but the file lives in a different folder — %LOCALAPPDATA%\Docker\wsl\disk\docker_data.vhdx.)
Step 3: Compact the disk
On Windows 10/11 Pro or Enterprise, open PowerShell as Administrator:
Optimize-VHD -Path "C:\path\to\ext4.vhdx" -Mode Full
On Windows 10/11 Home, the Hyper-V module isn't available by default, so use diskpart instead:
diskpart
select vdisk file="C:\path\to\ext4.vhdx"
attach vdisk readonly
compact vdisk
detach vdisk
exit
Want to actually reclaim a large amount of space? Compacting only returns space Linux itself has already marked as free. If your distro's disk is genuinely full of unused packages, logs, or old Docker layers, clean those up from inside WSL first — then shut down and compact. Compacting an already-full disk won't do much.
Step 4: Restart
Just open a terminal into your distro again, or start Docker Desktop — WSL restarts itself automatically on first use.
Prevent it from growing unchecked
You can cap how much a distro's disk is allowed to grow by editing %USERPROFILE%\.wslconfig:
[wsl2]
memory=6GB
processors=4
swap=0
This limits memory and CPU rather than disk size directly, but keeping WSL's resource usage in check tends to slow down how fast the disk fills in the first place — most growth comes from Docker layers and package caches building up over time.
I'm exploring building a small tool that finds this kind of thing automatically — WSL and Docker virtual disks, node_modules, build caches — across your whole drive instead of hunting for each one manually. Still early stage, but if you're curious: sweepdevv.netlify.app
Top comments (0)