0.缘起
wsl的linux系统是以一个单独的.vhdx镜像文件的方式存在的。开发过程中,体积可能会变得比较大。包括镜像和容器。所以,有了这个问题。下面的工作是将其从C盘转移到容量更大的D盘。
默认wsl的安装位置是系统盘,并且似乎没有直接指定安装目录的方法。
PS C:\Windows\system32> wsl --install Ubuntu-20.04
1.显示当前的所有wsl镜像
PS C:\Windows\system32> wsl --list --verbose
NAME STATE VERSION
* Ubuntu-20.04 Running 2
2.终止某个wsl镜像,然后打包,删除该镜像
PS C:\Windows\system32> wsl --terminate ubuntu-20.04
操作成功完成。
PS C:\Windows\system32> wsl --export Ubuntu-20.04 D:\git\wsl\wsl-backup\Ubuntu-20.04.tar
正在导出,这可能需要几分钟时间。 (1965 MB): ./var/snap/lxd/common/lxd/unix.socket: pax format cannot archive sockets操作成功完成。
PS C:\Windows\system32> wsl --unregister ubuntu-20.04
正在注销。
操作成功完成。
3.在新的路径导入映像,并重新加载
PS C:\Windows\system32> wsl --import Ubuntu-20.04 D:\git\wsl\Ubuntu-20.04 D:\git\wsl\wsl-backup\Ubuntu-20.04.tar
操作成功完成。
PS C:\Windows\system32> wsl --list --verbose
NAME STATE VERSION
* Ubuntu-20.04 Stopped 2
PS C:\Windows\system32> wsl -d Ubuntu-20.04
Welcome to Ubuntu 20.04.6 LTS (GNU/Linux 5.15.167.4-microsoft-standard-WSL2 x86_64)* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantageSystem information as of Thu Feb 13 10:11:59 CST 2025
System load: 0.07 Processes: 82
Usage of /: 0.2% of 1006.85GB Users logged in: 0
Memory usage: 8% IPv4 address for eth0: 172.22.207.57
Swap usage: 0%
Expanded Security Maintenance for Applications is not enabled.164 updates can be applied immediately.
115 of these updates are standard security updates.
To see these additional updates run: apt list --upgradableEnable ESM Apps to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro statusThis message is shown once a day. To disable it please create the
/root/.hushlogin file.
4.校验: