Monday, April 29, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  5] [ 0]  / answers: 1 / hits: 14872  / 3 Years ago, tue, june 22, 2021, 1:01:04

currently I am using wsl2 and I notice a significant amount of disk space is required for ext4.vhdx, like I know it's Ubuntu's file management system, but I don't deeply understand what's inside, that's why I want to look inside and delete all unnecessary files, how can I do it? like I know wsl2 doesn't release used disk space back to the host system (I am using windows 10), so that's why I want to see what disk storage does ubuntu holds.


More From » windows-10

 Answers
0

@thomas-ward's answer is correct, but it seems to me that there is an additional "question inside your question" that still needs answered.


To start with, to re-word the other answer, you can most easily see the entire contents of ext4.vhdx by simply running WSL and looking at the files. For instance:


sudo find / -xdev | less

That will find all files on the ext4 filesystem mounted as root (/), but not any files on your mounted NTFS/Windows drives (the -xdev excludes other filesystems).


You can also see the storage being used by those same files with:


sudo du -hdx

If that amount differs from the size of the ext4.vhdx file, then yes, as you already suspect, you likely have unreclaimed space. As you mentioned in your question, WSL will grow that file as needed, but it will not automatically shrink it when files are removed.


To manually shrink the file, you can follow any of the steps I mention at this Super User answer. Here's one of them, copied from a referenced Github comment:


wsl --shutdown
# At this point, it is recommended that you back up your ext.vhdx and delete the backup once you have confirmed the other commands are successful.
diskpart
# open window Diskpart
select vdisk file="C:WSL-Distros…ext4.vhdx"
attach vdisk readonly
compact vdisk
detach vdisk
exit

Note: An alternative way of accessing the vhdx directly would be to spin up a new Linux-based VM on Hyper-V and add that virtual drive (or a copy of it) to the instance. It isn't possible to examine it directly in Windows since Windows doesn't understand the ext4 filesystem.


[#1628] Wednesday, June 23, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alkeake

Total Points: 467
Total Questions: 94
Total Answers: 126

Location: Tajikistan
Member since Tue, Jun 15, 2021
3 Years ago
alkeake questions
Mon, Jul 5, 21, 09:24, 3 Years ago
Sun, Apr 23, 23, 03:29, 1 Year ago
Thu, Dec 22, 22, 20:30, 1 Year ago
;