WSL2でsystemctlを有効化した時のエラー解決まとめ


初投稿です!

お役に立ちましたら、LGBMお願いします!

PCスペック

・windows 10 Pro 10.0.19042 ビルド 19042
・WSL2(ubuntu 20.04 LTS)

発生した問題

・WSL2にDockerを導入していたところ、systemctlが使えなかった。
こちらのサイトを参考にsystermctl有効化の作業を進めていたが、以下のコマンドでエラーに、、

User@DESKTOP-OOO:/mnt/c/Users/User/WSL2/ubuntu$ curl -s https://packagecloud.io/install/repositories/arkane-systems/wsl-translinux/script.deb.sh | sudo bash
bash: line 1: syntax error near unexpected token `newline'
bash: line 1: `<!DOCTYPE html>'

...とりあえずエラーメッセージをググると、こちら同じサイトで同じエラーの人を発見!
→どうやら記事のバージョンが古くて、「dotnet-sdk-3.1」とか「genie」のインストール方法が古くなってるらしい、、

以下の方法で解決(参考サイト)

・SDK-5.0とaspnetcore-runtime-5.0のインストール(こちら)

1.パッケージリポジトリの追加

wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb

2.SDK-5.0のインストール

sudo apt-get update; \
  sudo apt-get install -y apt-transport-https && \
  sudo apt-get update && \
  sudo apt-get install -y dotnet-sdk-5.0

3.aspnetcore-runtime-5.0のインストール

sudo apt-get update; \
  sudo apt-get install -y apt-transport-https && \
  sudo apt-get update && \
  sudo apt-get install -y aspnetcore-runtime-5.0
  sudo apt-get install -y dotnet-runtime-5.0

・wsl-transdebianリポジトリを追加(こちら)

1.「sudo -s」でrootに移動

2.以下コマンドを実行

apt install apt-transport-https

wget -O /etc/apt/trusted.gpg.d/wsl-transdebian.gpg https://arkane-systems.github.io/wsl-transdebian/apt/wsl-transdebian.gpg

chmod a+r /etc/apt/trusted.gpg.d/wsl-transdebian.gpg

cat << EOF > /etc/apt/sources.list.d/wsl-transdebian.list
deb https://arkane-systems.github.io/wsl-transdebian/apt/ $(lsb_release -cs) main
deb-src https://arkane-systems.github.io/wsl-transdebian/apt/ $(lsb_release -cs) main
EOF

apt update

・genieをインストール&起動1

sudo apt update
sudo apt install -y systemd-genie
genie -s

・Dockerでsystemctlを使ってみる

User@DESKTOP-OOO-wsl:~$ sudo systemctl status docker
● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2021-06-27 11:59:46 JST; 13min ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 306 (dockerd)
      Tasks: 19
     Memory: 54.1M
     CGroup: /system.slice/docker.service
             └─306 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
systemctlが正常に機能していますね!

  1. ここで以下のようなエラーが発生するかもですが、今回Dockerでsystemctlは機能しているので今回は無視します。 

    Timed out waiting for systemd to enter running state.
    This may indicate a systemd configuration error.
    Attempting to continue.
    Failed units will now be displayed (systemctl list-units --failed):
    UNIT LOAD ACTIVE SUB DESCRIPTION
    ● ssh.service loaded failed failed OpenBSD Secure Shell server
    ● systemd-remount-fs.service loaded failed failed Remount Root and Kernel File Systems
    ● multipathd.socket loaded failed failed multipathd control socket

    LOAD = Reflects whether the unit definition was properly loaded.
    ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
    SUB = The low-level unit activation state, values depend on unit type.

    3 loaded units listed.