将默认安装的 WSL2 迁移至指定目录
将默认安装的 WSL2 迁移至指定目录1. 默认安装的 WSL2 目录2. 将安装的 WSL2 迁移至指定目录3. 通过终端打开 Ubuntu-20.04ReferencesWSL2 默认安装在 C 盘下系统盘空间有限推荐迁移安装目录。1. 默认安装的 WSL2 目录C:\Users\cheng\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu20.04onWindows_79rhkp1fndgsc\LocalState\ext4.vhdxC:\Users\cheng\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu_79rhkp1fndgsc\LocalState\ext4.vhdx2. 将安装的 WSL2 迁移至指定目录wsl --list --verbose-wsl -l -v查看安装在 Windows 计算机上的 Linux 发行版列表其中包括状态和运行发行版的 WSL 版本 (WSL 1 或 WSL 2)。wsl --shutdown立即终止所有正在运行的发行版和 WSL 2 轻量级实用工具虚拟机。Microsoft Windows [版本 10.0.22621.1265] (c) Microsoft Corporation。保留所有权利。 C:\Users\chengwsl --list --verbose NAME STATE VERSION * Ubuntu-20.04 Running 2 C:\Users\cheng C:\Users\chengwsl -l -v NAME STATE VERSION * Ubuntu-20.04 Running 2 C:\Users\cheng C:\Users\chengwsl --shutdown C:\Users\cheng C:\Users\chengwsl --list --verbose NAME STATE VERSION * Ubuntu-20.04 Stopped 2 C:\Users\chengwsl --export Ubuntu-20.04 f:\ubuntu20.04.tar将指定tar文件导出为新的发行版。--export选项后面是查看运行状态中 Linux 系统的名字。C:\Users\chengwsl --export Ubuntu-20.04 f:\ubuntu2004.tar C:\Users\chengUnregister or uninstall a Linux distribution (注销或卸载 Linux 发行版)While Linux distributions can be installed through the Microsoft Store, they can’t be uninstalled through the store.尽管可以通过 Microsoft Store 安装 Linux 发行版但无法通过 Store 将其卸载。To unregister and uninstall a WSL distributionwsl --unregister DistributionNameReplacingDistributionNamewith the name of your targeted Linux distribution will unregister that distribution from WSL so it can be reinstalled or cleaned up. Caution: Once unregistered, all data, settings, and software associated with that distribution will be permanently lost. Reinstalling from the store will install a clean copy of the distribution. For example,wsl --unregister Ubuntuwould remove Ubuntu from the distributions available in WSL. Runningwsl --listwill reveal that it is no longer listed.如果将DistributionName替换为目标 Linux 发行版的名称则将从 WSL 取消注册该发行版以便可以重新安装或清理它。警告取消注册后与该分发版关联的所有数据、设置和软件将永久丢失。从 Store 重新安装会安装分发版的干净副本。 例如wsl --unregister Ubuntu将从可用于 WSL 的发行版中删除 Ubuntu。运行wsl --list将会显示它不再列出。You can also uninstall the Linux distribution app on your Windows machine just like any other store application. To reinstall, find the distribution in the Microsoft Store and selectLaunch.还可以像卸载任何其他应用商店应用程序一样卸载 Windows 计算机上的 Linux 发行版应用。若要重新安装请在 Microsoft Store 中找到该发行版然后选择Launch。C:\Users\chengwsl --list --verbose NAME STATE VERSION * Ubuntu-20.04 Stopped 2 C:\Users\cheng C:\Users\chengwsl --unregister Ubuntu-20.04 正在注销... C:\Users\cheng C:\Users\chengwsl --list --verbose 适用于 Linux 的 Windows 子系统没有已安装的分发版。 可以通过访问 Microsoft Store 来安装分发版: https://aka.ms/wslstore C:\Users\chengwsl --import Ubuntu-20.04 f:\ubuntu_20_04 f:\ubuntu2004.tar将指定tar文件导入为新的发行版。wsl --import Distribution Name InstallLocation FileName C:\Users\chengwsl --import Ubuntu-20.04 f:\ubuntu_20_04 f:\ubuntu2004.tar C:\Users\cheng迁移成功之后可在安装目录下查看 vhdx 文件。F:\ubuntu_20_04\ext4.vhdxubuntu2004.exe config --default-user yongqiang设置默认登陆用户为安装时的用户名。C:\Users\chengubuntu2004.exe config --default-user yongqiang C:\Users\cheng删除f:\ubuntu2004.tar文件C:\Users\chengdel f:\ubuntu2004.tar C:\Users\cheng3. 通过终端打开Ubuntu-20.04在 Windows 图标 [开始] 处点击鼠标右键终端 / 终端 (管理员)References[1] Yongqiang Cheng (程永强), https://yongqiang.blog.csdn.net/