Which WSL distro is using AppData\Local\Docker\wsl\data\ext4.vhdx after docker-desktop-data was exported and unregistered
Asked Answered
S

3

10

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.

Serapis answered 2/10, 2020 at 8:44 Comment(2)
I also have a large data.ext4 and the same location (after installing WSL, then Docker, then upgrading to WSL2), and would like to remove it.Kaine
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.Serapis
P
13

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.

Percutaneous answered 11/8, 2021 at 15:40 Comment(0)
D
5

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

enter image description here

Dichromaticism answered 2/11, 2021 at 13:0 Comment(0)
S
0

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.

Serapis answered 13/10, 2020 at 15:3 Comment(3)
Good deal, will have to try. (Just shy of 10GB used up for me.) Would you mind sharing a link or a bit more explanation regarding “default setting” and “docker-desktop troubleshoot”?Kaine
Sorry, I didn't find any related doc to this. I was just trial and error. What I can say that resetting it to default settings didn't break my Ubuntu distro. IMO 10GB used is fine (mostly cached images), mine went to 150GB which was too big.Serapis
After uninstalling and reinstalling Docker Desktop, this was resolved.Kaine

© 2022 - 2024 — McMap. All rights reserved.