systemd-shutdown / initrd のループをデバッグするにはどうすればいいですか? (Arch Linux)

systemd-shutdown / initrd のループをデバッグするにはどうすればいいですか? (Arch Linux)

最近、ZFS 上のルートのカスタム構成で、Arch Linux を仮想ディスクにインストールしました。これは、Arch と FreeBSD の両方で使用される別々のブート プールとルート プールを持つマルチブート構成を管理するために作成したスクリプトを使用していました。現在、ZFS プール構成は VM 下の FreeBSD で作成されています。その後、Arch Linux インストールは別の VM から作成され、Arch は Ext4 パーティションにインストールされました。ブート/ルート ZFS 構成で Arch をインストールし、Grub の設定を行った後、ZFS 上の Arch インストールが正常に起動するようになりました。

現在、ZFS プールがある仮想ディスクは別の仮想マシンで実行されています。現時点では、そのマシンの仮想ディスクにインストールされている OS は Arch Linux のみです。現在は、対応する Grub2 構成で正常に起動します。ただし、シャットダウン中にループが発生しているようです。

[ 1561.324253] systemd-shutdown[1]: Sending SIGKILL to remaining processes...
[ 1561.336930] systemd-shutdown[1]: Unmounting file systems.
[ 1561.341650] [563]: Remounting '/var' read-only in with options 'noxattr,noacl'.
[ 1561.783555] [564]: Unmounting '/var'.
[ 1561.790194] [565]: Remounting '/usr' read-only in with options 'noxattr,noacl'.
[ 1561.796853] [566]: Remounting '/' read-only in with options 'noxattr,noacl'.
[ 1561.803420] systemd-shutdown[1]: All filesystems unmounted.
[ 1561.809423] systemd-shutdown[1]: Deactivating swaps.
[ 1561.813672] systemd-shutdown[1]: All swaps deactivated.
[ 1561.818688] systemd-shutdown[1]: Detaching loop devices.
[ 1561.824354] systemd-shutdown[1]: All loop devices detached.
[ 1561.829085] systemd-shutdown[1]: Stopping MD devices.
[ 1561.833346] systemd-shutdown[1]: All MD devices stopped.
[ 1561.837982] systemd-shutdown[1]: Detaching DM devices.
[ 1561.842299] systemd-shutdown[1]: All DM devices detached.
[ 1561.847501] systemd-shutdown[1]: All filesystems, swaps, loop devices, MD devices and DM devices detached.
[ 1561.856852] systemd-shutdown[1]: Successfully changed into root pivot.
[ 1561.863478] systemd-shutdown[1]: Returning to initrd...
[ 1562.306958] shutdown[1]: Syncing filesystems and block devices.
[ 1562.311377] shutdown[1]: Sending SIGTERM to remaining processes...
[ 1562.316903] shutdown[1]: Sending SIGKILL to remaining processes...
[ 1562.329374] shutdown[1]: Unmounting file systems.
[ 1562.334319] sd-remou[569]: Remounting '/' read-only in with options 'noxattr,noacl'.
[ 1562.346902] sd-umoun[570]: Unmounting '/oldroot/sys/kernel/config'.
[ 1562.354595] sd-umoun[571]: Unmounting '/oldroot/sys/fs/fuse/connections'.
[ 1562.361525] sd-umoun[572]: Unmounting '/oldroot/sys/kernel/tracing'.
[ 1562.368232] sd-umoun[573]: Unmounting '/oldroot/sys/kernel/debug'.
[ 1562.373715] sd-umoun[574]: Unmounting '/oldroot/dev/mqueue'.
[ 1562.380105] sd-umoun[575]: Unmounting '/oldroot/dev/hugepages'.
[ 1562.386843] sd-umoun[576]: Unmounting '/oldroot/sys/fs/bpf'.
[ 1562.391984] sd-umoun[577]: Unmounting '/oldroot/sys/fs/pstore'.
[ 1562.397417] sd-umoun[578]: Unmounting '/oldroot/sys/fs/cgroup'.
[ 1562.404234] audit: type=1334 audit(1635363440.667:81): prog-id=8 op=UNLOAD
[ 1562.410100] sd-umoun[579]: Unmounting '/oldroot/dev/pts'.
[ 1562.414579] audit: type=1334 audit(1635363440.667:82): prog-id=6 op=UNLOAD
[ 1562.420101] sd-umoun[580]: Unmounting '/oldroot/dev/shm'.
[ 1562.426852] sd-umoun[581]: Unmounting '/oldroot/sys/kernel/security'.
[ 1562.432165] sd-umoun[582]: Unmounting '/oldroot/usr'.
[ 1562.443869] sd-remou[583]: Remounting '/oldroot/run' read-only in with options 'noxattr,noacl'.
[ 1562.456905] sd-umoun[584]: Unmounting '/oldroot/run'.
[ 1562.461323] sd-umoun[585]: Unmounting '/oldroot'.
[ 1562.466800] sd-umoun[585]: Failed to unmount /oldroot: Device or resource busy
[ 1562.473458] sd-umoun[586]: Unmounting '/oldroot/dev'.
[ 1562.478395] sd-umoun[587]: Unmounting '/oldroot/sys'.
[ 1562.483288] sd-umoun[588]: Unmounting '/oldroot/proc'.
[ 1562.488082] sd-umoun[589]: Unmounting '/oldroot'.
[ 1562.493279] shutdown[1]: All filesystems unmounted.
[ 1562.498851] shutdown[1]: Deactivating swaps.
[ 1562.502456] shutdown[1]: All swaps deactivated.
[ 1562.506839] shutdown[1]: Detaching loop devices.
[ 1562.511505] shutdown[1]: All loop devices detached.
[ 1562.515404] shutdown[1]: Stopping MD devices.
[ 1562.520083] shutdown[1]: All MD devices stopped.
[ 1562.523666] shutdown[1]: Detaching DM devices.
[ 1562.527617] shutdown[1]: All DM devices detached.
[ 1562.531822] shutdown[1]: All filesystems, swaps, loop devices, MD devices and DM devices detached.
[ 1562.540145] shutdown[1]: Successfully changed into root pivot.
[ 1562.544940] shutdown[1]: Returning to initrd...

