WSL Disk Space Cleanup
- Virtualization & Containers
- Published May 14, 2026
The Windows Subsystem for Linux (WSL) stores its virtual hard disks in the user profile on drive C:. These VHDX files can grow up to 1 TB in size, making it necessary to clean up and reclaim space occasionally. This article shows how.

Reclaim Disk Space Within the WSL VM
Start by cleaning up inside the WSL virtual machine.
Look for Large Directories With Ncdu
Install ncdu (NCurses Disk Usage) and use it to inspect your home directory for large folders. If you use WSL for software development, as I do, there may be huge leftovers from earlier builds.
Docker Cleanup
Remove Docker images and other files that are not used anymore:
sudo docker system prune -a
Reduce the Size of the WSL VM
Once the cleanup inside the WSL VM is complete, you can shrink the VM itself. Run the following commands on the Windows host.
Shut down WSL:
wsl --shutdown
Compact WSL’s virtual hard disk (VHDX) file:
# Launch the disk partition tool
diskpart
# Select your virtual disk
# In the path below, replace YOUR_NAME and GUID with your actual values
select vdisk file="C:\Users\YOUR_NAME\AppData\Local\wsl\GUID\ext4.vhdx"
# Attach it as read-only to prevent errors during compaction
attach vdisk readonly
# Run the compaction
compact vdisk
# Detach the virtual disk
detach vdisk
# Exit diskpart
exit
Move the WSL VM from C: to Another Disk
To move the Ubuntu WSL VM from C: to D:, run the following commands:
# Create a directory for the WSL VM
md d:\WSL\Ubuntu
# Shut down WSL
wsl --shutdown
# Move the VM
wsl --manage Ubuntu --move "D:\WSL\Ubuntu"
Notes
Devcontainer Startup Issues
If your devcontainer does not start after the cleanup, remove it so it can be recreated:
docker rm -f CONTAINER_NAME
Windows Disk Usage Tool
Use WizTree to explore disk usage on Windows. It is free for personal use and works well.







Comments