Over time, WSL2 distributions and Docker images can consume significant disk space. Even after deleting files, the allocated virtual disk (VHDX) does not automatically shrink. This guide explains how to manually reclaim disk space by optimizing the virtual disk.
On Windows 11, WSL2 distributions store their virtual disks in the following location:
C:\Users\username\AppData\Local\Packages\
Look for the vendor name corresponding to your installed distribution:
- Ubuntu:
CanonicalGroupLimited - Debian:
TheDebianProject - Pengwin:
WhitewaterFoundryLtd.Co
Once you identify the folder, navigate to the LocalState subdirectory, where you will find the .vhdx file for the distribution.
- Shut down WSL2 completely:
wsl --shutdown - Open PowerShell as Administrator and run the following command:
Replace
optimize-vhd -Path "C:\Path\To\Your.vhdx" -Mode full
C:\Path\To\Your.vhdxwith the actual path to your VHDX file.
Docker stores its virtual disk files for WSL2 in the following location:
C:\Users\YOURNAME\AppData\Local\Docker\wsl\disk
C:\Users\YOURNAME\AppData\Local\Docker\wsl\data
- Shut down Docker completely:
wsl --shutdown - Open PowerShell as Administrator and run:
Replace
optimize-vhd -Path "C:\Users\YOURNAME\AppData\Local\Docker\wsl\disk\yourvdisk.vhdx" -Mode full
yourvdisk.vhdxwith the actual VHDX file name if different.
By following these steps, you can reclaim disk space occupied by WSL2 distributions and Docker images, improving overall storage efficiency on your system.