Due to increasing space consumption of WSL I was forced to move my WSL distros to another disk.
Ubuntu
docker-desktop
docker-desktop-data

I used these commands.
wsl --shutdown
wsl --export (on all three of those distros)
wsl --import (already on another disk)

Now my environment is running fine but the ext4.vhdx in AppData\Local\Docker\wsl\data is still present and I can't remove it due to it still being used.

When I look at process hadnles enter image description here

Its still being used by system which is not telling much.

If I run WSL --shutdown all virtual disks present on disk E: lose their handles and the one on disk C: is still being used.

enter image description here

Would you know how to find out what part of WSL or if it even is WSL is using? Since shutting down WSL does not remove that handle it might be used by something else. Its not docker-for-desktop that one uses different disk.

Thanks for your suggestions.

3

There are 3 best solutions below

3
On

Upgrading from WSL1 to WSL2 made it a bit messy, but resetting docker-desktop to its default setting and then purging data from WSL (using docker-desktop troublesshot) cleared it for me.

0
On

Docker Desktop for Windows, which uses WSL2, stores all image and container files in a separate virtual volume (vhdx). This virtual hard disk file can automatically grow when it needs more space (to a certain limit). Unfortunately, if you reclaim some space, i.e. by removing unused images, vhdx doesn't shrink automatically. Luckily, you can reduce its size manually by calling this command in PowerShell (as Administrator):

Optimize-VHD -Path $Env:LOCALAPPDATA\Docker\wsl\data\ext4.vhdx -Mode Full

If the above command fails with

The system failed to compact 'C:\Users\Maxx\AppData\Local\Docker\wsl\data\ext4.vhdx':
The process cannot access the file because it is being used by another process. (0x80070020).

exit form Docker Desktop or stop services and tasks using that file:

net stop com.docker.service
taskkill /IM "docker.exe" /F
taskkill /IM "Docker Desktop.exe" /F
wsl --shutdown

I reclaimed 15Gb of 40Gb.

Origin of the solution.

0
On

You can just clean data from interface. Troubleshooting -> Clean/Purge data

enter image description here