Reclaiming disk space when using WSL (Windows Subsystem For Linux)
Posted: Tue Jul 21, 2026 3:05 pm
If you use WSL you may have noticed that it can eat up a ton of disk space. In my case I use it for some regular backup jobs for remote systems and it tends to get very large. After searching for a bit I found that if you clean up the space in the WSL filesystem (you must do this first) and then run the following command, you can get the space back as it shrinks the virtual hard disk.
You must run this in PowerShell using an elevated terminal (or sudo if you have that installed). Replace <user> with your local user ID and <distro folder> with the folder that corresponds to the distro you are running.
I haven't tested this on anything other than an ext4 file system as this is what my Ubuntu instance is running.
You must run this in PowerShell using an elevated terminal (or sudo if you have that installed). Replace <user> with your local user ID and <distro folder> with the folder that corresponds to the distro you are running.
Code: Select all
Optimize-VHD C:\Users\<user>\AppData\Local\Packages\<distro folder>\LocalState\ext4.vhdx