如何调试 systemd-shutdown / initrd 中的循环? (架构Linux)

如何调试 systemd-shutdown / initrd 中的循环? (架构Linux)

我最近在 ZFS 上的根自定义配置下将 Arch Linux 安装到了虚拟磁盘。这是因为我使用了一些脚本来管理多重引导配置,其中有单独的引导池和根池,每个脚本都可用于 Arch 和 FreeBSD。目前,ZFS 池配置是在 VM 下使用 FreeBSD 创建的。然后从另一个虚拟机创建 Arch Linux 安装,其中 Arch 安装在 Ext4 分区上。将 Arch 安装在引导/根 ZFS 配置上,并在对 Grub 进行一些配置后,ZFS 上的 Arch 安装现在可以成功引导。

目前,带有 ZFS 池的虚拟磁盘正在单独的虚拟机下运行。目前,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 版本,并且 Arch 位于那里的 Ext4 分区上,在该计算机关闭期间不会发生此类循环。可能是由于 ZFS 配置上的 root 造成的?

我不知道如何进一步调试这个循环。

据我猜测,这可能与 mkinticpio 上的一些 systemd-shutdown 脚本有关,例如 2013 年引入的脚本(巴赫勒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:

我不确定这是否真的进入了虚拟机上的关闭过程 - 系统可能无法满足那么多规定的先决条件。

我尝试mkinitcpio-generate-shutdown-ramfs在 systemd 下屏蔽该服务,然后mkinitcpio -P再次运行,重新启动......并且在系统关闭期间它仍然进入该循环。

该系统在虚拟机安装下仍然可用 - 至少在关闭事件发生之前,当机器开始无限循环时。理想情况下,我希望能够在安装 Arch 之外的任何东西或将其放入机器的内部硬盘之前,从配置中解决这个问题。

我不确定这条消息可能会产生什么结果Failed to unmount /oldroot: Device or resource busy。这可能与 ZFS 安装的 root 有关吗?但这只是一个猜测,真的。

从我自己的角度来看,systemd 关闭进程 - 从控制台输出中可以看出,它是否在 initrd 下运行?我相信此时调试似乎并不简单。

我确信在 VM 虚拟磁盘下的 ZFS 池配置中将 FreeBSD 安装在 Arch 旁边之后,我可以继续使用 Arch 来保持 Grub 配置最新。然而,如果可以通过 Arch 下的关闭循环来解决这个问题,我希望能够将 Arch 安装作为一个工作桌面系统来维护 - 在 VM 安装中,或者最终在 PC 的硬盘上。

虽然我不知道如何进一步调试这个循环,但对于关闭期间的循环,也许有一个我还没有找到的补丁?

更新

我发现了源代码对于 systemd-shutdown,在 Arch Linux 上使用的版本。我认为它看起来像是一些相当简单的代码。可能没有太多关于“oldroot”挂载点的内容,或者它如何在 systemd-shutdown 下变得不可挂载。

这似乎不是由于日志记录造成的。我已经设置Storage=volatile/etc/systemd/journald.conf创建了一个在启动后运行的 oneshot systemd 服务/usr/bin/journalctl --flush。文件/var/系统现在已成功卸载,并且我不相信重新启动后会丢失所有日志数据。

然而,在关闭期间,循环仍然发生,并伴随着Failed to unmount /oldroot...来自 systemd-shutdown 的消息。是不是有什么副作用把它挂起来了?

相关内容