0

I've tried running this to cleaning out docker images, etc… with this command:

compact vdisk

The filesystem allocation is 1007GB and only 4% is used.

How do I fix this?

All the forums and questions seem to point to running diskpart, from this Server Fault question that explains things to do, which I've done. My pyenvs take up about 9GB and I've deleted most.

I am so confused.

2
  • 2
    "The filesystem allocation is 1007GB and only 4% is used." What is the question? If 96% of the disk is empty, what problem are you trying to solve? Commented Jan 1 at 20:15
  • Use this post to shrink excess space. ..... superuser.com/questions/1606213/…
    – anon
    Commented Jan 1 at 21:08

1 Answer 1

0

Your post is a bit confusing, and I actually closed it as a duplicate before realizing that you aren't asking how to reclaim unused space, but rather it seems you are asking what is actually taking up the space in your WSL disk image in the first place.

You mention that your image is taking up ~40GB, and that it is showing 4% usage of approximately 1TB (the normal sparse size for a WSL disk). I'm assuming you used df inside WSL to get that number. The Windows and Linux numbers match up, so the disk image itself already seems to be compressed as much as possible.

To find what is using the space, the standard method is to use the du (disk usage) command. On WSL, I'd recommend the following:

sudo du -hxs --exclude=/{proc,sys,dev,run} /*

Where:

  • sudo allows you to read the filesizes in directories you wouldn't otherwise have access to as your normal user. It's unlikely that the culprit is in one of those directories, but this will also suppress the errors that would otherwise result from attempting to read them.
  • -h gives you "human readable" directory sizes
  • -s summarizes the information for each file/directory in the root (/*)
  • The -x is particularly important with WSL, since without it du will try to following /mnt/c, etc. These files live outsize WSL, and shouldn't be counted.
  • Also, ignoring the virtual filesystems is nice for suppressing a few errors you'd get otherwise. Credit to this answer for that tidbit.

A sudo du -hxs --exclude=/{proc,sys,dev,run} / (without the wildcard) should give you a total for all the contents of the root filesystem, which should match with the number that df gave you.

Once you've figured out what directory has the bulk of the files, you re-run du on that directory, drilling down until you find the culprit. E.g.:

sudo du -hxs --exclude=/{proc,sys,dev,run} /var/*

Side note: If you are running Docker Desktop, then most of its storage should be in a separate WSL image, docker-desktop-data. However, if you are not running Docker Desktop, and instead just have a Docker Engine install in WSL, then it's possible that there are files left from that. The compact vdisk command you mentioned doesn't do anything with Docker data.

Finally, once you have removed the offending files from WSL, then run the compaction routine on the WSL ext4.vhdx as I cover in my answer to this question.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .