WSL2安装systemd方法

确保systemd在wsl 2发行版中启用,可以按照以下步骤进行操作:

  1. 下载并运行最新的安装程序脚本

    使用以下命令下载并运行安装脚本:

    curl -L -O "https://raw.githubusercontent.com/nullpo-head/wsl-distrod/main/install.sh"
    chmod +x install.sh
    sudo ./install.sh install

    此脚本会安装Distrod,但尚未启用它。

  2. 在发行版中启用Distrod

    有两种选择:

    • 如果希望在Windows启动时自动启动Distrod,请使用以下命令:

      /opt/distrod/bin/distrod enable --start-on-windows-boot
    • 如果不需要在Windows启动时自动启动Distrod,则使用以下命令:

      /opt/distrod/bin/distrod enable

    如果以后需要启用自动启动,可以再次运行带有

    --start-on-windows-boot
    的命令。

  3. 重新启动发行版

    关闭WSL的终端,打开一个新的命令提示符窗口,然后运行以下命令:

    wsl --terminate Distrod

    重新打开新的WSL窗口后,shell将在systemd会话中运行。

安装完成后,可以运行以下命令来检查systemd的状态:

systemctl status | cat