WSL2 installs ubuntu20 to the C drive, and today suddenly found that the C drive is occupied to only 80G:
check the C drive occupation, and see that wsl2 occupies 230G of disk space (the actual data is much smaller than this value)
After querying, it may be caused by the problem that wsl does not automatically reclaim space. The resolution steps are listed below:
- Enter wsl2 and mount the primary partition as readonly mode:
mount /dev/sdc -o remount,ro
- Run zerofree to zero-fill unused blocks in the ext4 file system
zerofree /dev/sdc
- Exit wsl2, and close it:
exit
wsl --shutdown
- Use the diskpart tool to compress space
Execute the following command:
diskpart> select vdisk file="C:\Users\<Username>\AppData\Local\Packages\<Linux-Distribution-AppPackageName>\LocalState\ext4.vhdx"
diskpart> compact vdisk
Note, <>中的内容需要根据自身情况替换
5. Check the C disk space, it has been restored
Notice,步骤1和2是必要的,在网上查的都是只有3,4,并不适用我的情况