【WSL2/Ubuntu】systemdをPID1で動かす 2021年3月版

2021年3月31日Linux,環境構築WSL

追記: 2022/11/20

WSL自体がsystemdをサポートしたとのことで記事を投稿しています。
こちらもご確認ください。

追記:2021/07/19

どんな勢いで更新されるんだ、という印象ですが
こちらの内容からインストール方法が変更されていたので再度まとめなおしました。
【WSL2】Ubuntu 20.04でPID1をsystemdにする 2021年7月版


こんにちは、しきゆらです。
今回は、またまたWSL2環境でsystemdをPID1で動かす手順をメモしておきます。

というのも、またまたPCパーツを買ったので組みなおしつつOSをクリーンインストールしました。
1年程度でOSをクリーンインストールするので、妙な不具合なんかは出ないのでとても良いのですが、
WSL2のインストールももう一度やることになります。
以前の記事「【WSL2】Ubuntu20.04でPID1をSystemdにする」を参考にしてみるとうまくいかない。
なんでや、と思ってもろもろ調べてみると結構手順が変わっていたので、調べながらインストールしました。
その手順をメモしておきます。

公式はこちらに移ったようです。
arkane-systems/genie: A quick way into a systemd “bottle" for WSL | https://github.com/arkane-systems/genie

READMEにはトップページを全部読んでね、と書いてあるので読んでおきましょう。
ではインストール。
なお、環境はUbuntu20.04です。

インストール手順

まずは、依存しているライブラリから。
Ubuntuなので、公式のDebianの手順を参考にしていきます。

dotnet-runtime-5.0を以下を参考にインストール。
https://docs.microsoft.com/ja-jp/dotnet/core/install/linux-ubuntu

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
sudo apt-get install -y dotnet-runtime-5.0

続いて本命。
こちらも公式が別で手順を置いてくれていたのでそちらを参考に。
https://arkane-systems.github.io/wsl-transdebian/

sudo apt install apt-transport-https
sudo 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

sudo emacs /etc/apt/sources.list.d/wsl-transdebian.list
// Ubuntu 20.04環境なので<distro>をfocalに置換
deb https://arkane-systems.github.io/wsl-transdebian/apt/ focal main
deb-src https://arkane-systems.github.io/wsl-transdebian/apt/ focal main

これにて準備終わり。
本命をインストール。

sudo apt update 
sudo apt install systemd-genie

これにてインストール完了です。
あとはいつも通りgenie -sとかで動かせば終わり。

一応公式使い方を張っておきます。

# 以下からの引用です
# arkane-systems/genie: A quick way into a systemd "bottle" for WSL | https://github.com/arkane-systems/genie

genie:
  Handles transitions to the "bottle" namespace for systemd under WSL.

Usage:
  genie [options] [command]

Options:
  -v, --verbose <VERBOSE>    Display verbose progress messages
  --version                  Display version information

Commands:
  -i, --initialize           Initialize the bottle (if necessary) only.
  -s, --shell                Initialize the bottle (if necessary), and run a shell in it.
  -l, --login                Initialize the bottle (if necessary), and open a logon prompt in it.
  -c, --command <COMMAND>    Initialize the bottle (if necessary), and run the specified command in it.
  -u, --shutdown             Shut down systemd and exit the bottle.
  -r, --is-running           Check whether systemd is running in genie, or not.
  -b, --is-in-bottle         Check whether currently executing within the genie bottle, or not.

まとめ

だいぶ長いことこの辺を詰まったタイミングで追っていますが、今回はどうもちょっと面倒でした。
というのも、元のリポジトリが移動したことでどこにあるのかを見つけるのに時間がかかりましたね。
見つかってよかった。

そして、元のリポジトリのころは「429 Too Many Requests」のエラーで更新できない状況が続いていましたが、Githubに移行したようで問題なくインストールできました。
何度かアップデートをたたいても問題なさそう。
良き良き。
これで心置きなくLinuxっぽい世界で遊べますね。

今回は、ここまで。
おわり

Linux,環境構築WSL

Posted by shikiyura