用户登录后挂载 NFS 共享

用户登录后挂载 NFS 共享

我想在登录后挂载 NFS 共享,因为如果无法访问 NAS,通过 fstab 挂载它将延长我的启动过程。

所以我想到了 systemd --user 服务。

[Unit]
Description=Mounting the GuendoNAS
After=network.target

[Service]
User=root
Type=oneshot
ExecStart=/usr/bin/mount -t nfs 10.0.0.64:/disk1 /storage/guendonas/disk1
ExecStart=/usr/bin/mount -t nfs 10.0.0.64:/disk2 /storage/guendonas/disk2

[Install]
WantedBy=default.target

这导致 GROUP 无法生成 /usr/bin/mount/:操作不允许

Active: failed (Result: exit-code) since Fri 2016-01-22 19:06:02 CET; 25s ago
 Main PID: 1968 (code=exited, status=216/GROUP)

Jan 22 19:06:02 Asgard systemd[604]: Starting Mounting the GuendoNAS...
Jan 22 19:06:02 Asgard systemd[1968]: guendomount.service: Failed at step GROUP spawning /usr/bin/mount: Operation not permitted
Jan 22 19:06:02 Asgard systemd[604]: guendomount.service: Main process exited, code=exited, status=216/GROUP
Jan 22 19:06:02 Asgard systemd[604]: Failed to start Mounting the GuendoNAS.
Jan 22 19:06:02 Asgard systemd[604]: guendomount.service: Unit entered failed state.
Jan 22 19:06:02 Asgard systemd[604]: guendomount.service: Failed with result 'exit-code'.

我不确定为什么会发生这种情况,因为该服务应该以 root 用户身份运行,还是 systemd --user 服务允许这样做?有什么替代方案?我可以制作一个自动启动脚本,但我想将该服务用作其他服务的依赖项

答案1

虽然我找不到明确说明这一点的手册页,但人们会认为用户服务单元不能将 USER 设置为除其正在运行的用户 ID 之外的其他值。您应该使用系统 (自动) 挂载单元,可以使用 /etc/fstab 中的条目轻松创建:

10.0.0.64:/disk1  /storage/guendonas/disk1  nfs  noauto,x-systemd.automount 0 0

(在 /etc/hosts 中命名您的服务器可能是一个好主意。)

相关内容