1

On my Windows system, I have WSL2 with Ubuntu installed. I found the ubuntu vhdx file is about 64 GB in size. However, when I try to compact it, the size does not shrink.

df -h shows:

Filesystem      Size  Used Avail Use% Mounted on
/dev/sdd        251G  215G   24G  91% /

sudo du / -x -d 1 -h shows:

346M    /home
4.0K    /srv
7.1M    /etc
4.0K    /opt
20K     /root
4.0K    /mnt
2.4G    /usr
4.0K    /media
4.0K    /boot
4.0K    /snap
220M    /tmp
586M    /var
16K     /lost+found
3.6G    /

I suspect something is holding those space in the VM so Windows cannot compact the VHDX file.

I am pretty sure that VBox answer is not related.

David S.
  • 846
  • 3
  • 18
  • 36
  • that's the non-zero-sectors in the VHDX. The driver knows nothing about file systems, it only cares about blocks. So you have to zero out all empty blocks in the disk to compact it – phuclv May 04 '21 at 00:57
  • [How can I compact the VHD file with Ubuntu?](https://serverfault.com/q/551053/343888), – phuclv May 04 '21 at 01:00
  • 1
    The reason I flagged this as a duplicate is because you had indicated you had already decrease the size of the VHDX itself using the appropriate command, however, your guest OS had not been adjusted. The command to do that is explained in the answer to the duplicate. – Ramhound May 04 '21 at 16:43
  • Which ever moderator closed this definitely linked to the *wrong* question on Super User. Information on how to compact a VirtualBox VDI file has absolutely nothing to do with compacting a WSL/Hyper-V VHDX file. They are different formats, and different tools. The question linked from Server Fault is *closer*, but still doesn't answer the question actually being *asked*. The OP seems to have already done that, but they are not seeing the desired results. Further, AFAIK a question on Server Fault does not make this a duplicate question on Super User. – NotTheDr01ds May 04 '21 at 23:18
  • @david-s, can you edit your question to include *how* you compacted the disk? There are at least three different methods that I'm aware of for doing this (discussed [here](https://superuser.com/a/1612289/1210833)). – NotTheDr01ds May 04 '21 at 23:56
  • @NotTheDr01ds the OP just ran the compact command from the host, which doesn't work because you must zero the disk from inside the VM first, which is said in the above questions. Only after that the host compact command will work – phuclv May 05 '21 at 02:34
  • @NotTheDr01ds I used the `Optimize-VHD` tool which auto zeros..btw, I found out the cause...there's a hidden file in the `/mnt` directory. Took me a long time to find it. – David S. May 05 '21 at 03:02
  • @phuclv That's just not been my (or other's) experience with WSL (see [here](https://superuser.com/a/1612289/1210833)). It also doesn't seem to have been the problem for the OP per the previous comment. – NotTheDr01ds May 05 '21 at 03:45
  • @david-s Good to hear you found it. – NotTheDr01ds May 05 '21 at 03:46

0 Answers0