systemd 挂载单元失败显示 “Dependency failed” 但手动 mount 成功

9次阅读

systemd挂载失败主因是依赖单元未就绪,需检查Requires/After声明、反向依赖、fstab冲突及挂载点目录存在性,并通过journalctl定位具体失败依赖。

systemd 挂载单元失败显示 “Dependency failed” 但手动 mount 成功ailed”。

  • 运行 systemctl list-dependencies --reverse your-mount-unit.mount 查看哪些单元依赖它,反向推导其前置条件
  • systemctl cat your-mount-unit.mount 检查 [Unit] 段中是否写了 Requires=network-online.targetAfter=nfs-client.target 等,但对应 target/service 实际未启动成功
  • 执行 systemctl status your-mount-unit.mount,重点看 Loaded 行末尾的依赖提示(如 (TriggeredBy: network-online.target)),再查那个 target 的状态

确认挂载点路径和 fstab 兼容性

systemd 会自动将 /etc/fstab 条目转为动态挂载单元,若同时存在同名的自定义 .mount 单元,可能引发冲突或依赖解析异常。

  • 确保没有重复定义:运行 systemctl list-units --type=mount | grep your-mount-point,看是否出现两个同名单元(如 mnt-data.mountmnt-data.automount
  • 若使用自定义 .mount 单元,建议从 /etc/fstab 中移除对应条目,避免 systemd 生成冲突的隐式单元
  • 挂载点目录必须存在且权限正确;systemd 不会自动创建父目录(除非加 mkdir -pExecStartPre= 中)

调试依赖未就绪的典型场景

常见于网络存储(NFS/CIFS)或加密卷(LUKS+ext4),它们对时机敏感:

  • NFS 挂载:需确保 nfs-client.target 已启动,且 rpc-statd.servicerpcbind.service(如需要)处于 active 状态;可加 Requires=nfs-client.targetAfter=nfs-client.target
  • CIFS 挂载:依赖网络和 systemd-networkd-wait-online.service(或 NetworkManager-wait-online.service),否则可能在 IP 还没配好时就尝试挂载
  • LUKS 解密后挂载:需明确设置 Requires=dev-mapper-your-crypt.deviceAfter=dev-mapper-your-crypt.device,不能只依赖 .device 自动发现

临时验证与修复建议

先快速定位问题,再做持久化修复:

  • systemctl start your-mount-unit.mount 手动触发,观察实时错误:journalctl -u your-mount-unit.mount -n 50 -f
  • 若报 “Job for xxx.mount failed. See 'systemctl status xxx.mount' and 'journalctl -xn'.”,接着运行 journalctl -xn 查最近 10 行完整上下文,常能看到具体哪个依赖 unit failed
  • 确认无误后,用 systemctl daemon-reload 重载配置,再 systemctl enable your-mount-unit.mount 启用开机挂载
text=ZqhQzanResources