私は、ZFS 上の Arch Linux インストールでのみこれに遭遇しました。別の VM インストールで同じ systemd、mkinitcpio、linux、および zfs-linux バージョンを使用し、そこの Ext4 パーティションに Arch をインストールした場合、そのマシンのシャットダウン中にこのようなループは発生しません。これは ZFS 構成のルートによるものでしょうか?

このループをこれ以上デバッグする方法がわからず困っています。

私の推測では、これはおそらく、2013年に導入されたmkinticpioのsystemd-shutdown用のスクリプトに関連していると思われます(ベヒラー2013)。

その頃に導入されたサービスの主なコードと思われるものmkinitcpio-generate-shutdown-ramfs- 抜粋/usr/lib/systemd/system/mkinitcpio-generate-shutdown-ramfs.service

[Service]
Type=oneshot
# /tmp could be umounted at this point
# use /run as temporary directory
Environment=TMPDIR=/run
ExecStart=/usr/bin/mkinitcpio -A sd-shutdown -k none -c /dev/null -d /run/initramfs

さらに、ファイルの内容/usr/lib/initcpio/install/sd-shutdown

#!/bin/bash

build() {
    add_binary /usr/lib/systemd/systemd-shutdown /shutdown

    if type -P kexec >/dev/null; then
        add_binary kexec
    fi
}

help() {
    cat <<HELPEOF
This hook adds systemd-shutdown to the initramfs. This is only
if the image is extracted to /run/initramfs before shutdown.
HELPEOF
}

# vim: set ft=sh ts=4 sw=4 et:

それが実際に VM 上のシャットダウン プロセスに反映されるかどうかはわかりません。システムがその程度の前提条件を満たしていない可能性があります。

systemd でサービスをマスクしmkinitcpio-generate-shutdown-ramfsmkinitcpio -P再度実行して再起動してみましたが、システムのシャットダウン中にまだループに陥ってしまいます。

VM インストールでは、システムは引き続き使用可能です。少なくとも、シャットダウン時にマシンが無限ループを開始するイベントが発生するまでは。理想的には、Arch 以外のものをインストールしたり、マシンの内蔵ハードディスクにこれを配置する前に、この構成の問題を解決できるようにしたいと思います。

このメッセージの原因が何なのかはわかりませんFailed to unmount /oldroot: Device or resource busy。ZFS インストールのルートに関連するものでしょうか? しかし、それは単なる推測にすぎません。

私自身の見解では、コンソール出力から判断すると、systemd-shutdown プロセスは initrd の下で実行されているのでしょうか? 現時点では、デバッグするのは簡単ではないと思います。

VM の仮想ディスクの下の ZFS プール構成で、Arch の横に FreeBSD をインストールした後、Grub 構成を最新の状態に保つために Arch を使い続けることができると確信しています。ただし、Arch でのシャットダウン ループに関するこの問題を解決できる場合は、VM インストール内、または最終的には PC のハード ディスク上で、Arch インストールを稼働中のデスクトップ システムとして維持できるようにしたいと思います。

このループをさらにデバッグする方法を見つけようとして途方に暮れている間、シャットダウン中のループについては、私がまだ見つけていないパッチがあるかもしれません。

アップデート

私は見つけたソースコードArch Linux で使用されているバージョンの systemd-shutdown 用です。かなりわかりやすいコードのように思えます。'oldroot' マウント ポイントや、systemd-shutdown でマウント解除できなくなる理由についてはあまり説明されていないかもしれません。

ログ記録が原因ではないようです。起動後に実行されるワンショット systemd サービスを設定して作成しましたStorage=volatile。ファイルシステムは正常にアンマウントされるようになり、再起動してもログ データがすべて失われることはないと思います。/etc/systemd/journald.conf/usr/bin/journalctl --flush/var/

ただし、シャットダウン中もループは発生しており、Failed to unmount /oldroot...systemd-shutdown からのメッセージも表示されます。副作用によって何かがハングアップしているのでしょうか?

関連情報