我正在调试 systemd 关机问题。这里的问题是一些文件系统在服务仍在运行时被卸载。
一般来说,我们希望 systemd 先关闭服务,然后卸载挂载点。
但是在这里,卸载和停止服务是并行发生的。(见下文)。首先还要卸载根文件系统。
# Unmounting /root...
Unmounting /var/lib/ntp...
Unmounting /etc/cron.d/local...
[ OK ] Stopped Apply Kernel Variables.
Unmounting /proc/fs/nfsd...
Unmounting /tmp/rshell/trace...
Stopping Availability of block devices...
Unmounting /etc/timestamp...
Unmounting /var/lib/nfs/rpc_pipefs...
Unmounting /etc/sysconfig/clock...
[ OK ] Removed slice system-getty.slice.
[ OK ] Stopped Load Kernel Modules.
Unmounting /etc/ssh/ssh_external_host_rsa_key...
[ OK ] Stopped Create Static Device Nodes in /dev.
Unmounting /mnt/log...
[ OK ] Stopped Resets System Activity Logs.
Stopping Crond Periodic Command Scheduler...
[ OK ] Stopped Mount Restricted SFTP Jail Folders.
[ OK ] Stopped Mount Restricted Shell Folders.
Stopping Runs processtat...
Unmounting /etc/ssh/ssh_external_host_ecdsa_key.pub...
[ OK ] Stopped target RPC Port Mapper.
Unmounting /boot...
Unmounting /srv...
Stopping Initializes network console logging...
[ OK ] Stopped Crond Periodic Command Scheduler.
[FAILED] Failed unmounting /root.
[ OK ] Unmounted /var/lib/ntp.
[ OK ] Unmounted /etc/cron.d/local.
**[FAILED] Failed unmounting /mnt/sysimg.**
[ OK ] Unmounted /etc/sysconfig/clock.
[ OK ] Unmounted /usr/share/cracklib.
**[FAILED] Failed unmounting /run/netns.**
[ OK ] Unmounted /tftpboot/state.
**[FAILED] Failed unmounting /tmp/ldap.**
我们如何在 systemd 中同步它?
一般来说,systemd-reboot.service 依赖于 final.target、shutdown.target 和 umount.target。
看起来,umount.target 和 shutdown.target 是并行执行的。
# cat /usr/lib/systemd/system/systemd-reboot.service
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
[Unit]
Description=Reboot
Documentation=man:systemd-halt.service(8)
DefaultDependencies=no
Requires=shutdown.target umount.target final.target
After=shutdown.target umount.target final.target
[Service]
Type=oneshot
ExecStart=/usr/bin/systemctl --force reboot
我试过了, umount.target 依赖于 shutdown.target 但这没有帮助。这些卸载和服务关闭似乎总是并行发生。如果我的理解有误请指正。
请提供一些提示/建议以先正确关闭服务,然后再卸载挂载点。