systemd 已可用于 WSL
WSL systemd

> 
> 微软的 WSL 现已支持 systemd，为用户提供了更好的体验。你可阅读此文了解更多。
> 
> 
> 


![systemd 已可用于 WSL](/data/attachment/album/202209/25/103049wo515nibzxy1b411.png)


WSL（<ruby> Windows 的 Linux 子系统 <rt>  Windows Subsystem for Linux </rt></ruby>）终于拥有了对 systemd 的支持，这是在 systemd 的创建者加入微软的几个月后实现的。



> 
> **[更多 Linux 开发者们加入微软，systemd 的创建者也加入这一行列](https://news.itsfoss.com/systemd-creator-microsoft/)**
> 
> 
> 


而这已通过微软和 Cannonical 的合作成为可能。



> 
> **如果你好奇 systemd 是什么**：
> 
> 
> systemd 是一套 Linux 系统的基本组成模块。它提供了一个系统和服务管理器，作为 PID 1 运行，并启动系统的其他部分。
> 
> 
> 来自：[systemd.io](http://systemd.io)
> 
> 
> 


它作为一个初始化系统，启动并维持用户空间其他服务的正常运行。


让我们看看它是如何被引入 WSL 的。


### systemd 增强 WSL 的体验






在 WSL 中引入 systemd，主要是为改善 Windows 机器上的 Linux 工作流程。


像 Debian、Ubuntu、Fedora 等，都是默认运行 systemd 的。因此，这项整合将使这些发行版的用户更方便地在 WSL 上做更多工作。


很多关键的 Linux 程序也是靠 systemd 实现的。例如 snap、microk8s 和 LXD 都依赖它。


即使我们有 [不含 systemd 的发行版](https://itsfoss.com/systemd-free-distros/) 可用，它们也并不适合所有人。因此，在 WSL 上添加对 systemd 的支持是很有意义的。


systemd 的存在也使得在 Windows 中使用更多工具来测试和运行成为可能，从而带来更好的 WSL 体验。


### 它是如何实现的


WSL 背后的团队必须修改其架构，它们让 WSL 的初始化进程在 Linux 发行版中以 systemd 的一个子进程启动。


正如其 [官方公告](https://devblogs.microsoft.com/commandline/systemd-support-is-now-available-in-wsl/) 所述，这样做使得 WSL 初始化程序能够为 Windows 和 Linux 子系统之间的通讯提供必要的基础。


它们还做了额外的修改，通过防止 systemd 保持 WSL 实例的活动以确保系统的干净关机。


你亦可访问他们的 [官方文档](https://learn.microsoft.com/en-in/windows/wsl/) 以了解更多。


### 在 WSL 上使用 systemd



> 
> 现有的 WSL 用户必须在他们的系统上手动启用 systemd，以防止由于 systemd 的引入而导致的启动问题。
> 
> 
> 


首先，你必须确保你的系统运行的是 **0.67.6** 或更高版本的 WSL。


你可以通过以下命令检查你的 WSL 版本。



```
wsl --version

```

如果你正在运行旧版本，你可以通过 <ruby> 微软应用商店 <rt>  Microsoft Store </rt></ruby> 或者以下命令更新它。



```
wsl --update

```

此外，如果你不是 <ruby> Windows 预览体验成员 <rt>  Windows Insider </rt></ruby>，你可以到 [WSL 发行页面](https://github.com/microsoft/WSL/releases) 下载它来体验。


为了让 systemd 在你的系统上运行，你需要修改 [wsl.conf](https://learn.microsoft.com/en-in/windows/wsl/wsl-config#wslconf) 这个文件以确保 systemd 在启动时运行。


在 `wsl.conf` 添加以下几行以使 WSL 在启动时运行 systemd



```
[boot]
systemd=true

```

最后，重启你的 WSL 实例以见证更改。


随着对 systemd 的支持，微软在 WSL 的发展又前进了一大步，这将使得 WSL 吸引更多用户。


*? 是否对 WSL 支持 systemd 感到兴奋？或是你更喜欢无 systemd 的发行版？*




---


via: <https://news.itsfoss.com/systemd-wsl/>


作者：[Sourav Rudra](https://news.itsfoss.com/author/sourav/) 选题：[lkxed](https://github.com/lkxed) 译者：[vvvbbbcz](https://github.com/vvvbbbcz) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
![](/assets/images/pikapods-banner-v3.webp)


![](/assets/images/pikapods-banner-v3.webp)

WSL (Windows Subsystem for Linux) has finally received support for Systemd, this comes in a few months after its creator joined Microsoft.

[More Linux Developers Joining Microsoft, Systemd Creator Adds to the ListMicrosoft always gets the attention for some reason when it comes to open-source and Linux. And, it also comes to the limelight when we talk about Linux developers…why? It seems that Microsoft is hiring a lot of Linux developers for a range of projects. And, a popular name has](https://news.itsfoss.com/systemd-creator-microsoft/)![](https://news.itsfoss.com/content/images/wordpress/2022/07/more-linux-devs-joing-microsoft-systemd-creator-add-list.jpg)


![](https://news.itsfoss.com/content/images/wordpress/2022/07/more-linux-devs-joing-microsoft-systemd-creator-add-list.jpg)

And this has been made possible with a partnership between Microsoft and Canonical.

**In case you're curious**:

systemd is a suite of basic building blocks for a Linux system. It provides a system and service manager that runs as PID 1 and starts the rest of the system.

viasystemd.io

It acts as an init system that starts up and keeps user space services in running order.

Let's see how it has been introduced to WSL.

## Systemd Enhancing the WSL Experience

The main focus of introducing systemd to WSL is to improve the Linux workflow on Windows machines.

The likes of Debian, Ubuntu, Fedora, and more run systemd by default. So, this integration will now make it even more straightforward for users of those distros to conveniently do more with WSL.

Even though we have systemd-free distros available, it is not meant for everyone. So, the support for systemd on WSL makes sense.

A lot of critical Linux applications also rely on systemd to be functional. For instance, '**snap**', '**microk8s**' and '**LXD**' are dependent on it.

The presence of systemd also makes it possible to use more tools to test and run from within Windows, resulting in a better WSL experience.

### Suggested Read 📖

[14 Best Systemd-Free Linux Distributionssystemd has been adopted by most major Linux distribution. If you don’t like systemd at all, here are the alternative Linux distros for you.](https://itsfoss.com/systemd-free-distros/?ref=news.itsfoss.com)![](https://itsfoss.com/wp-content/uploads/2022/03/systemd-free-distros.png)


![](https://itsfoss.com/wp-content/uploads/2022/03/systemd-free-distros.png)

## Here's How It Was Made Possible

The team behind WSL had to make changes to the architecture, they made the WSL init process start within the Linux distro as a child process under systemd.

Doing so enabled the WSL init process to provide the necessary foundation for communication between the Windows and Linux sub-systems, as explained in their [official announcement](https://devblogs.microsoft.com/commandline/systemd-support-is-now-available-in-wsl/?ref=news.itsfoss.com).

They also did additional modifications to ensure a clean system shutdown by preventing systemd from keeping the WSL instance active.

You can also visit their official [documentation](https://learn.microsoft.com/en-in/windows/wsl/?ref=news.itsfoss.com) website for more information.

## Get Started With Systemd on WSL

First and foremost, you have to ensure that your system is running WSL: **Version 0.67.6** or above.

You can check your WSL version by running the following command

`wsl --version`


If you are running the older version, you can update it via the **Microsoft Store** or by running this command.

`wsl --update`


Furthermore, if you are not a part of Windows Insiders, you can go to the [WSL release page](https://github.com/microsoft/WSL/releases?ref=news.itsfoss.com) and download it to test it out.

For systemd to work on your system, you will have to edit the '[wsl.conf](https://learn.microsoft.com/en-in/windows/wsl/wsl-config?ref=news.itsfoss.com#wslconf)' file to ensure that systemd starts up on boot.

Add the following lines to make WSL run systemd on boot.

```
[boot]
systemd=true
```


Finally, restart your WSL instance to see the changes.

Microsoft has taken a big step forward in the development of WSL with the implementation of systemd, this should result in more users being attracted to WSL.

**💬 **Excited to run WSL with systemd? Or do you prefer systemd-free distros?

## More from It's FOSS...

- Support us by opting for
[It's FOSS Plus](https://itsfoss.com/#/portal/signup)membership. - Join our
[community forum](https://itsfoss.community/). - 📩 Stay updated with the latest on Linux and Open Source. Get our
[weekly Newsletter](https://itsfoss.com/newsletter/).