WSL2 Ubuntu 作業メモ

とりあえず順不同で、メモしておく方が良さそうな内容を記述しておくことにします。

WSLに増設したSSDを割り当てる

Windowsが起動した時点で増設のストレージが割り当てられれば問題ないのですが、対策方法が不明なため現状は毎回個別設定を行います。

PS C:\Windows\System32> GET-CimInstance -query "SELECT * from Win32_DiskDrive"

DeviceID           Caption                  Partitions Size          Model
--------           -------                  ---------- ----          -----
\\.\PHYSICALDRIVE1 KINGSTON OM8PDP3256B-A01 3          512105932800  KINGSTON OM8PDP3256B-A01
\\.\PHYSICALDRIVE0 CT1000BX500SSD1          4          1000202273280 CT1000BX500SSD1

PS C:\Windows\System32> wsl --mount \\.\PHYSICALDRIVE0 --bare

上記内容の –mount で、WSL2 に増設した SSD を割り当てます。

自動的に割り振られるホスト名を変更

難しいホスト名を単純な “WSL01” に置き換えます。再起動後に適用されるようです。

PS C:\Windows\System32> Rename-Computer -NewName "WSL01"

仮想マシン(Ubuntu) の起動を一般ユーザーに

仮想マシンに入って、/etc/wsl.conf ファイルを作成してその中に次を記述するらしい。

# cat << EOF > /etc/wsl.conf
> [user]
> default=sunao
> EOF

Ubuntu側の漢字処理を組込む

以下の説明を参考にして、中で説明のコマンドを実行して再起動です。

https://astherier.com/blog/2021/07/windows11-wsl2-wslg-japanese/
$ wget https://astherier.com/static/blog/2021-07-11/japanize-wslg.sh
$ bash japanize-wslg.sh

$ rm japanize-wslg.sh

systemctl コマンドが使えない

WSL2 は、PID 1 に init が陣取っているようで、色々なシステムが動作できない状態になるらしいのです。ここでディズニーに出てくる genie の力を借りて systemd を PID 1 に入れ替えてしまうことをするらしいです。

sunao@WSL01:~$ localectl set-locale LANG=ja_JP.UTF-8 LANGUAGE="ja_JP:ja"
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: ホストが落ちています

以下の再確認でも同じメッセージです。

sunao@WSL01:~$ systemctl
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: ホストが落ちています

PID 1 が systemd でないためにエラーが起きているようです。次の情報を参考に作業してランプから genie にお越しいただこうと思います。

https://qiita.com/RyoSakon001/items/26b3d073b70dfe911d59

忘れないようにコマンド入力と出されるメッセージをメモとして残しておきます。

sunao@WSL01:~$ sudo apt install daemonize dbus gawk libc6 libstdc++6 policykit-1 systemd systemd-container
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています... 完了
状態情報を読み取っています... 完了
dbus はすでに最新バージョン (1.12.20-2ubuntu4) です。
dbus は手動でインストールしたと設定されました。
取得:3 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 libnss-mymachines amd64 249.11-0ubuntu3.3 [146 kB]
547 kB を 2秒 で取得しました (279 kB/s)
以前に未選択のパッケージ daemonize を選択しています。
(データベースを読み込んでいます ... 現在 83017 個のファイルとディレクトリがインストールされています。)
.../daemonize_1.7.8-1_amd64.deb を展開する準備をしています ...
daemonize (1.7.8-1) を展開しています...
以前に未選択のパッケージ systemd-container を選択しています。
.../systemd-container_249.11-0ubuntu3.3_amd64.deb を展開する準備をしています ...
systemd-container (249.11-0ubuntu3.3) を展開しています...
以前に未選択のパッケージ libnss-mymachines:amd64 を選択しています。
.../libnss-mymachines_249.11-0ubuntu3.3_amd64.deb を展開する準備をしています ...
libnss-mymachines:amd64 (249.11-0ubuntu3.3) を展開しています...
systemd-container (249.11-0ubuntu3.3) を設定しています ...
Created symlink /etc/systemd/system/multi-user.target.wants/machines.target → /lib/systemd/system/machines.target.
daemonize (1.7.8-1) を設定しています ...
libnss-mymachines:amd64 (249.11-0ubuntu3.3) を設定しています ...
First installation detected...
Checking NSS setup...
libc-bin (2.35-0ubuntu3) のトリガを処理しています ...
man-db (2.10.2-1) のトリガを処理しています ...
dbus (1.12.20-2ubuntu4) のトリガを処理しています ...
Scanning processes...
Scanning processor microcode...
Scanning linux images...

Failed to retrieve available kernel versions.

The processor microcode seems to be up-to-date.

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.
sunao@WSL01:~$ wget https://packages.microsoft.com/config/debian/10/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
--2022-06-30 10:12:52--  https://packages.microsoft.com/config/debian/10/packages-microsoft-prod.deb
packages.microsoft.com (packages.microsoft.com) をDNSに問いあわせています... 23.99.120.248
packages.microsoft.com (packages.microsoft.com)|23.99.120.248|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 3124 (3.1K) [application/octet-stream]
‘packages-microsoft-prod.deb’ に保存中

packages-microsoft-prod.de 100%[========================================>]   3.05K  --.-KB/s    in 0s

2022-06-30 10:12:52 (1.10 GB/s) - ‘packages-microsoft-prod.deb’ へ保存完了 [3124/3124]

