WSL2でSystemctlを動かす
WSL2 Ubuntu 22.04 で systemd が動作するようになったようなのでテスト
こちらを参考にさせていただいた
Ubuntuを20.04 -> 22.04 にアップグレードする
まだストアアプリのUbuntuは22.04になっていないようなので、20.04からのアップグレードが必要。
# パッケージを最新版にしておく
sudo apt -y update && sudo apt -y upgrade
# ディストリビューションのアップグレード
sudo do-release-upgrade -d
# 何度か質問があるので、必要な項目を選択...
# アップグレード完了後、バージョンが上がっていることを確認する
cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy
systemd を起動する
systemdを起動するスクリプトファイルが以下のディレクトリにあるようなので、それを自動起動するように設定する。
/usr/libexec/wsl-systemd
wsl.confを作成して自動起動するようにする。
wsl.confは配置したディストリビューションに適用される設定で、Windows側のユーザーホームに配置する.wslconfigはディストリビューション全体に適用されるっぽい。
# wsl.conf が存在しない場合は作成する
sudo vi /etc/wsl.conf
# wsl.conf内にブート時に実行するコマンドを追加する。
[boot]
command = /usr/libexec/wsl-systemd
# 保存して閉じる
ESC
:wq
起動しているか確認する
$ systemctl status
● win-desktop
State: starting
[boot]
Jobs: 4 queued
Failed: 2 units
Since: Tue 2022-05-03 13:23:01 JST; 3s ago
CGroup: /
├─init.scope
│ └─6039 /lib/systemd/systemd --unit=multi-user.target
└─system.slice
├─dmesg.service
│ └─6137 (savelog)
├─systemd-networkd.service
│ └─6132 /lib/systemd/systemd-networkd
├─systemd-udevd.service
│ └─6107 /lib/systemd/systemd-udevd
├─cron.service
│ └─6326 /usr/sbin/cron -f -P
├─polkit.service
│ └─6139 /usr/libexec/polkitd --no-debug
├─systemd-timedated.service
│ └─6911 /lib/systemd/systemd-timedated
├─networkd-dispatcher.service
│ └─6138 /usr/bin/python3 /usr/bin/networkd-dispatcher --run-startup-triggers
├─ModemManager.service
│ └─6154 /usr/sbin/ModemManager
├─systemd-journald.service
│ └─6082 /lib/systemd/systemd-journald
├─unattended-upgrades.service
│ └─6331 /usr/bin/python3 /usr/share/unattended-upgrades/unattended-upgrade-shutdown --wait-for-signal
systemctl コマンドを試してみる
(SSHサービスが起動している)
$ systemctl status sshd
● ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2022-05-03 13:25:25 JST; 19min ago
Docs: man:sshd(8)
man:sshd_config(5)
Process: 304 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
Main PID: 329 (cron)
Tasks: 1 (limit: 19163)
Memory: 6.3M
CGroup: /system.slice/ssh.service
└─329 "sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups"
May 03 13:25:25 win-desktop systemd[1]: Starting OpenBSD Secure Shell server...
May 03 13:25:25 win-desktop sshd[329]: Server listening on 0.0.0.0 port 22.
May 03 13:25:25 win-desktop sshd[329]: Server listening on :: port 22.
May 03 13:25:25 win-desktop systemd[1]: Started OpenBSD Secure Shell server.
あとがき
snapでいろんなツールをインストールしたいが、snapdが動作しないのでうまくいかない。。。調査継続。
$ sudo apt install snap
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
snap
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 377 kB of archives.
After this operation, 2756 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu jammy/universe amd64 snap amd64 2013-11-29-11 [377 kB]
Fetched 377 kB in 2s (168 kB/s)
Selecting previously unselected package snap.
(Reading database ... 34688 files and directories currently installed.)
Preparing to unpack .../snap_2013-11-29-11_amd64.deb ...
Unpacking snap (2013-11-29-11) ...
Setting up snap (2013-11-29-11) ...
Processing triggers for man-db (2.10.2-1) ...
Scanning processes...
Scanning candidates...
No services need to be restarted.
No containers need to be restarted.
No user sessions are running outdated binaries.
No VM guests are running outdated hypervisor (qemu) binaries on this host.
$ snap --version
snap 2.55.3+22.04ubuntu1
snapd unavailable
series -
この記事が気に入ったらサポートをしてみませんか?