https://github.com/mikemaccana/compact-wsl2-disk
A small script for Windows 10 Home users to compact their WSL2 disks
https://github.com/mikemaccana/compact-wsl2-disk
Last synced: 13 days ago
JSON representation
A small script for Windows 10 Home users to compact their WSL2 disks
- Host: GitHub
- URL: https://github.com/mikemaccana/compact-wsl2-disk
- Owner: mikemaccana
- License: mit
- Created: 2020-11-10T17:27:13.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-03-07T11:34:42.000Z (about 2 years ago)
- Last Synced: 2025-04-09T15:07:54.072Z (13 days ago)
- Language: PowerShell
- Size: 17.6 KB
- Stars: 254
- Watchers: 9
- Forks: 26
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - mikemaccana/compact-wsl2-disk - A small script for Windows 10 Home users to compact their WSL2 disks (PowerShell)
README
# WSL2 Compacter 🗜
## A small script for Windows 10 Home users to compact their WSL2 disks
Inspired by [this post on GitHub about WSL2 filling hard disks](https://github.com/microsoft/WSL/issues/4699#issuecomment-627133168). This script will:
- Find your `vhdx` file(s) in the default paths of
* WSL2 distros (`C:\Users\\AppData\Local\Packages\CanonicalGroupLimited...`)
* Docker WSL2 distros (`C:\Users\\AppData\Local\Docker`)
* Any other folder defined via the `WSL_FOLDERS` environment variable.
For having multiple directories, format it as `$PATH`, as in:
`C:\PATH\TO\FOLDER1;D:\PATH\TO\FOLDER2;...`
- Shut down WSL2
- Compact all found disks with [`diskpart`](https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/diskpart)
After that just open another Linux terminal and WSL2 will restart automatically.## Warning
1. I am a strange man on the internet asking you to run a powershell script. You should probably look inside the script [`compact-wsl2-disk.ps1`](compact-wsl2-disk.ps1) and make sure you understand what it does.
2. This will stop WSL. So save your work in Linux.
## Usage
Open Powershell as Administrator and run:
`powershell.exe .\compact-wsl2-disk.ps1`
## PRs are welcome!
Please file pull requests instead of just asking for things. Thanks!
## License
MIT
## Thanks
[This person on StackOverflow](https://stackoverflow.com/questions/64772243/can-diskpart-take-command-line-parameters-or-can-i-fake-them-with-powershell) and [everyone on the WSL GitHub](https://github.com/microsoft/WSL/issues/4699) and [R0Wi](https://github.com/R0Wi).