sunao@WSL01:~$ sudo dpkg -i packages-microsoft-prod.deb
以前に未選択のパッケージ packages-microsoft-prod を選択しています。
(データベースを読み込んでいます ... 現在 83093 個のファイルとディレクトリがインストールされています。)
packages-microsoft-prod.deb を展開する準備をしています ...
packages-microsoft-prod (1.0-debian10.1) を展開しています...
packages-microsoft-prod (1.0-debian10.1) を設定しています ...
sunao@WSL01:~$ rm packages-microsoft-prod.deb
sunao@WSL01:~$ sudo apt update
取得:1 https://packages.microsoft.com/debian/10/prod buster InRelease [29.8 kB]
ヒット:2 http://archive.ubuntu.com/ubuntu jammy InRelease
取得:3 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
取得:4 https://packages.microsoft.com/debian/10/prod buster/main arm64 Packages [25.9 kB]
取得:5 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [109 kB]
取得:6 https://packages.microsoft.com/debian/10/prod buster/main armhf Packages [26.5 kB]
取得:7 https://packages.microsoft.com/debian/10/prod buster/main amd64 Packages [174 kB]
取得:8 https://packages.microsoft.com/debian/10/prod buster/main all Packages [4,034 B]
取得:9 http://archive.ubuntu.com/ubuntu jammy-backports InRelease [99.8 kB]
取得:10 http://archive.ubuntu.com/ubuntu jammy/main Translation-ja [295 kB]
取得:11 http://security.ubuntu.com/ubuntu jammy-security/main amd64 c-n-f Metadata [3,156 B]
取得:12 http://archive.ubuntu.com/ubuntu jammy/universe Translation-ja [1,534 kB]
取得:13 http://archive.ubuntu.com/ubuntu jammy/multiverse Translation-ja [7,160 B]
取得:14 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 c-n-f Metadata [5,720 B]
2,425 kB を 2秒 で取得しました (973 kB/s)
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています... 完了
状態情報を読み取っています... 完了
パッケージはすべて最新です。

指定された dotnet-runtime-5.0 が古いらしく依存関係でエラーが出ました。

sunao@WSL01:~$ sudo apt install dotnet-runtime-5.0
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています... 完了
状態情報を読み取っています... 完了
インストールすることができないパッケージがありました。おそらく、あり得
ない状況を要求したか、(不安定版ディストリビューションを使用しているの
であれば) 必要なパッケージがまだ作成されていなかったり Incoming から移
動されていないことが考えられます。
以下の情報がこの問題を解決するために役立つかもしれません:

以下のパッケージには満たせない依存関係があります:
 dotnet-runtime-deps-5.0 : 依存: libssl1.0.0 しかし、インストールすることができません または
                                   libssl1.0.2 しかし、インストールすることができません または
                                   libssl1.1 しかし、インストールすることができません
E: 問題を解決することができません。壊れた変更禁止パッケージがあります。
sunao@WSL01:~$ sudo apt install dotnet-runtime
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています... 完了
状態情報を読み取っています... 完了
E: パッケージ dotnet-runtime が見つかりません
sunao@WSL01:~$ aptitude search dotnet-runtime
p   dotnet-runtime-2.1                            - Microsoft .NET Core Runtime - 2.1.30 Microsoft.NETCore.A
p   dotnet-runtime-2.2                            - Microsoft .NET Core Runtime - 2.2.8 Microsoft.NETCore.Ap
p   dotnet-runtime-3.0                            - Microsoft .NET Core Runtime - 3.0.3 Microsoft.NETCore.Ap
p   dotnet-runtime-3.1                            - Microsoft .NET Core Runtime - 3.1.26 Microsoft.NETCore.A
p   dotnet-runtime-5.0                            - Microsoft .NET Runtime - 5.0.17 Microsoft.NETCore.App 5.
p   dotnet-runtime-6.0                            - Microsoft.NETCore.App.Runtime 6.0.6
p   dotnet-runtime-deps-2.1                       - dotnet-runtime-deps-2.1 2.1.30
p   dotnet-runtime-deps-2.2                       - dotnet-runtime-deps-2.2 2.2.8

最新は、6.0 のようですので、最新版を継続してインストールを続けます。ログは aptitude で確認を挟んだ結果、記録された一部の行が消えています。

取得:3 https://packages.microsoft.com/debian/10/prod buster/main amd64 dotnet-runtime-deps-6.0 amd64 6.0.6-1 [2,806 B]
取得:4 https://packages.microsoft.com/debian/10/prod buster/main amd64 dotnet-runtime-6.0 amd64 6.0.6-1 [22.8 MB]
23.0 MB を 12秒 で取得しました (1,865 kB/s)
以前に未選択のパッケージ dotnet-host を選択しています。
(データベースを読み込んでいます ... 現在 83101 個のファイルとディレクトリがインストールされています。)
.../dotnet-host_6.0.6-1_amd64.deb を展開する準備をしています ...
dotnet-host (6.0.6-1) を展開しています...
以前に未選択のパッケージ dotnet-hostfxr-6.0 を選択しています。
.../dotnet-hostfxr-6.0_6.0.6-1_amd64.deb を展開する準備をしています ...
dotnet-hostfxr-6.0 (6.0.6-1) を展開しています...
以前に未選択のパッケージ dotnet-runtime-deps-6.0 を選択しています。
.../dotnet-runtime-deps-6.0_6.0.6-1_amd64.deb を展開する準備をしています ...
dotnet-runtime-deps-6.0 (6.0.6-1) を展開しています...
以前に未選択のパッケージ dotnet-runtime-6.0 を選択しています。
.../dotnet-runtime-6.0_6.0.6-1_amd64.deb を展開する準備をしています ...
dotnet-runtime-6.0 (6.0.6-1) を展開しています...
dotnet-host (6.0.6-1) を設定しています ...
dotnet-runtime-deps-6.0 (6.0.6-1) を設定しています ...
dotnet-hostfxr-6.0 (6.0.6-1) を設定しています ...
dotnet-runtime-6.0 (6.0.6-1) を設定しています ...
man-db (2.10.2-1) のトリガを処理しています ...
Scanning processes...
Scanning processor microcode...
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.
sunao@WSL01:~$ sudo apt install apt-transport-https
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています... 完了
状態情報を読み取っています... 完了
以下のパッケージが新たにインストールされます:
  apt-transport-https
アップグレード: 0 個、新規インストール: 1 個、削除: 0 個、保留: 0 個。
1,512 B のアーカイブを取得する必要があります。
この操作後に追加で 169 kB のディスク容量が消費されます。
取得:1 http://archive.ubuntu.com/ubuntu jammy/universe amd64 apt-transport-https all 2.4.5 [1,512 B]
1,512 B を 1秒 で取得しました (2,864 B/s)
以前に未選択のパッケージ apt-transport-https を選択しています。
(データベースを読み込んでいます ... 現在 83307 個のファイルとディレクトリがインストールされています。)
.../apt-transport-https_2.4.5_all.deb を展開する準備をしています ...
apt-transport-https (2.4.5) を展開しています...
apt-transport-https (2.4.5) を設定しています ...
Scanning processes...
Scanning processor microcode...
Scanning linux images...

Failed to retrieve available kernel versions.

