[wsl2] ext4 hard disk expansion and compression

  • First of all, expand the hard disk Microsoft’s official article is very detailed, so I won’t go into details: Expand the size of the WSL 2 virtual hard disk

  • compressed hard drive

    • Let me talk about the usage scenario first.
    • For example, I want to download a set of aosp codes. First, I download a compressed package from the domestic mirror site, which contains all the aosp codes. The compressed package size is 181G.
    • When I was done, I decompressed the compressed package again. When I decompressed, I found that the disk of wsl2 was too small, and the decompression failed, so I expanded the disk size to 512G.
    • The decompression is complete, delete the compressed package, the remaining space of wsl is large, but the remaining hard disk space of the physical machine is too little. So I'm freeing part of the wsl hard drive.
  • Compression works as follows:

    • First execute in wsl fstrim -a.
    • Then execute it in powershell wsl shutdownand close wsl.
    • Then use diskpart to select the virtual hard disk file as when expanding the hard disk. and execute compact vdisk. Wait for it to finish and that's it.

References:
1, WSL2 distro rapidly expands to fill drive without using space and cannot be shrunk #8226

Guess you like

Origin blog.csdn.net/C2681595858/article/details/124780637