WSL: WSL2 distro rapidly expands to fill drive without using space and cannot be shrunk
Version
Microsoft Windows [Version 10.0.22000.593]
WSL Version
- WSL 2
- WSL 1
Kernel Version
5.10.16
Distro Version
Ubuntu 20.04
Other Software
No response
Repro Steps
I am running a Python script calculating some values which are then put in a dictionary and pickled on the disk.
python script_saving_dictionaries
.
.
.
input/output error
Expected Behavior
Expected disk usage by WSL distro to increase by the amount occupied by my saved files (7MB at point of failure)
Actual Behavior
I got to saving ~400 dictionaries with a total size of 7MB, which was what I expected.
However soon I encounter an input/output error due to low disk space. The Ubuntu ext4.vhdx seems to occupy 103GB now from the original ~40GB. This occupies all my disk space and my task fails.
I tried my best to confirm if I was saving some junk somewhere prompting this behaviour but cannot find it. Using du -hs --exclude mnt/ on path ~/../../ (in an effort to see all disk space usage by Ubuntu) returns a size of ~39GB, and I am unable to find what’s occupying the rest of the space.
I uninstalled and reinstalled Ubuntu to the same result.
Using optimize-vhd -Path ...\ext4.vhdx -Mode full or using diskpart does not reclaim the space.
Diagnostic Logs
No response
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 2
- Comments: 17
Interesting. Does running
fstrim -ain wsl, then wslwsl --shutdownandOptimize-Vhdagain helps ? I wonder if filesystem is fragmented@OneBlue Thank you so much for the
fstrim -atrick! ❤️I was in the exact same situation than @sjshamsi and I got back 130+GB of free space thanks to you. 🕺👯💃
I had the same issue
/usr/lib/wsl/driverswas huge like 216GB andfstrim -awithOptimize-VHDworked like a charm!PS: Commenting, so others can find it easier with search👍🏻
@ryanjlind I had this same issue in WSL2 Ubuntu, and all defragmentation,
optimize-vhd, andfstrim -aattempts did nothing. My /dev/sdc was full to 100%, and even though I deleted gigabytes from my home directory, it would always fill up soon after, even though I had only ~40 GB in my home dir. Unless I manually deleted files from the file explorer in \wsl$, I couldn’t even open a terminal properly due to the disk being full.For me, it ended up being a docker issue; I finally narrowed my
du -shcalls down to /var/lib/docker/overlay2 (had tosudo suto enter thedockerdir), which was the entirety of the problem at almost 200G. Runningdocker system prunefreed about 30G, but I had to rundocker system prune -ain order to free the rest.Hope this helps. Cheers!
Holy cow dude. That did it. That was the problem. Docker. Thank you soooo much!
It took like 15 minutes to clear all the junk out of Docker, and freed up 200GB. Man!
Thanks again. Really appreciate it.
If
Optimize-VHDis not recognized, try the solution here:I got this same problem. I have WSL 2 Ubuntu 22.04 on Windows 11.
The size of
ext4.vhdxis ~265GB as mentioned in the screenshot below:I am sure that I have used a little of space but here it rests only 220GB free.
I run these two methods to shrink the WSL hard drive and get back the free disk:
Method 1
fstrim -aon the ubuntu terminalMethod 2
fstrim -aon the ubuntu terminaldf -hgives me the following:I did not get back anything!! I am sure that I did not use this such size of ~700GB
Hello I am having the same issue. I installed WSL 2 without any problems on my Win machine (Win 10 Enterprise 21H2 Build 19044.3930). But after installing Docker I can see that the Ubuntu distro starts using more and more disk space. After one hour it increased by more than 10GB and it doesnt stop which you can see in the following pictures.
It is really eating up my disk space without any obvious reason.
It is a fresh Docker installation without any containers running.
Unfortunately
Optimize-VHDis not found anddocker system prune -acomes up with 0B released since nothing is running. I am having other Docker Deamons running on different Win machines without having this problem. Do you have any other ideas how I can stop this?In case you’re using Win 10 Home, you may not have Opimize-Vhd available. Alternative way of compacting the virtual drive is described here:
https://answers.microsoft.com/en-us/windows/forum/all/optimize-vhd-not-found-in-windows-10-home/a727b760-0f82-4d0f-8480-d49eeaeb11a2
Hi @OneBlue, thansk for the comment. So in this meantime I reimaged my machine but it does exhibit the same problem. Currently Windows displays 33.1GB free of 186GB C drive, and
ext4.vhdxoccupies 118GB.On WSL,
df -hdisplays:I am quite new to Linux filesystems but I was concerned with
/dev/sdcdisplaying 16% use. Please let me know if I can provde more details.