The processor microcode seems to be up-to-date.

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.
sunao@WSL01:~$ sudo wget -O /etc/apt/trusted.gpg.d/wsl-transdebian.gpg https://arkane-systems.github.io/wsl-
transdebian/apt/wsl-transdebian.gpg
--2022-06-30 10:19:17--  https://arkane-systems.github.io/wsl-transdebian/apt/wsl-transdebian.gpg
arkane-systems.github.io (arkane-systems.github.io) をDNSに問いあわせています... 185.199.109.153, 185.199.108.153, 185.199.111.153, ...
arkane-systems.github.io (arkane-systems.github.io)|185.199.109.153|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 2280 (2.2K) [application/octet-stream]
‘/etc/apt/trusted.gpg.d/wsl-transdebian.gpg’ に保存中

/etc/apt/trusted.gpg.d/wsl 100%[========================================>]   2.23K  --.-KB/s    in 0s

2022-06-30 10:19:17 (30.7 MB/s) - ‘/etc/apt/trusted.gpg.d/wsl-transdebian.gpg’ へ保存完了 [2280/2280]

sunao@WSL01:~$ sudo chmod a+r /etc/apt/trusted.gpg.d/wsl-transdebian.gpg

root ユーザーに変更して作業を継続します。

sunao@WSL01:~$ sudo su -
Welcome to Ubuntu 22.04 LTS (GNU/Linux 5.10.102.1-microsoft-standard-WSL2 x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of 2022年  6月 30日 木曜日 10:20:27 JST

  System load:    0.0029296875      Processes:             28
  Usage of /home: 0.0% of 95.56GB   Users logged in:       0
  Memory usage:   3%                IPv4 address for eth0: 172.28.186.10
  Swap usage:     0%


0 updates can be applied immediately.



This message is shown once a day. To disable it please create the
/root/.hushlogin file.
root@WSL01:~# 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
root@WSL01:~#
ログアウト

追加したリポジトリから genie 関連のシステムを取り込みます。

sunao@WSL01:~$ sudo apt update
取得:1 https://arkane-systems.github.io/wsl-transdebian/apt jammy InRelease [3,215 B]
ヒット:2 https://packages.microsoft.com/debian/10/prod buster InRelease
取得:3 https://arkane-systems.github.io/wsl-transdebian/apt jammy/main Sources [1,609 B]
ヒット:4 http://archive.ubuntu.com/ubuntu jammy InRelease
取得:5 https://arkane-systems.github.io/wsl-transdebian/apt jammy/main amd64 Packages [2,115 B]
ヒット:6 http://security.ubuntu.com/ubuntu jammy-security InRelease
ヒット:7 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
取得:8 http://archive.ubuntu.com/ubuntu jammy-backports InRelease [99.8 kB]
107 kB を 1秒 で取得しました (83.5 kB/s)
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています... 完了
状態情報を読み取っています... 完了
パッケージはすべて最新です。
sunao@WSL01:~$ sudo apt install systemd-genie
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています... 完了
状態情報を読み取っています... 完了
以下の追加パッケージがインストールされます:
  build-essential dpkg-dev fakeroot g++ g++-11 gcc gcc-11 libalgorithm-diff-perl libalgorithm-diff-xs-perl
  libalgorithm-merge-perl libasan6 libatomic1 libc-dev-bin libc-devtools libc6-dev libcc1-0 libcrypt-dev
  libexpat1-dev libfakeroot libgcc-11-dev libitm1 libjs-sphinxdoc liblsan0 libnsl-dev libpython3-dev
  libpython3.10-dev libstdc++-11-dev libtirpc-dev libtsan0 libubsan1 linux-libc-dev lto-disabled-list make
  manpages-dev python3-dev python3-pip python3-psutil python3-wheel python3.10-dev rpcsvc-proto zlib1g-dev
提案パッケージ:
  debian-keyring g++-multilib g++-11-multilib gcc-11-doc gcc-multilib autoconf automake libtool flex bison
  gdb gcc-doc gcc-11-multilib gcc-11-locales glibc-doc libstdc++-11-doc make-doc python-psutil-doc
以下のパッケージが新たにインストールされます:
  build-essential dpkg-dev fakeroot g++ g++-11 gcc gcc-11 libalgorithm-diff-perl libalgorithm-diff-xs-perl
  libalgorithm-merge-perl libasan6 libatomic1 libc-dev-bin libc-devtools libc6-dev libcc1-0 libcrypt-dev
  libexpat1-dev libfakeroot libgcc-11-dev libitm1 libjs-sphinxdoc liblsan0 libnsl-dev libpython3-dev
  libpython3.10-dev libstdc++-11-dev libtirpc-dev libtsan0 libubsan1 linux-libc-dev lto-disabled-list make
  manpages-dev python3-dev python3-pip python3-psutil python3-wheel python3.10-dev rpcsvc-proto
  systemd-genie zlib1g-dev
アップグレード: 0 個、新規インストール: 42 個、削除: 0 個、保留: 0 個。
57.5 MB のアーカイブを取得する必要があります。
この操作後に追加で 200 MB のディスク容量が消費されます。
続行しますか? [Y/n]
取得:1 https://arkane-systems.github.io/wsl-transdebian/apt jammy/main amd64 systemd-genie amd64 2.4 [53.8 kB]
取得:2 http://archive.ubuntu.com/ubuntu jammy/main amd64 libc-dev-bin amd64 2.35-0ubuntu3 [20.3 kB]
取得:3 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 linux-libc-dev amd64 5.15.0-40.43 [1,286 kB]
取得:4 http://archive.ubuntu.com/ubuntu jammy/main amd64 libcrypt-dev amd64 1:4.4.27-1 [112 kB]
取得:5 http://archive.ubuntu.com/ubuntu jammy/main amd64 rpcsvc-proto amd64 1.4.2-0ubuntu6 [68.5 kB]
取得:6 http://archive.ubuntu.com/ubuntu jammy/main amd64 libtirpc-dev amd64 1.3.2-2build1 [192 kB]
取得:7 http://archive.ubuntu.com/ubuntu jammy/main amd64 libnsl-dev amd64 1.3.0-2build2 [71.3 kB]
取得:8 http://archive.ubuntu.com/ubuntu jammy/main amd64 libc6-dev amd64 2.35-0ubuntu3 [2,099 kB]
取得:9 http://archive.ubuntu.com/ubuntu jammy/main amd64 libcc1-0 amd64 12-20220319-1ubuntu1 [47.2 kB]
取得:10 http://archive.ubuntu.com/ubuntu jammy/main amd64 libitm1 amd64 12-20220319-1ubuntu1 [30.2 kB]
取得:11 http://archive.ubuntu.com/ubuntu jammy/main amd64 libatomic1 amd64 12-20220319-1ubuntu1 [10.4 kB]
取得:12 http://archive.ubuntu.com/ubuntu jammy/main amd64 libasan6 amd64 11.2.0-19ubuntu1 [2,283 kB]
取得:13 http://archive.ubuntu.com/ubuntu jammy/main amd64 liblsan0 amd64 12-20220319-1ubuntu1 [1,069 kB]
取得:14 http://archive.ubuntu.com/ubuntu jammy/main amd64 libtsan0 amd64 11.2.0-19ubuntu1 [2,261 kB]
取得:15 http://archive.ubuntu.com/ubuntu jammy/main amd64 libubsan1 amd64 12-20220319-1ubuntu1 [976 kB]
取得:16 http://archive.ubuntu.com/ubuntu jammy/main amd64 libgcc-11-dev amd64 11.2.0-19ubuntu1 [2,526 kB]
取得:17 http://archive.ubuntu.com/ubuntu jammy/main amd64 gcc-11 amd64 11.2.0-19ubuntu1 [20.1 MB]
取得:18 http://archive.ubuntu.com/ubuntu jammy/main amd64 gcc amd64 4:11.2.0-1ubuntu1 [5,112 B]
取得:19 http://archive.ubuntu.com/ubuntu jammy/main amd64 libstdc++-11-dev amd64 11.2.0-19ubuntu1 [2,083 kB]
取得:20 http://archive.ubuntu.com/ubuntu jammy/main amd64 g++-11 amd64 11.2.0-19ubuntu1 [11.4 MB]
取得:21 http://archive.ubuntu.com/ubuntu jammy/main amd64 g++ amd64 4:11.2.0-1ubuntu1 [1,412 B]
libitm1:amd64 (12-20220319-1ubuntu1) を設定しています ...
libc-devtools (2.35-0ubuntu3) を設定しています ...
libalgorithm-merge-perl (0.08-3) を設定しています ...
libtsan0:amd64 (11.2.0-19ubuntu1) を設定しています ...
systemd-genie (2.4) を設定しています ...
dpkg-dev (1.21.1ubuntu2.1) を設定しています ...
libgcc-11-dev:amd64 (11.2.0-19ubuntu1) を設定しています ...
gcc-11 (11.2.0-19ubuntu1) を設定しています ...
libc6-dev:amd64 (2.35-0ubuntu3) を設定しています ...
gcc (4:11.2.0-1ubuntu1) を設定しています ...
libexpat1-dev:amd64 (2.4.7-1) を設定しています ...
libstdc++-11-dev:amd64 (11.2.0-19ubuntu1) を設定しています ...
zlib1g-dev:amd64 (1:1.2.11.dfsg-2ubuntu9) を設定しています ...
g++-11 (11.2.0-19ubuntu1) を設定しています ...
libpython3.10-dev:amd64 (3.10.4-3) を設定しています ...
python3.10-dev (3.10.4-3) を設定しています ...
g++ (4:11.2.0-1ubuntu1) を設定しています ...
update-alternatives: /usr/bin/c++ (c++) を提供するために自動モードで /usr/bin/g++ を使います
build-essential (12.9ubuntu3) を設定しています ...
libpython3-dev:amd64 (3.10.4-0ubuntu2) を設定しています ...
python3-dev (3.10.4-0ubuntu2) を設定しています ...
man-db (2.10.2-1) のトリガを処理しています ...
libc-bin (2.35-0ubuntu3) のトリガを処理しています ...
Scanning processes...
Scanning processor microcode...
Scanning linux images...

Failed to retrieve available kernel versions.

The processor microcode seems to be up-to-date.

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.
sunao@WSL01:~$ genie -l
genie: WARNING: systemd default target is default.target; targets other than multi-user.target may not work
genie: WARNING: if you wish to use a different target, this warning can be disabled in the config file
genie: WARNING: if you experience problems, please change the target to multi-user.target
Waiting for systemd....!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!  ^C で強制停止を行いました。

Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/usr/lib/genie/genie/__main__.py", line 581, in <module>
  File "/usr/lib/genie/genie/__main__.py", line 564, in entrypoint
  File "/usr/lib/genie/genie/__main__.py", line 351, in do_initialize
  File "/usr/lib/genie/genie/__main__.py", line 294, in inner_do_initialize
KeyboardInterrupt
Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/usr/lib/genie/genie/__main__.py", line 581, in <module>
  File "/usr/lib/genie/genie/__main__.py", line 568, in entrypoint
  File "/usr/lib/genie/genie/__main__.py", line 384, in do_login
  File "/usr/lib/genie/genie/__main__.py", line 112, in pre_systemd_action_checks
  File "/usr/lib/python3.10/subprocess.py", line 503, in run
    stdout, stderr = process.communicate(input, timeout=timeout)
  File "/usr/lib/python3.10/subprocess.py", line 1141, in communicate
    self.wait()
  File "/usr/lib/python3.10/subprocess.py", line 1204, in wait
    return self._wait(timeout=timeout)
  File "/usr/lib/python3.10/subprocess.py", line 1938, in _wait
    (pid, sts) = self._try_wait(0)
  File "/usr/lib/python3.10/subprocess.py", line 1896, in _try_wait
    (pid, sts) = os.waitpid(self.pid, wait_flags)
KeyboardInterrupt

PID 1 が systemd に置き換えられているのか気になるところです。 top コマンドで確認してみました。

sunao@WSL01:~$ genie -s
genie: WARNING: systemd is in degraded state, issues may occur!
sunao@WSL01-wsl:~$ top
top - 10:26:42 up  1:57,  1 user,  load average: 0.03, 0.12, 0.06
Tasks:  32 total,   1 running,  31 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem :  15705.3 total,  13924.7 free,    593.7 used,   1186.9 buff/cache
MiB Swap:   4096.0 total,   4096.0 free,      0.0 used.  14828.2 avail Mem

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
   1117 sunao     20   0   11388   3800   3208 R   0.3   0.0   0:00.01 top
      1 root      20   0  171676  13176   8592 S   0.0   0.1   0:00.71 systemd
     48 root      19  -1   39600  15708  14616 S   0.0   0.1   0:00.09 systemd-journal
     72 root      20   0   22944   6560   4456 S   0.0   0.0   0:00.09 systemd-udevd
     95 systemd+  20   0   16112   7984   6976 S   0.0   0.0   0:00.05 systemd-network
     96 message+  20   0    8852   5028   4148 S   0.0   0.0   0:00.10 dbus-daemon
     99 root      20   0   39580  21104  11820 S   0.0   0.1   0:00.08 networkd-dispat
    100 root      20   0  236444   9216   7036 S   0.0   0.1   0:00.03 polkitd
    101 syslog    20   0  222396   5312   4488 S   0.0   0.0   0:00.04 rsyslogd
    102 root      20   0 2279332  49004  17588 S   0.0   0.3   0:00.65 snapd
    106 root      20   0   15304   7308   6344 S   0.0   0.0   0:00.10 systemd-logind
    110 root      20   0  392764  13156  10816 S   0.0   0.1   0:00.05 udisksd
    151 root      20   0  316920  11872  10100 S   0.0   0.1   0:00.05 ModemManager
    246 systemd+  20   0   25256  12412   8384 S   0.0   0.1   0:00.06 systemd-resolve
    329 root      20   0    7936   1256   1116 S   0.0   0.0   0:00.00 cron
    341 root      20   0  116584  23532  14824 S   0.0   0.1   0:00.03 unattended-upgr
    353 root      20   0    7216   1096   1008 S   0.0   0.0   0:00.00 agetty
    355 root      20   0    7216   1072    984 S   0.0   0.0   0:00.00 agetty
   1039 root      20   0    2884    952    856 S   0.0   0.0   0:00.00 sh

systemd が PID 1 に収まっているようです。

genieの効果はいつまで続くのか?

永久的に genie の効果が持続しているようではないらしく、systemd が PID 1 に収まっているのは特定の期間だけのようで、どの時点にかはわかりませんが元の init に戻っています。


genie の環境が刻々と変化しているようで

今年 2022 年 GW前後の新しい動き、『WSL2+Ubuntu22.04に標準で入ったsystemdを試す』との情報に systemdを起動して PID 1 に収まっている記事がありましたが、現時点で確認すると PID 1 は元々の init が占めていて、別な場所に systemd が乗っています。

この systemd は wsl2 専用らしい

sunao@WSL01-wsl:~$ ls -l /usr/libexec/wsl-systemd
-rwxr-xr-x 1 root root 550  3月 18 00:08 /usr/libexec/wsl-systemd

sunao@WSL01-wsl:~$ /usr/libexec/nslogin
sunao@WSL01-wsl:~$

ランプの精の genie 君も成りを潜めていて PID 1 を奪い取ることをしていないようです。その説明の中で書かれている nslogin を起動してもメッセージはなくプロンプトが帰ります。

apache2を起動して結果を見ました

何かよくわかりませんが、apache2 を起動すると、特にエラーもなく起動されたようです。

sunao@WSL01-wsl:~$ sudo systemctl start apache2
sunao@WSL01-wsl:~$ sudo systemctl status apache2
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2022-07-06 10:14:08 JST; 13s ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 816 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
   Main PID: 820 (apache2)
      Tasks: 4 (limit: 18840)
     Memory: 5.3M
     CGroup: /system.slice/apache2.service
             ├─820 /usr/sbin/apache2 -k start
             ├─821 /usr/sbin/apache2 -k start
             ├─822 /usr/sbin/apache2 -k start
             └─823 /usr/sbin/apache2 -k start

 7月 06 10:14:08 WSL01-wsl systemd[1]: Starting The Apache HTTP Server...
 7月 06 10:14:08 WSL01-wsl systemd[1]: Started The Apache HTTP Server.

コマンド top の結果を次に載せておきます。当初からの init が PID 1 を占めているようで、systemd は別の場所に乗っているです。

top - 11:22:05 up  2:02,  3 users,  load average: 0.00, 0.00, 0.00
Tasks:  70 total,   1 running,  69 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem :  15705.3 total,  14445.1 free,    511.9 used,    748.2 buff/cache
MiB Swap:   4096.0 total,   4096.0 free,      0.0 used.  14932.6 avail Mem

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
      1 root      20   0    1776   1056   1020 S   0.0   0.0   0:00.02 init
     13 root      20   0    2116    356      0 S   0.0   0.0   0:00.00 init
     14 root      20   0    2124    356      0 S   0.0   0.0   0:00.19 init
     15 sunao     20   0    9748   5376   3628 S   0.0   0.0   0:00.02 bash
     34 sunao     20   0    8164   2148   1716 S   0.0   0.0   0:00.00 dbus-launch
     35 sunao     20   0    8292   2432   2052 S   0.0   0.0   0:00.00 dbus-daemon
     38 sunao     20   0  323148  38188  29196 S   0.0   0.2   0:00.13 fcitx
     45 sunao     20   0    8292   2928   2568 S   0.0   0.0   0:00.00 dbus-daemon
     49 sunao     39  19    6572    236      0 S   0.0   0.0   0:00.00 fcitx-dbus-watc
     50 sunao     20   0  187448  20192  13688 S   0.0   0.1   0:00.07 mozc_server
     82 root      20   0    2116    356      0 S   0.0   0.0   0:00.01 init
    107 root      20   0    6812    960    872 S   0.0   0.0   0:00.00 unshare
    108 root      20   0   18900  11340   7932 S   0.0   0.1   0:00.69 systemd
    155 root      19  -1   47796  15572  14464 S   0.0   0.1   0:00.16 systemd-journal
    189 root      20   0   23068   6672   4480 S   0.0   0.0   0:00.35 systemd-udevd
    191 root      20   0    4732   1684   1228 S   0.0   0.0   0:00.21 snapfuse
    192 root      20   0    4796   1804   1220 S   0.0   0.0   0:02.17 snapfuse
    217 systemd+  20   0   16112   8040   7028 S   0.0   0.0   0:00.16 systemd-network
    218 message+  20   0    9044   4892   4012 S   0.0   0.0   0:00.18 dbus-daemon
    221 root      20   0   39580  21088  11800 S   0.0   0.1   0:00.08 networkd-dispat
    222 root      20   0  236444  11000   6780 S   0.0   0.1   0:00.04 polkitd

使い方や動きがしっくりきていませんが、しばらく様子を見ながら付き合っていこうと考えています。

apache2 が起動しない

現状の環境からの模索

プライベート写真をネット環境に公開しているWebサーバー用に、アップロードするデーター等を作成したり、動作の検証をするために別の機器を立上げ、そこにデーターを変換するアプリや検証のために apache http サーバーを設定して利用しています。

古くて遅いノートPC

別の機器としての作業は、現状は非力で処理の遅い古いノートPCでの作業です。基本的に写真をカメラで写し、居た場所をGPSロガーで収集して、ノートPCに移して加工しています。

動作の検証もノートPC内に立上げた Web サーバー apache で行っているため、全てがワンパッケージで完結しているので、まとまっていて操作性は良いのですが、非力でストレスになってます。

更に非効率なos切替

GPSロガーはアプリがWindows対応なのでそれに従い、写真に位置情報を追加したり公開用にサイズを縮小したりの加工は Linux のバッチ処理で加工しています。OSの切替は昔からあるオーソドックスなデュアルブートを利用しています。切替に時間が掛かりとても効率が悪いです。

データー加工とWebサーバー

新しいノートPCを購入するとか、速くて効率的な作業環境に移行できればストレスも減るのですが、何よりもまず資金が必要な事だし、今ある機器で分散できないものかと模索しています。

機器の分散を模索

データー変換や検証のWebサーバーを別に立て、リモート環境を作ろうかと模索していて、分散対象のサーバーに利用する予定の機器は、サーバーなのに20分で停止してしまったり、致命的な問題はapache が立上げできません。

サーバーとしての機能

サーバーが 20分で停止する問題は、別にまとめた Linux Ubuntu のバージョンアップの仕様が問題でしたが、その後の状況から解決できました。
(systemd の対策で停止を解決)

Webサーバーを設定

検証用Webサーバーとして実績のあるノートPCから apache のサイト情報等のコピーを行ったのに立上げでエラーになります。

$ sudo systemctl start apache2
Job for apache2.service failed because the control process exited with error code.
See "systemctl status apache2.service" and "journalctl -xe" for details.

ログ等を確認すると、https を設定するために使用している認証情報に問題があるらしく、今までに実績のあるファイルをコピーして手を抜こうと考えたのですが、定義されたキーが短過ぎるのが原因らしいです。

$ sudo systemctl status apache2
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Sun 2021-03-14 13:35:13 JST; 11min ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 561706 ExecStart=/usr/sbin/apachectl start (code=exited, status=1/FAILURE)

 3月 14 13:35:13 big-book systemd[1]: Starting The Apache HTTP Server...
 3月 14 13:35:13 big-book apachectl[561721]: AH00558: apache2: Could not reliably determine the server's fully>
 3月 14 13:35:13 big-book apachectl[561706]: Action 'start' failed.
 3月 14 13:35:13 big-book apachectl[561706]: The Apache error log may have more information.
 3月 14 13:35:13 big-book systemd[1]: apache2.service: Control process exited, code=exited, status=1/FAILURE
 3月 14 13:35:13 big-book systemd[1]: apache2.service: Failed with result 'exit-code'.
 3月 14 13:35:13 big-book systemd[1]: Failed to start The Apache HTTP Server.
lines 1-13/13 (END)

error.log を開いてみると、:ee key too small と出ているので証明書の key が小さいのが原因と思われます。

$ less /var/log/apache2/error.log
[Sun Mar 14 13:35:13.253066 2021] [ssl:emerg] [pid 561721:tid 140387924089920] AH02562: Failed to configure certificate sunao-mita.pgw.jp:443:0 (with chain), check /etc/apache2/ssl/server.cert
[Sun Mar 14 13:35:13.253158 2021] [ssl:emerg] [pid 561721:tid 140387924089920] SSL Library Error: error:140AB18F:SSL routines:SSL_CTX_use_certificate:ee key too small
AH00016: Configuration Failed
/var/log/apache2/error.log (END)

オレオレ証明書の作成

昔々、ネットの情報を参考にさせて頂きオレオレ証明書を作成したことがありました。それを流用して暫く使えていたのですが今回はエラーになってしまいました。証明書の条件も年月と共に厳しくなっているので少しずつ対応していかないといけません。

ネットを色々と調べ内容の重げなサイトを見付けました。ほぼ丸コピーで試してみようと思います。
https://one-it-thing.com/63/

まずは、オレオレ認証局かな

あまり意識したことがなかったけど OpenSSL のバージョンの確認あたりから進めていこうと思っています。

$ openssl version
OpenSSL 1.1.1f  31 Mar 2020

root ユーザーになって、作業用に /openssl のディレクトリを作成して、そこに移動してサンプルをコピーして、作業を進めることにします。

$ sudo su -
# mkdir /openssl
# cd /openssl
# cp /etc/ssl/openssl.cnf ./

作業用ディレクトリをカレントに定義、シリアルナンバーファイルを作成しておきます。

# vi openssl.cnf
〜途中省略〜
dir = ./ # Where everything is kept
〜途中省略〜


# touch ./index.txt
# echo 00 > ./serial

CA秘密鍵を作成します。途中でパスワードを2回打鍵して継続します。

# openssl genrsa -aes256 -out ./cakey.pem 2048
Generating RSA private key, 2048 bit long modulus (2 primes)
......................................................+++++
.................................................................+++++
e is 65537 (0x010001)
Enter pass phrase for ./cakey.pem: (パスワードを入力して備忘しておく)
Verifying - Enter pass phrase for ./cakey.pem:

CA証明書リクエストを作成

CA とは証明書認証局なのでしょうか、あまり理解できていませんが、ネット情報を参考に進めます。

# openssl req -new -key ./cakey.pem -config ./openssl.cnf -out cacert.csr
Enter pass phrase for ./cakey.pem:
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:JP
State or Province Name (full name) [Some-State]:Gunma
Locality Name (eg, city) []:Fujioka
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Mita
Organizational Unit Name (eg, section) []:Mita-sec
Common Name (e.g. server FQDN or YOUR name) []:192.168.11.5
Email Address []:sunao.mita@nifty.com

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

理解をしていませんが、X509 v3 拡張領域に入れるために、v3_ca.txt を作成するのだそうです。

# vi v3_ca.txt
basicConstraints = critical, CA:true
keyUsage = critical, cRLSign, keyCertSign
subjectKeyIdentifier=hash

CA証明書作成

ここでやっとCA証明書の作成になるようです。

# openssl ca -in cacert.csr -selfsign -keyfile ./cakey.pem -notext -config ./openssl.cnf 
-outdir . -days 3650 -extfile v3_ca.txt -out cacert.pem
Using configuration from ./openssl.cnf
Enter pass phrase for ./cakey.pem:
Check that the request matches the signature
Signature ok
Certificate Details:
        Serial Number: 0 (0x0)
        Validity
            Not Before: Mar 14 06:43:10 2021 GMT
            Not After : Mar 12 06:43:10 2031 GMT
        Subject:
            countryName               = JP
            stateOrProvinceName       = Gunma
            organizationName          = Mita
            organizationalUnitName    = Mita-sec
            commonName                = 192.168.11.5
            emailAddress              = sunao.mita@nifty.com
        X509v3 extensions:
            X509v3 Basic Constraints: critical
                CA:TRUE 
            X509v3 Key Usage: critical
                Certificate Sign, CRL Sign
            X509v3 Subject Key Identifier:
                CD:2A:04:41:9A:3D:D3:23:1E:BE:C6:FE:FD:E4:3C:8D:1D:9C:1A:79
Certificate is to be certified until Mar 12 06:43:10 2031 GMT (3650 days)
Sign the certificate? [y/n]:y


1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated

できあがった証明書をテキストで確認してみて、X509v3 の記述があることを確認するのだそうです。

# openssl x509 -in cacert.pem -text
〜省略〜
       X509v3 extensions:
            X509v3 Basic Constraints: critical
                CA:TRUE
            X509v3 Key Usage: critical
                Certificate Sign, CRL Sign
            X509v3 Subject Key Identifier: 
                CD:2A:04:41:9A:3D:D3:23:1E:BE:C6:FE:FD:E4:3C:8D:1D:9C:1A:79
〜省略〜

オレオレ サーバー証明書

サーバー秘密鍵の作成

# openssl genrsa -aes256 -out ./server.key 2048
Generating RSA private key, 2048 bit long modulus (2 primes)
........................................................................................................................................................................................................................+++++
..........................+++++
e is 65537 (0x010001)
Enter pass phrase for ./server.key: (パスワードを入力して備忘しておく)
Verifying - Enter pass phrase for ./server.key:

サーバー証明書リクエスト作成

サーバー証明書リクエストの作成を行います。個人使用なので CA証明書と内容は同じで良いようです。

# openssl req -new -key ./server.key -config ./openssl.cnf -out server.csr
Enter pass phrase for ./server.key: (秘密鍵に設定したパスワード)
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:JP
State or Province Name (full name) [Some-State]:Gunma
Locality Name (eg, city) []:Fujioka
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Mita
Organizational Unit Name (eg, section) []:Mita-sec
Common Name (e.g. server FQDN or YOUR name) []:sunao-mita.pgw.jp
Email Address []:sunao.mita@nifty.com

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

証明書のX509 v3拡張情報

# vi v3_server.txt
[SAN]
basicConstraints = CA:false
keyUsage = critical, digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth
authorityKeyIdentifier=keyid,issuer

subjectAltName=@alt_names
basicConstraints=CA:FALSE
[alt_names]
DNS.1=192.168.11.2
IP.1=192.168.11.5
IP.2=127.0.0.1

サーバー証明書の作成

# openssl ca -in server.csr -config openssl.cnf -keyfile ./cakey.pem -outdir . -extfile v3_server.txt -extensions SAN -out server.crt -days 3650
Using configuration from openssl.cnf
Enter pass phrase for ./cakey.pem:
Check that the request matches the signature
Signature ok
Certificate Details:
        Serial Number: 1 (0x1)
        Validity
            Not Before: Mar 14 07:43:48 2021 GMT
            Not After : Mar 12 07:43:48 2031 GMT
        Subject:
            countryName               = JP
            stateOrProvinceName       = Gunma
            organizationName          = Mita
            organizationalUnitName    = Mita-sec
            commonName                = sunao-mita.pgw.jp
            emailAddress              = sunao.mita@nifty.com
        X509v3 extensions:
            X509v3 Key Usage: critical
                Digital Signature, Key Encipherment
            X509v3 Extended Key Usage: 
                TLS Web Server Authentication
            X509v3 Authority Key Identifier: 
                keyid:CD:2A:04:41:9A:3D:D3:23:1E:BE:C6:FE:FD:E4:3C:8D:1D:9C:1A:79

            X509v3 Subject Alternative Name: 
                DNS:192.168.11.2, IP Address:192.168.11.5, IP Address:127.0.0.1
            X509v3 Basic Constraints: 
                CA:FALSE
Certificate is to be certified until Mar 12 07:43:48 2031 GMT (3650 days)
Sign the certificate? [y/n]:y


1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated

確認のためにできたサーバー証明書をテキストダンプして確認します。

# openssl x509 -in server.crt -text
〜省略〜
        X509v3 extensions:
            X509v3 Key Usage: critical
                Digital Signature, Key Encipherment
            X509v3 Extended Key Usage: 
                TLS Web Server Authentication
            X509v3 Authority Key Identifier: 
                keyid:CD:2A:04:41:9A:3D:D3:23:1E:BE:C6:FE:FD:E4:3C:8D:1D:9C:1A:79

            X509v3 Subject Alternative Name: 
                DNS:192.168.11.2, IP Address:192.168.11.5, IP Address:127.0.0.1
            X509v3 Basic Constraints: 
                CA:FALSE
〜省略〜

パスなしサーバー秘密鍵の生成

# openssl rsa -in ./server.key -out nopass_server.key
Enter pass phrase for ./server.key:
writing RSA key

作業ディレクトリ内にできた成果

作業ディレクトリ内には不要な作業ファイルも含め、色々なファイルが残っていますが、必要なものは次の4点のようです。

  1. CA秘密鍵:cakey.pem …サーバ証明書を作るためで、不使用
  2. CA証明書:cacert.pem …サーバーを利用する端末のブラウザで使用
  3. サーバ秘密鍵:nopass_server.key …サーバーの apache に指定
  4. サーバ証明書:server.crt …サーバーの apache に指定

サーバー sslの設定に

定義されている場所が複数あり、その1箇所を次に示します。同様に sites-available 内のssl に関連するファイルを確認する必要があります。

# vi /etc/apache2/sites-available/default-ssl.conf
〜省略〜
                SSLCertificateFile    /openssl/server.crt
                SSLCertificateKeyFile /openssl/nopass_server.key
〜省略〜

コンフィグファイルの確認

$ apache2ctl configtest
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
Syntax OK

apache2 の起動と確認

Syntax OK となっていても、実際に start でエラーが出て起動しない場合が多いので原因をじっくり潰します。

$ sudo systemctl start apache2
$ sudo systemctl status apache2
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2021-03-14 21:52:25 JST; 28s ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 877445 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
   Main PID: 877471 (apache2)
      Tasks: 57 (limit: 4413)
     Memory: 8.2M
     CGroup: /system.slice/apache2.service
             ├─877471 /usr/sbin/apache2 -k start
             ├─877472 /usr/sbin/apache2 -k start
             ├─877473 /usr/sbin/apache2 -k start
             ├─877474 /usr/sbin/apache2 -k start
             └─877475 /usr/sbin/apache2 -k start

 3月 14 21:52:25 big-book systemd[1]: Starting The Apache HTTP Server...
 3月 14 21:52:25 big-book apachectl[877454]: AH00558: apache2: Could not reliably determine the server's fully>
 3月 14 21:52:25 big-book systemd[1]: Started The Apache HTTP Server.
lines 2-18/18 (END)

何とか最後に起動できました。

Ubuntuのサーバーが止まる

新LTSが公開され半年経過でバージョンアップ

Linux の Ubuntuを大柄なノートPCにセットアップして、サーバーとして利用していましたが、18.04 LTS から20.04 LTS にバージョンアップしたら動作中に止まるらしく、リモート接続していても NFS でリモートディスクとして利用していても固まってしまいます。

画面の蓋開閉が原因かと設定直すも効果なし

ディスクトップを開いて作業していれば問題はなく、画面を閉じると停止してしまいます。そのため、画面を閉じてもサスペンドやファイバネーションが起動されない設定を行いました。それでも20分で停止します。

ネットの記事を頼りに色々と試すしかない

ネット検索すると同様の条件で苦労しているらしい人達の情報に行き当たります。アメリカとどこかの国で、何かの会議で可決されたエコの対象として自動的に停止するようにしなければならなくなったとか、の改悪らしいことが書かれていました。

1時間や半日とか処理に掛かるのは一般的なものですが、勝手に止まってそれを復旧するために時間が取られ、止まらないように付きっ切りで監視しているのがエコとは思えない、ギャグのような本末転倒な行為ですけど、その様な改悪がバージョンアップで起きてしまっていることに驚きです。

システムを自動停止させる設定を外部から操作できない

バージョンアップ前の 18.04 LTS では、システムの処理が停止しないように設定するための画面操作があって、そこで問題無く思うように設定できたのですが、20.04 LTS にバージョンアップしたらその様な設定項目が見付けられませんでした。ネット情報によると変更できないように設定アプリを取り除いたらしい事が書かれていました。

使い物にならないバグだと思ったら…

サーバーが勝手に停止してしまうバグだと思ったら、それが仕様だったとは驚き、その仕様を作成した人達の脳味噌のシステムパグだったと言うことですよね、更に驚きでした。

有効な対策の紹介記事に辿り着く

対策を日本語で紹介してくれる場所に辿り着きました。リンクの埋め込みには失敗しましたが、次にURLを示します。結果は良好で停止すること無く稼働していることが確認できました。

https://www-it–swarm-jp-net.cdn.ampproject.org/v/s/www.it-swarm.jp.net/ja/suspend/ubuntu-2004は、関連する電源設定が無効になっていても、アイドル状態になると一時停止します/997985878/amp/?amp_gsa=1&amp_js_v=a6&usqp=mq331AQHKAFQArABIA%3D%3D

実施した対策内容

その書かれていた systemd の対策を実施しました。結果として問題ないようです。

$ sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
Created symlink /etc/systemd/system/sleep.target → /dev/null.
Created symlink /etc/systemd/system/suspend.target → /dev/null.
Created symlink /etc/systemd/system/hibernate.target → /dev/null.
Created symlink /etc/systemd/system/hybrid-sleep.target → /dev/null.

インストール済みのリスト

Debian / Raspbian でインストールされているパッケージをリストするコマンドの備忘録

APT コマンド

sudo apt list –installed

$ sudo apt list --installed | grep ssh

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

libssh-gcrypt-4/oldstable,now 0.7.3-2+deb9u2 armhf [インストール済み、自動]
libssh2-1/oldstable,now 1.7.0-1+deb9u1 armhf [インストール済み、自動]
openssh-client/oldstable,now 1:7.4p1-10+deb9u7 armhf [インストール済み、自動]
openssh-server/oldstable,now 1:7.4p1-10+deb9u7 armhf [インストール済み、自動]
openssh-sftp-server/oldstable,now 1:7.4p1-10+deb9u7 armhf [インストール済み、自動]
ssh/oldstable,now 1:7.4p1-10+deb9u7 all [インストール済み]

DPKG コマンド

dpkg –get-selections

$ dpkg --get-selections | grep ssh
libssh-gcrypt-4:armhf                           install
libssh2-1:armhf                                 install
openssh-client                                  install
openssh-server                                  install
openssh-sftp-server                             install
ssh                                             install

dpkg-query コマンド

dpkg-query -l

$ sudo dpkg-query -l | grep ssh
ii  libssh-gcrypt-4:armhf                 0.7.3-2+deb9u2                    armhf        tiny C SSH library (gcrypt flavor)
ii  libssh2-1:armhf                       1.7.0-1+deb9u1                    armhf        SSH2 client-side library
ii  openssh-client                        1:7.4p1-10+deb9u7                 armhf        secure shell (SSH) client, for secure access to remote machines
ii  openssh-server                        1:7.4p1-10+deb9u7                 armhf        secure shell (SSH) server, for secure access from remote machines
ii  openssh-sftp-server                   1:7.4p1-10+deb9u7                 armhf        secure shell (SSH) sftp server module, for SFTP access from remote machines
ii  ssh                                   1:7.4p1-10+deb9u7                 all          secure shell client and server (metapackage)