ubuntu for wsl2
之前在wsl2下的python查看版本时发现python版本相同,以为是链接着win的python,之后发现应该是巧合而已,Ubuntu默认安装了python,nodejs也要在wsl2里面重新装一遍,不过也从侧面看出wsl和win的文件状态的分隔,这在官方参考也提到。
Comparing WSL 1 and WSL 2
之前提到vhdx文件应该可以通过设置,使wsl2的默认储存位置在指定数据盘,以节省空间,具体操作如下
- 导出当前镜像
使用wsl --export [distros_name] ./new_name.tar
- 将tar文件导入指定位置并作为wsl镜像文件
使用wsl --import [new_distros_name] D:\locationfolder .\Ubuntu_distros.tar
这样就把tar文件import到本地D:\locationfolder下并作为wsl镜像 - 检查
使用wsl -l
,可以查到两个distros适用于 Linux 的 Windows 子系统分发版: old_name (默认) new_name
- 注销原本的的distros
使用wsl --unregister old_name
这样就把占用c盘的wsl镜像复制到其他盘了,原本C:\Users\IvanGrishagin\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState
下的镜像文件也会在注销后自动删除。如果不想注销掉原本的,不执行4,使用wsl --distribution new_name
可运行刚复制过来的镜像
参考:
how to move the vhdx of wsl2 to other disk
WSL commands and launch configurations
还有通过修改注册表的,可参考
Change Location of WSL2 Container
Oct 26, 2020