如何調試 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 的消息。是不是有什麼副作用把它掛起來了?

相關內容