采用wsl创建子系统,但子系统的vhdx文件能自适应的扩容但不能自适应的压缩
因此,需要手动压缩
1、在windows的powershell输入:wsl.exe --list --verbose 查看wsl子系统的运行状态
PS C:\Users\ljx> wsl.exe --list --verbose
NAME STATE VERSION
* Ubuntu-20.04 Stopped 2
Ubuntu-18.04 Running 2
可以发现有部分子系统仍在运行,如果需要压缩的子系统在运行则需要停止子系统
2、在windows的powershell输入:wsl --shutdown 停止子系统
3、然后再输入wsl.exe --list --verbose检查待压缩子系统是否停止
PS C:\Users\ljx> wsl --shutdown
PS C:\Users\ljx> wsl.exe --list --verbose
NAME STATE VERSION
* Ubuntu-20.04 Stopped 2
Ubuntu-18.04 Stopped 2
4、若已经停止则在windows的powershell输入:diskpart 打开进入diskpart界面
5、在diskpart中选择虚拟机文件执行瘦身
> select vdisk file="C:\Users\ljx\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu18.04LTS_79rhkp1fndgsc\LocalState\ext4.vhdx"
> attach vdisk readonly
> compact vdisk
然后出现百分比进度,等待进度结束