systemd
https://github.com/nullpo-head/wsl-distrod
Option 2: Make your Current Distro Run Systemd
By this installation, systemd is enabled in your WSL 2 distro.
-
Download and run the latest installer script.
1
2
3curl -L -O "https://raw.githubusercontent.com/nullpo-head/wsl-distrod/main/install.sh"
chmod +x install.sh
sudo ./install.sh installThis script installs distrod, but doesn’t enable it yet.
-
Enable distrod in your distro
You have two options.
If you want to automatically start your distro on Windows startup, enable distrod by the following command1
/opt/distrod/bin/distrod enable --start-on-windows-boot
Otherwise,
1
/opt/distrod/bin/distrod enable
You can run
enable
with--start-on-windows-boot
again if you want to enable autostart later. -
Restart your distro
Close your WSL’s terminal.
Open a new Command Prompt window, and run the following command.1
wsl --terminate Distrod
After re-opening a new WSL window, your shell runs in a systemd session.
端口转发
下载release到一个目录, 比如C:\Users\qwq\WSLHostPatcher\WSLHostPatcher.exe
在wsl2中systemd使其开机自启:
1 | sudo vi /lib/systemd/system/wsl-host-patcher.service |
1 | [Unit] |
重新加载 systemd
模块
1 | sudo systemctl daemon-reload |
启动 WSLHostPatcher 服务
1 | sudo systemctl start wsl-host-patcher.service |
设置开机自启
1 | sudo systemctl enable wsl-host-patcher.service |
code-server
在wsl2中systemd使其开机自启:
1 | sudo vi /lib/systemd/system/code-server@.service |
1 | [Unit] |
重新加载 systemd
模块
1 | sudo systemctl daemon-reload |
启动 WSLHostPatcher 服务
1 | sudo systemctl start code-server@usr |
设置开机自启
1 | sudo systemctl enable code-server@usr |