WSL 默认安装在 C 盘,随着系统的使用,会占用我们 C 盘的空间,所以我们可以将其迁移放到其他盘去。
- 查看 WSL 发行版本
在 Windows PowerShell 中输入命令:wsl -l --all -v
- 导出分发版为 tar 文件到 D 盘
wsl --export Ubuntu-20.04 d:\wsl-ubuntu20.04.tar
(Ubuntu-20.04 修改成你现在的发行版名称)
-
注销当前分发版
wsl --unregister Ubuntu-20.04
(Ubuntu-20.04 修改成你现在的发行版名称)
-
重新导入并安装 WSL 在 D:\wsl-ubuntu20.04(可以修改成你自己想要的目录)
wsl --import Ubuntu-20.04 d:\wsl-ubuntu20.04 d:\wsl-ubuntu20.04.tar --version 2
- 设置默认登录用户为安装时用户名
ubuntu2004 config --default-user Username
- 删除 tar 文件(可选)
del d:\wsl-ubuntu20.04.tar
示例
C:\Users\yourname> wsl -l -v
NAME STATE VERSION
* Ubuntu-20.04 Running 2
C:\Users\yourname>
C:\Users\yourname> wsl --shutdown
C:\Users\yourname>
C:\Users\yourname> wsl -l -v
NAME STATE VERSION
* Ubuntu-20.04 Stopped 2
C:\Users\yourname> wsl --export Ubuntu-20.04 d:\wslworkspace\ubuntu.tar
C:\Users\yourname>
C:\Users\yourname> wsl --unregister Ubuntu-20.04
正在注销...
C:\Users\yourname>
C:\Users\yourname> wsl --import Ubuntu-20.04 D:\wslworkspace\ubuntu20.04\ d:\wslworkspace\ubuntu.tar --version 2
C:\Users\yourname>
C:\Users\yourname> wsl -l -v
NAME STATE VERSION
* Ubuntu-20.04 Stopped 2
C:\Users\yourname>
C:\Users\yourname> ubuntu2004.exe config --default-user sure
C:\Users\yourname> wsl -d Ubuntu-20.04
适用于 Linux 的 Windows 子系统现已在 Microsoft Store 中可用!
你可以通过运行“wsl.exe --update”或通过访问 https://aka.ms/wslstorepage 进行升级
从 Microsoft Store 安装 WSL 将可以更快地获取最新的 WSL 更新。
有关详细信息,请访问 https://aka.ms/wslstoreinfo
Welcome to Ubuntu 20.04.6 LTS (GNU/Linux 5.10.16.3-microsoft-standard-WSL2 x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/pro
System load: 0.0 Processes: 43
Usage of /: 48.8% of 250.98GB Users logged in: 0
Memory usage: 1% IPv4 address for eth0: 172.29.68.82
Swap usage: 0%
* Strictly confined Kubernetes makes edge and IoT secure. Learn how MicroK8s
just raised the bar for easy, resilient and secure K8s cluster deployment.
https://ubuntu.com/engage/secure-kubernetes-at-the-edge
Expanded Security Maintenance for Applications is not enabled.
2 updates can be applied immediately.
To see these additional updates run: apt list --upgradable
Enable ESM Apto receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status
发现在已经安装的应用,可以直接迁移
发现个新大陆,已经安装的应用,可以直接迁移。但会带来什么影响,需要研究一下。