WSL2 reclaims space

WSL2 installs ubuntu20 to the C drive, and today suddenly found that the C drive is occupied to only 80G:
insert image description here
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:

  1. Enter wsl2 and mount the primary partition as readonly mode:
    insert image description here
mount /dev/sdc -o remount,ro
  1. Run zerofree to zero-fill unused blocks in the ext4 file system
zerofree /dev/sdc
  1. Exit wsl2, and close it:
exit
wsl --shutdown
  1. Use the diskpart tool to compress space
    insert image description here
    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
insert image description here

Notice,步骤1和2是必要的,在网上查的都是只有3,4,并不适用我的情况

Guess you like

Origin blog.csdn.net/airenKKK/article/details/129213200