r/bashonubuntuonwindows • u/_tegos • 11h ago
self promotion I got tired of ext4.vhdx eating my C: drive, so I wrote one tool for clean + backup + compact
Deleting files inside WSL doesn't give the space back to Windows. I moved about 20 GB of project data out of my distro to another drive, and ext4.vhdx stayed at 66.7 GB. C: was down to 21 GB free, while the distro itself now held about 33 GB.
The fix is known (clean up, wsl --shutdown, Optimize-VHD), but I was doing it with 8 different scripts and kept forgetting a step. So I merged them into one tool:
maint audit/maint space- what is taking the space, per cache rule and per folder, plus how much a compact would return. Deletes nothing.maint clean- cleans caches from a rules file (npx, pip, the journal, Playwright browsers no project pins any more, and so on), with--dry-runmaint docker- prunes the build cache and anonymous dangling volumes. Named volumes only if you opt in, anddb-data/mysql/postgres-like names are never touchedmaint.bat full- clean, export the distro to a zstd archive, verify it, rotate old backups, shut WSL down, compact bothext4.vhdxanddocker_data.vhdx
Result on that run (clean, then winclean for %TEMP% and the recycle bin, then compact): ext4.vhdx 66.7 -> 42.8 GB, docker_data.vhdx 33.3 -> 31.0 GB, about 3.8 GB from TEMP and the bin, C: free 21 -> 56 GB.
Things to know before you run it:
fullandcompactshut WSL down and need admin (UAC prompt)- compact needs the Hyper-V PowerShell module, so on Windows Home only the cleanup and backup parts work
- the shipped
rules.confis from my machine, review it first.auditand--dry-runare safe to try
Bash on the WSL side, PowerShell 5.1 on the Windows side, one shared config. MIT.
https://github.com/tegos/wsl-maint
There's a demo gif in the README. Feedback welcome, especially from people on Windows Home or with the distro on a non-C: drive.



