「Windows」- Subsystem for Linux,WSL

  CREATED BY JENKINSBOT

问题描述

WSL:在 Windows 中,使用 GNU Linux 工具的方法。

该笔记将记录:在 Windows 中,如何使用 WSL 模块,以及相关问题的解决方法。

注意事项

# 09/13/2021

我们需要在笔记本中运行 VirtualBox 5.2 版本,但是 VirtualBox 与 Hyper-V 不能共存:
1)如果开启 Hyper-V 模块,那么 VirtualBox 将提示 VT-x is not available 错误;
2)如果关闭 Hyper-V 模块,那么 WLS 2 将提示 The specified network name is no longer available 错误;

鉴于 VirtualBox 能够将 主机文件系统挂在到 虚拟机中,所以能够在 Linux 环境下进行操作。这能够满足我们的需求,所以我们放弃使用 WSL 2 特性。

安装 WSL 模块

参考 Windows Subsystem for Linux Installation Guide for Windows 10 文档。

安装步骤:
1)在 Control Panel ⇒ Programs ⇒ Turn Windows features on or off 中,
2)启用 Windows Subsystem for Linux 选项,并重启主机;
3)在 Microsoft Store 中,搜索并安装 Ubuntu 20.04 TLS 发行版;

在安装完成后,Windows Terminal 能够快速进入 Ubuntu 20.04 中(如果需要设置,参考 Install and set up Windows Terminal 文档)

常用操作

查看当前 WSL 运行版本

WSL: Am I running version 1 or version 2?

# wsl -l -v
  NAME      STATE           VERSION
* Ubuntu    Stopped         1

挂载新磁盘

How to Mount Windows Network Drives in WSL

当主机插入 U 盘或者其他磁盘设备后,需要挂载到 WSL 中:

mount -t drvfs M: /mnt/m

常见问题处理

The specified network name is no longer available.(指定的网络名不再可用)

WSL 2 FAQs

原因分析,正如 Microsoft 官方 FAQ 所说:

Will I be able to run WSL 2 and other 3rd party virtualization tools such as VMware, or VirtualBox?

Some 3rd party applications cannot work when Hyper-V is in use, which means they will not be able to run when WSL 2 is enabled, such as VMware and VirtualBox. However, recently both VirtualBox and VMware have released versions that support Hyper-V and WSL2. Learn more about VirtualBox’s changes here and VMware’s changes here. For troubleshooting issues, take a look at the VirtualBox issue discussions in the WSL repo on GitHub.

We are consistently working on solutions to support third-party integration of Hyper-V. For example, we expose a set of APIs called Hypervisor Platform that third-party virtualization providers can use to make their software compatible with Hyper-V. This lets applications use the Hyper-V architecture for their emulation such as the Google Android Emulator, and VirtualBox 6 and above which are both now compatible with Hyper-V.

解决方案,我们需要开启 Hyper-V 组件,但为了 VirtualBox 能够正常运行,需要升级 VirtualBox 至 6.0.0 版本(VirtualBox 不支持以多版本运行),因为在 alBox 6.0.0 中 Added support for using Hyper-V as the fallback execution core on Windows host, to avoid inability to run VMs at the price of reduced performance