The WSL disk image has grown to fill the host C:/ drive due to too many large docker builds.

The virtual partition needs to be shrunk, the process below can be used. Thanks to this comment on Github.

The path to the virtual disk was found via WinDirStat:

C:\Users\<User>\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\ext4.vhdx

In a Windows command line terminal shutdown WSL.

wsl --shutdown
wsl --unmount
wsl -l --verbose
  NAME      STATE           VERSION
* Ubuntu    Stopped         2

Then run the partition tool.

diskpart

This opens a new window.


Microsoft DiskPart version 10.0.22000.1

Copyright (C) Microsoft Corporation.
On computer: PHIL-LAPTOP

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

DiskPart successfully selected the virtual disk file.

DISKPART> attach vdisk readonly

  100 percent completed

DiskPart successfully attached the virtual disk file.

DISKPART> compact vdisk

   11 percent completed

...

  100 percent completed

DiskPart successfully compacted the virtual disk file.

DISKPART>

Takes some time to clean up, but the results are:

  • Before: 239GB
  • After: 132GB

Embedded Embedded