Shrinking only works if the free space inside the Linux filesystem is actually free.
sudo apt update
sudo apt autoremove -y
sudo apt cleanThe magic sauce that most people tend to forget, missing out on huge amounts of available space
sudo dd if=/dev/zero of=zero.fill bs=1M
sudo sync
sudo rm zero.fillFrom PowerShell (not inside WSL):
wsl --shutdownMake sure the runtime is ACTUALLY OFFLINE, or you risk irreversible, colossal damage in the form of gigabytes of blood sweat and tears disappearing into thin air.
Each distro has a file like:
%LOCALAPPDATA%\Packages\<DistroName>\LocalState\ext4.vhdx
You don’t need to open it — just know where it is.
This is the safe, Microsoft‑recommended method.
Open PowerShell as Administrator:
Optimize-VHD -Path "C:\Users\<you>\AppData\Local\Packages\<Distro>\LocalState\ext4.vhdx" -Mode FullThis will shrink the virtual disk to the smallest size possible based on the free space you created earlier.
- It doesn't take much for the "my hard drive needs space and WSL is being a hog" problem to escalate into a "massive, holy shit, major data loss problem."
- Patience, as I have so regretfullyy learned, when dealing with such virtual drivves capable of so much destruction if elbowed the wrong way.
- Anyways, successfully reclaimed 60GB after nearly two years of fighting with WSL2.