首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Windows上运行多个WSL2实例?

如何在Windows上运行多个WSL2实例?
EN

Stack Overflow用户
提问于 2021-02-05 14:52:03
回答 2查看 9.4K关注 0票数 12

我已经安装了WSL2并在其上部署了两台计算机:

  • CentOS
  • Ubuntu-20.04

可以在我的Ubuntu-20.04机器上运行多个win10实例吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-02-05 17:16:33

是的完全有可能。以下是我推荐的步骤。在PowerShell中(您也可以使用cmd ):

  • 在方便的地方创建一个目录,以便处理WSL图像。当然,我叫我的WSL。这不一定在你的C:\驱动器上。
  • 创建两个子目录,imagesinstances。再说一次,名字真的取决于你。
  • wsl -l -v只是为了确认您当前的发行版名称。
  • 使用类似wsl --export Ubuntu images\2021-02-05_Ubuntu20.04_snapshot.tar的东西备份现有的20.04发行版(当然,假设您的发行版名为"Ubuntu“)。
  • 使用类似于wsl --import Ubuntu20.04_clone instances\Ubuntu20.04_clone images\2021-02-05_Ubuntu20.04_snapshot.tar --version 2的快照创建一个新实例。当ext4.vhdx文件完成时,您应该会在instances\Ubuntu20.04_clone目录中看到它。--version是可选的,但如果需要,可以同时创建WSL1和WSL2实例。(例如,如果需要访问NTFS文件系统,WSL1要快得多。)
  • 使用wsl ~ -d Ubuntu20.04_clone启动该实例。或者重新启动Windows终端(假设您正在使用它),则应该自动检测到新实例。
  • 默认情况下,新实例将作为root启动。您需要通过创建具有以下内容的/etc/wsl.conf来设置您的用户名: 用户default=me ..。当然,替换你的用户名。
  • 退出、终止(通过wsl --terminate Ubuntu20.04_clone)并重新启动该发行版,并确认您的环境正在按您的预期操作。
  • 现在已经确认了新实例的正确操作,下面的步骤是可选的,但建议这样做。(有关另一种方法,请参见u/Zoredache在这个Reddit线程中的注释(复数))。
代码语言:javascript
复制
- "Reset" the old image to a clean state by `wsl --unregister <distroname>` of the original distribution.
代码语言:javascript
复制
- Re-run the "App" (technically it's an "App Execution Alias") from the Windows Start Menu with _Start->Run_ and type _Ubuntu_.  This will re-run the configuration steps and create your default user/password/etc.  (Thanks @JackoBongo for the suggestion in the comments for this).
代码语言:javascript
复制
- For convenience, I recommend going ahead and adding the `/etc/wsl.conf` as described above to this instance.  That will keep you from having to do it each time you add or replace an instance.  Note:  Don't do this if you plan to distribute this image to other users; just if you are doing this for yourself.
代码语言:javascript
复制
- Back up this "clean copy" using the `wsl --export` command as above, to something like `2021-02-05_Ubuntu20.04_default.tar`.  This "clean" version can now be your starting point for a `wsl --import` if you want to spin up a new Ubuntu 20.04 to test something out without worrying that your apps/customizations from your normal working environment get in the way.
代码语言:javascript
复制
- Since you are already running multiple distributions (CentOS and Ubuntu), then I'm guessing you are using something like Windows Terminal already.  But if you launch Ubuntu through the start menu with the "Ubuntu" entry, then you will probably want to copy your cloned `vhdx` file back over the newly installed clean version.  You'll find the "default" version in `%userprofile%\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc` (or something similar).
票数 25
EN

Stack Overflow用户

发布于 2021-09-18 00:27:45

GitHub (我的项目)上也有一个GUI,用于管理多个WSL2实例。也许能帮你节省一点时间。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66065419

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档