# WSL子系统教程介绍

**在使用安装器自动安装子系统时，可能会由于电脑设置及windows内核版本较低出现各种问题，这里，提供一些子系统的基础知识以及手动安装子系统的教程，来帮助各位解决安装中出现的问题**

官方基础使用教程链接为：<https://learn.microsoft.com/en-us/windows/wsl/basic-commands>

## 一、WSL子系统基本命令

{% hint style="info" %}
**WSL子系统安装命令**

wsl --install <发布版名称>
{% endhint %}

其中，发布版名称可以通过wsl --list --online进行查询

{% hint style="info" %}
**将子系统默认版本设置为2**

wsl --set-default-version 2
{% endhint %}

在WSL 1和WSL 2之间切换可能会耗费时间，并由于两种架构之间的差异导致失败。对于拥有大型项目的发行版，我们建议在尝试转换之前备份文件。

{% hint style="info" %}
**子系统更新**

wsl --update
{% endhint %}

子系统更新是最容易出现问题的地方，尤其是容易受到网络影响出现卡顿问题，需要根据具体报错情况进行修复，由于需要从GitHub或者Microsoft Store上下载对应的内核，因此推荐科学上网进行安装。

如果要安装老版本wsl，则需要使用命令：

* `--web-download`: 该命令从GitHub上下载对应的wsl子系统，而不是从Microsoft Store上下载。

{% hint style="info" %}
**子系统关闭**

wsl --shutdown
{% endhint %}

外部关闭子系统，相当于关机功能，如果同时运行多个镜像，则会全部关闭

{% hint style="info" %}
**指定关闭某一个发行版子系统**

wsl --terminate <发行版名称>
{% endhint %}

通过这种方法，在同时运行多个子系统镜像时可以指定关闭某一个镜像

{% hint style="info" %}
**查看子系统IP地址**

wsl hostname -i 是一种从CMD中查看IP地址的方法

cat /etc/resolv.conf是在wsl命令窗中查看子系统默认IP的方法
{% endhint %}

子系统的IP地址设置是非常关键的，同理，可以通过修改/etc/resolv.conf中的IP地址来设置子系统的默认IP

{% hint style="info" %}
**导出当前发行版到镜像文件**

&#x20; wsl --export <发行版名称> <导出路径>
{% endhint %}

这里，要说明的是，发行版名称为对应的子系统名称，导出路径最终命名应为一个tar文件

{% hint style="info" %}
**导入一个发行版系统镜像**

wsl --import <发行版名称> <安装路径> <镜像地址>
{% endhint %}

导入系统时应确保目前子系统没有同名，否则会被覆盖或者报错，这一步请谨慎操作，防止丢失文件

{% hint style="info" %}
**注销或者卸载一个Linux发行版系统**

wsl --unregister <发行版名称>
{% endhint %}

该操作可以直接卸载或者注销掉对应名称的子系统，


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bit-sigma.gitbook.io/tutorials-for-sigma-free/sigma-free-fang-zhen-xi-tong-jian-jie/an-zhuang-zhi-nan/wsl-zi-xi-tong-jiao-cheng-jie-shao.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
