Code Snippets

This is really just stuff we forget how to do and want to keep around. Hopefully it helps anyone else vis the magic of search results.

Compress VDISK for WSL2 Instance in DISKPART

In powershell:

wsl.exe --list --verbose

If the WSL in question is running, stop it, e.g.:

wsl.exe --terminate 'Ubuntu'

Locate the package directory for your WSL2 instance in your user folder in \AppData\Local\Packages\. Look for the vendor:

  • WhitewaterFoundryLtd.Co for Pengwin
  • CanonicalGroupLimited for Ubuntu
  • TheDebianProject for Debian
  • etc

The VHDX is in the LocalState subdirectory.


DISKPART> select vdisk file="C:\Users\kk\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu_79rhkp1fndgsc\LocalState\ext4.vhdx"

DiskPart successfully selected the virtual disk file.

DISKPART> compact vdisk

  100 percent completed

DiskPart successfully compacted the virtual disk file.