Shutdown WSL2:
wsl.exe --shutdown
Open Command Prompt as administrator: press Windows + R
to open the Run Command Window, type cmd
and press Ctrl + Shift + Enter
.
Download the compact_wsl2_disk.bat
script:
wget https://github.com/khourious/labstuffs/raw/master/configs/compact_wsl2_disk.bat
Find the WSL2 disk location:
WHERE.exe /R C:\Users ext4.vhdx
Run the script by typing compact_wsl2_disk.bat
followed by the path of the ext4.vhdx file:
compact_wsl2_disk.bat <path_to_ext4_vhdx_file>