6
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

WSL2でsystemctlを使えるようにする

Posted at

環境

・Ubuntu20.04

WSL2の弊害・対策

・WSL2でsystemctlコマンドを実行すると、下記のようなエラーが出てしまい使えなくなってしまいます。
・「genie」をインストールすることでsystemctlを使えるようにします。
※ちなみにディズニーのアラジンに出てくる「ジーニー」のことらしいです。

$ systemctl
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down

systemctlとは?

・サービスを管理するコマンド。うーん、よくわからない。

そもそも「サービス」とは?

・意外とわからなかったりします。
・正解は「WindowsOSにおける”常駐プログラム"」です。つまり、見た感じでは特に作動していないように見えるが、ソフトウェアを動かすために動いてくれている裏方のこと。
・画像のように、たくさんのサービスが裏で動いてくれています!ありがたや!
・UNIX系OSでは「サービス」ではなく「デーモン(daemon)」と呼びます。目に見えない悪魔ということですね。

image.png

コマンド例

※「hoge」にはサービス名、すなわちapache2, nginx, mysqlなどが入ります。

systemctl start hoge
systemctl stop hoge
systemctl restart hoge
systemctl reload hoge
systemctl enable hoge //自動起動を有効化。重要
systemctl disable hoge //自動起動を無効化。
systemctl status hoge //状態確認。重要

genieのインストール(準備)

# 必要なパッケージのインストール1
sudo apt install daemonize dbus gawk libc6 libstdc++6 policykit-1 systemd systemd-container
# 必要なパッケージのインストール2
wget https://packages.microsoft.com/config/debian/10/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb

# パッケージの最新版を取得、更新
sudo apt update
sudo apt upgrade
 
# dotnet-runtime-5.0をインストール
sudo apt install dotnet-runtime-5.0

genieのインストール

sudo 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

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

# rootユーザーで実施。入力後exit
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

sudo apt update
sudo apt install systemd-genie

# 実行
genie -l
# もし「Waiting for systemd....!!!!!!!」で止まるようならCtrl+Cで停止した後で実行
genie -s
6
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?