Skip to content

A small script for Windows 10 Home users to compact their WSL2 disks

License

Notifications You must be signed in to change notification settings

mikemaccana/compact-wsl2-disk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 

Repository files navigation

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. This script will:

  • Find your vhdx file(s) in the default paths of
    • WSL2 distros (C:\Users\<NAME>\AppData\Local\Packages\CanonicalGroupLimited...)
    • Docker WSL2 distros (C:\Users\<NAME>\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

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 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 and everyone on the WSL GitHub and R0Wi.

About

A small script for Windows 10 Home users to compact their WSL2 disks

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published