Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added docs/Appendix/images/vscode-store-remote-wsl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 7 additions & 61 deletions docs/Ch10/index.md → docs/Appendix/wsl.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,82 +60,32 @@ wsl --set-default-version 2

### 从微软商店下载 {#install-distro-msstore}

在微软商店中直接搜索对应的发行版进行安装即可,这种方法可以安装的发行版并不多,如 Arch Linux 和 Fedora 就无法通过这种方法进行安装
在微软商店中直接搜索对应的发行版进行安装即可。这种方法仅支持一部分发型版,如 Ubuntu 和 Debian 等
Comment thread
xiaoh1024 marked this conversation as resolved.
Outdated

![Microsoft Store Search Result](./images/ms-store-search-linux.png)

### 使用 Appx 文件进行安装 {#install-distro-appx}

有的打包为 Appx 的分发方式,也有提供了可执行应用程序来进行安装,在仓库里面提供了安装方式

- ArchLinux: [ArchWSL](https://github.com/yuk7/ArchWSL)
- Fedora: [FedoraWSL](https://github.com/yosukes-dev/FedoraWSL)
- Manjaro: [ManjaroWSL](https://github.com/sileshn/ManjaroWSL)
- Gentoo: [GentooWSL](https://github.com/imaandrew/GentooWSL)

### 使用 LxRunOffline 进行安装 {#install-lxrunoffline}

LxRunOffline 是进行 WSL 管理的一个应用程序,可以帮助管理 WSL 的安装与配置

LxRunOffline 仓库:[LxRunOffline](https://github.com/DDoSolitary/LxRunOffline)

LxRunOffline 是通过 Windows 提供的 API 来进行管理 WSL 的一个命令行工具

#### 例:安装 Arch Linux {#install-lxrunoffline-archlinux}

可以从 [LxRunOffline/wiki](https://github.com/DDoSolitary/LxRunOffline/wiki) 里面下载需要的发行版的 rootfs

对于 ArchLinux,可以从[这个链接](https://lxrunoffline.apphb.com/download/ArchLinux),下载 ArchLinux 的 rootfs 得到 `archlinux-bootstrap-*.tar.gz`

使用 LxRunOffline 进行安装

```shell
./LxRunOffline i -n ArchLinux -d D:/wsl/ArchLinux -f ./archlinux-bootstrap-*.tar.gz
```

- `-n` WSL 的名称

- `-d` 希望安装的位置,通过这种方法可以不需要将 wsl 安装在 C 盘

需要注意的是,这个安装方法不会在开始菜单中添加启动快捷方式,只能够通过命令行的方式启动:

```powershell
wsl -d ArchLinux
```

在安装完成后打开,默认是以 root 的身份执行,如果需要默认以其他的用户的身份运行,可以在添加了用户后,使用 LxRunOffline 运行:

```shell
./LxRunOffline su -n ArchLinux -v 1000
```

其中:

- `ArchLinux` 是 WSL 的名
- `-v 1000` 是设置登录的用户的 UID
- Manjaro: [ManjaroWSL2](https://github.com/sileshn/ManjaroWSL2)
- Gentoo: [GentooWSL2](https://github.com/imaandrew/GentooWSL2)

## 使用 {#usage}

### VS Code {#vscode-remote-wsl}

在 VS Code 中安装插件 "Remote - WSL" 后,可以像 "Remote - SSH" 一样使用 WSL
在 VS Code 中安装插件 "WSL" 后,可以像 "Remote - SSH" 一样使用 WSL

(或者也可以直接安装 "Remote Development" 插件,里面包含了 "WSL" 插件)
Comment thread
xiaoh1024 marked this conversation as resolved.
Outdated

![VS Code Store "Remote - WSL"](./images/vscode-store-remote-wsl.png)
![VS Code Store "WSL"](./images/vscode-store-remote-wsl.png)

### JetBrains {#jetbrains-remote-wsl}

包括 IntelliJ IDEA、PyCharm、WebStorm 等,都有对 WSL 的支持。在打开了 WSL 下的目录后,
会自动地选择 WSL 下的工具链,Git 会使用 WSL 中安装的 Git 而不是 Window 下的 Git。

但是还有一些问题仍待解决,如 PyCharm 并不支持 WSL 中的虚拟环境,在添加 Python Inpterpreter 时,
无法检测并使用现有的如 `virtualenv`、`conda` 等创建的虚拟环境,也无法创建。

对应的的 Issue:[PY-32853](https://youtrack.jetbrains.com/issue/PY-32853)

可以 workaround 来解决:在添加 Python Inpterpreter 时,添加 System Python Inpterpreter 而不是
Virtual Environment,在路径中填写虚拟环境下的 Python 路径,PyCharm 可以正确识别安装的包,但是在打开
终端的时候,不会自动地 `source` 虚拟环境。

### 在 WSL 中使用资源管理器打开文件夹 {#open-folder-in-wsl}

在 WSL 的终端中,直接输入 `explorer.exe .`,会在当前目录下打开资源管理器,也可以使用 Windows 上的应用程序打开相应的文件。
Expand All @@ -154,7 +104,3 @@ WSL 2 由于相当于是通过网络的方式访问 `/mnt/` 下的文件,导
可以通过将文件放在 `/` 下(不包括 `/mnt/`),来提高性能。

相关的 Issue 和评论:[microsoft/WSL#4197](https://github.com/microsoft/WSL/issues/4197#issuecomment-604592340)

### systemd {#systemd}

无论是 WSL 1 还是 WSL 2,都不原生支持 systemd,如果需要 systemd,可以通过 [systemd-genie](https://github.com/arkane-systems/genie) 来实现。
4 changes: 4 additions & 0 deletions docs/Ch01/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ Android TV 图标

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

!!! info "WSL"

如今,对于 Windows 用户来说,使用 WSL 安装 Linux 或许会是更加便捷的方法,详情可以参考[附录](../Appendix/wsl.md)
Comment thread
xiaoh1024 marked this conversation as resolved.
Outdated

### 获取虚拟机管理软件 {#get-vm-softwares}

现在在 Windows / macOS 上主流的虚拟机管理软件有:
Expand Down
4 changes: 2 additions & 2 deletions docs/credits.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

## 主要贡献者 {#team}

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

各章主要作者:

- 第一章:[RiessarSadyx](https://github.com/RiessarSadyx)
- 第一章:[Riessarius](https://github.com/Riessarius)
- 第二章:[LamWS](https://github.com/LamWS)
- 第三章:[zeyugao](https://github.com/zeyugao)
- 第四章:[psi-cmd](https://github.com/psi-cmd)
Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,4 @@ nav:
- Markdown 教程: Appendix/markdown.md
- man 文档的一些示例: Appendix/man.md
- 其他的 Linux 发行版:技术差异简介: Appendix/distribution.md
- 使用 WSL 安装 Linux: Appendix/wsl.md