Skip to content

Commit ddee445

Browse files
xiaoh1024taoky
andauthored
Add WSL related content (#98)
* Add WSL related content * Update credits.md * Fix prettier lint error * Update docs/Ch01/index.md Co-authored-by: taoky <[email protected]> * Update docs/Appendix/wsl.md Co-authored-by: taoky <[email protected]> * Update docs/Appendix/wsl.md Co-authored-by: taoky <[email protected]> * wsl: Style update * Update docs/Appendix/wsl.md * wsl: Fix typo --------- Co-authored-by: taoky <[email protected]>
1 parent f7f5758 commit ddee445

File tree

7 files changed

+117
-162
lines changed

7 files changed

+117
-162
lines changed
51.2 KB
Loading

docs/Appendix/wsl.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Windows Subsystem for Linux
2+
3+
!!! Warning "本文仍在编辑中,尚未校对、审阅和修订"
4+
5+
!!! abstract "导言"
6+
7+
本章节将介绍在 Windows 上体验和使用 Linux 的较好的方法之一——Windows Subsystem for Linux。
8+
9+
WSL 有着接近原生的性能、GPU 的支持和极易的安装方法,完整的 Linux 内核环境可以在涵盖绝大部分的 Linux 日常开发环境。
10+
11+
## 安装 {#install}
12+
13+
### 自动安装方法 {#install-auto}
14+
15+
在 Windows 10 Build 19041(Windows 10 2004)版本或以上,可以通过一条命令直接完成安装(需要以管理员身份运行):
16+
17+
```shell
18+
wsl --install
19+
```
20+
21+
这条命令会完成如下几个操作:
22+
23+
- 启用 WSL 和虚拟化平台
24+
- 下载并安装 WSL 的 Linux 内核
25+
- 设定 WSL 2 默认的版本
26+
- 从微软商店里面下载 Ubuntu 进行安装
27+
28+
安装完毕之后可以直接通过 `ubuntu` 命令启动。
29+
30+
### 手动安装 {#install-manual}
31+
32+
如果系统版本在 Windows 10 Build 19041 以下,如 Windows 10 LTSC 2019,需要手动配置系统。
33+
34+
#### 启用 WSL 和虚拟化平台 {#enable-windows-features}
35+
36+
使用管理员身份在 Powershell 中运行:
37+
38+
```batch
39+
Dism.exe /Online /Enable-feature /Featurename:Microsoft-Windows-Subsystem-Linux /All /NoRestart
40+
Dism.exe /Online /Enable-feature /Featurename:VirtualMachinePlatform /All /NoRestart
41+
```
42+
43+
#### 安装 Linux 内核 {#install-linux-kernel}
44+
45+
从微软下载 Linux 内核用于 Windows 的更新,并根据机器架构选择安装:
46+
47+
- [x64 内核](https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi)(绝大部分电脑)
48+
- [ARM64 内核](https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_arm64.msi)(使用高通等品牌 CPU 的电脑)
49+
50+
#### 设置 WSL 2 为默认的 WSL 版本 {#set-default-wsl-version}
51+
52+
```powershell
53+
wsl --set-default-version 2
54+
```
55+
56+
## 安装发行版 {#install-distro}
57+
58+
有许多的方法安装一个新的发行版。
59+
60+
### 从微软商店下载 {#install-distro-msstore}
61+
62+
在微软商店中直接搜索对应的发行版进行安装即可。这种方法仅支持一部分发行版,如 Ubuntu 和 Debian 等。
63+
64+
![Microsoft Store Search Result](./images/ms-store-search-linux.png)
65+
66+
图 1. Microsoft Store 搜素结果
67+
{: .caption }
68+
69+
### 手动安装 {#install-distro-manual}
70+
71+
有些发行版并未上架微软商店,但也有办法安装,比如可以参考下面这两个项目:
72+
73+
- Manjaro: [ManjaroWSL2](https://github.com/sileshn/ManjaroWSL2)
74+
- Gentoo: [GentooWSL2](https://github.com/VPraharsha03/GentooWSL2)
75+
76+
但需要注意,这种安装方式并非发行版官方支持。
77+
78+
## 使用 {#usage}
79+
80+
### VS Code {#vscode-remote-wsl}
81+
82+
在 VS Code 中安装插件 "WSL" 后,可以像 "Remote - SSH" 一样使用 WSL,或者也可以直接安装 "Remote Development" 插件,里面包含了 "WSL" 插件。
83+
84+
![VS Code Store "WSL"](./images/vscode-store-remote-wsl.png)
85+
86+
图 2. Visual Studio Code 搜索 "WSL"
87+
{: .caption }
88+
89+
### JetBrains {#jetbrains-remote-wsl}
90+
91+
包括 IntelliJ IDEA、PyCharm、WebStorm 等,都有对 WSL 的支持。在打开了 WSL 下的目录后,
92+
会自动地选择 WSL 下的工具链,Git 会使用 WSL 中安装的 Git 而不是 Window 下的 Git。
93+
94+
### 在 WSL 中使用资源管理器打开文件夹 {#open-folder-in-wsl}
95+
96+
在 WSL 的终端中,直接输入 `explorer.exe .`,会在当前目录下打开资源管理器,也可以使用 Windows 上的应用程序打开相应的文件。
97+
98+
## 已知的问题 {#known-issues}
99+
100+
### 运行 32 位应用程序 {#32-bit-exe}
101+
102+
由于实现原理,WSL 1 并不支持运行 32 位应用程序。WSL 2 由于是完整的 Linux 内核,在安装了对应的运行时后可以运行 32 位应用程序。
103+
104+
### WSL 下 `/mnt/` 性能问题 {#mnt-performance}
105+
106+
WSL 2 由于相当于是通过网络的方式访问 `/mnt/` 下的文件,导致性能相对于 WSL 1 有明显的下降。
107+
108+
可以通过将文件放在 `/` 下(不包括 `/mnt/`),来提高性能。
109+
110+
相关的 Issue 和评论:[microsoft/WSL#4197](https://github.com/microsoft/WSL/issues/4197#issuecomment-604592340)

docs/Ch01/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ Android TV 图标
213213

214214
因此,本书将主要讲解如何为自己搭建一个安全高效的 Linux 虚拟机。如果你有一台远程的 Linux 服务器,可以参考[拓展阅读](./supplement.md#ssh)的内容配置 SSH 连接。
215215

216+
!!! info "WSL"
217+
218+
如今,对于 Windows 用户来说,使用 WSL 安装 Linux 或许会是更加便捷的方法,详情可以参考[附录](../Appendix/wsl.md)。
219+
216220
### 获取虚拟机管理软件 {#get-vm-softwares}
217221

218222
现在在 Windows / macOS 上主流的虚拟机管理软件有:

docs/Ch10/index.md

Lines changed: 0 additions & 160 deletions
This file was deleted.

docs/credits.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
## 主要贡献者 {#team}
44

5-
项目主策划:[RiessarSadyx](https://github.com/RiessarSadyx)
5+
项目主策划:[Riessarius](https://github.com/Riessarius)
66

77
各章主要作者:
88

9-
- 第一章:[RiessarSadyx](https://github.com/RiessarSadyx)
9+
- 第一章:[Riessarius](https://github.com/Riessarius)
1010
- 第二章:[LamWS](https://github.com/LamWS)
1111
- 第三章:[zeyugao](https://github.com/zeyugao)
1212
- 第四章:[psi-cmd](https://github.com/psi-cmd)

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,4 @@ nav:
118118
- Markdown 教程: Appendix/markdown.md
119119
- man 文档的一些示例: Appendix/man.md
120120
- 其他的 Linux 发行版:技术差异简介: Appendix/distribution.md
121+
- 使用 WSL 安装 Linux: Appendix/wsl.md

0 commit comments

Comments
 (0)