← Back to SweepDev
Guide

WSL2 disk keeps growing? Here's how to shrink it

Why deleting files inside WSL doesn't free space on Windows, and the fix.

You deleted files, cleared caches, even uninstalled packages inside your WSL2 distro — and your C: drive usage hasn't moved. This trips up almost everyone who uses WSL2 for any length of time, 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

Open Command Prompt or PowerShell:

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 looking for Docker Desktop's disk rather than a Linux distro, see our separate Docker Desktop disk space guide — the process is nearly identical but the file lives in a different folder.

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.

SweepDev checks this for you automatically

It finds WSL and Docker virtual disks that have quietly outgrown their actual contents, alongside node_modules and build caches — all in one scan.

Join the beta waitlist