The Story of My Windows C Drive Being Occupied by Rust Build Caches
My personal PC (Windows) has one 1TB storage mounted, but recently the storage usage has been hitting the limit.
In this image, there’s about 16GB free, but at its peak, there was only 2GB left, almost full.
Cause
After installing the free software WizTree, I found that most of it was occupied by WSL environment files.
Surprisingly, over 700GB of the 1TB was occupied by WSL files.
Detailed Investigation
Running the following from PowerShell:
wsl -d Ubuntu-24.04 -u root -- du -xhd1 /
The results were as follows (partial). Most of it was in /home and /var.
571G /home
664M /opt
4.1G /root
129G /var
4.0K /boot
7.2G /usr
711G
Further logging into WSL and running
sudo du -xhd1 /home/hiroe | sort -hr
sudo du -xhd1 /var/lib | sort -hr
showed that /home/hiroe/src and /var/lib/docker were the largest.
Further running
sudo du -xhd1 /home/hiroe/src | sort -hr | head -n 25
produced the following result:
471G /home/hiroe/src
373G /home/hiroe/src/kunato
59G /home/hiroe/src/parry-core
37G /home/hiroe/src/XXXXXXXXXX
1.5G /home/hiroe/src/tech_notes
It turned out that this was my AI agent development environment (kunato), a previously abandoned project (parry-core), and a certain Rails application.
At this point, I realized that the Rust build cache for the kunato development environment had accumulated significantly and performed the deletion.
cargo clean
Additionally, to check for accumulated Docker cache, I ran the following:
$ docker buildx du --builder kamal-local-docker-container | tail -n 8
jnmiikj9y5sdswdns453uzppj true 376.7MB 2 weeks ago
ldln2ok1d9i5zgys643aljcdy true 376.7MB 8 days ago
x3ep6h7aandiog276cyma32z5 true 376.7MB 3 weeks ago
ol9a68ayyu3f20w6oqfslzq26 true 376.7MB 2 weeks ago
p0xyahp4krcubwhgtvoqab2pt true 376.9MB 4 weeks ago
tlshyz3lr6ss4j9kws8tw0ulg true 376.9MB 4 weeks ago
Reclaimable: 99.94GB
Total: 99.94GB
A total of 100GB had accumulated. I also deleted this.
docker buildx prune --builder kamal-local-docker-container
This was the cache created by kamal, the deployment tool for the Rails application.
Deletion Results
After performing these actions, the disk space in the WSL environment became as follows:
$ df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/sdd 1007G 192G 765G 21% /
What a great result!
However, at this point, only the WSL Linux environment’s usage decreased, and there was no change in the C drive’s usage on Windows.
Finally, to reduce the C drive’s usage, I performed a shrink on the WSL storage.
sudo fstrim -v /
This operation notifies the storage side of the deleted data area, and usually does not delete saved files.
After exiting WSL, run the following in PowerShell:
Get-ChildItem "$env:LOCALAPPDATA\wsl" -Filter ext4.vhdx -Recurse | Select-Object FullName, Length
The result will be displayed as follows. Please note this down.
FullName Length
-------- ------
C:\Users\hiroe\AppData\Local\wsl\{xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}\ext4.vhdx 771937533952
After confirming the above result, stop WSL
wsl --shutdown
Next, launch PowerShell as an administrator from the Windows menu.
In administrator mode PowerShell, run the following.
diskpart
Once DiskPart starts, it will wait for input as follows.
DISKPART>
Enter the following, replacing the file path after file= with the one you noted earlier (which varies per user).
select vdisk file="C:\Users\hiroe\AppData\Local\wsl\{xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}\ext4.vhdx"
After this command completes, the target disk file will be selected.
Check the disk file’s information.
detail vdisk
Confirm that the correct file has been selected by checking the “Status” and “Virtual Size”.
Finally, run the following to shrink the disk.
compact vdisk
After executing the above command, it will progress gradually.
DISKPART> compact vdisk
63% Completed
It takes some time. It may take about 30 minutes.
Eventually, the C drive’s usage was significantly reduced.
It’s amazing how this happens when developing quickly with AI.
From now on, I’ll write in AGENTS.md to frequently clear caches.
Comments
No comments yet.