[WSL2] ext4 disk compression

Due to some special reasons, I used the WSL2 ubuntu system and recompiled the kernel, but after cleaning up all the files, I found that the ubuntu disk file is very large. Here is a record of the WSL2 disk compression operation.

compression step

  • Execute in ubuntu fstrim -a
    The main function is to reclaim the unused space of all mounted file systems on the current system, that is, write the unused space to 0, and compress these spaces when performing disk compression.
  • Host execution wsl -l -v, check the running WSL name
  • The host executes wsl --terminate <WSL名称>and wsl --shutdown, closes WSL to be cleaned up.
  • Use diskpartto compress space
    diskpartis a system tool that comes with winodws, and you can execute it directly on the command line.
    In diskpart, select vdisk file="E:\WSL\ext4.VHDX"select the WSL disk file (change the path to your own), compact vdiskcompress, and wait for completion.
    The cleaning effect is as shown in the figure:
    insert image description here
    insert image description here

Guess you like

Origin blog.csdn.net/weixin_44411509/article/details/127150175