尽管配置了 IP 地址,NFS 安装在启动时失败

尽管配置了 IP 地址,NFS 安装在启动时失败

我尝试在 Raspberry Pi 4 上启动时挂载我的 NFS 共享。它不起作用,systemd 抱怨网络无法访问。手动安装每个共享按预期工作。我现在尝试了不同的事情。我没有使用/etc/fstabsystemd 服务来安装卷,如下所示:

[Unit]
Description=Mount NFS share Music
After=network-online.target
Wants=network-online.target

[Mount]
What=10.5.0.34:/music
Where=home/pi/media_storage/music
Options=auto
Type=nfs
TimeoutSec=60

[Install]
WantedBy=remote-fs.target

这两个服务systemd-networkd.servicesystemd-networkd-wait-online.service启用。这是journalctl输出:

Nov 30 16:30:46 NextcloudPi dhcpcd[383]: eth0: IAID 32:23:48:46
Nov 30 16:30:46 NextcloudPi dhcpcd[383]: eth0: adding address fe80::9819:5d1a:3c86:8b41
Nov 30 16:30:46 NextcloudPi dhcpcd[383]: eth0: rebinding lease of 10.5.0.43
Nov 30 16:30:46 NextcloudPi dhcpcd[383]: eth0: probing address 10.5.0.43/24
Nov 30 16:30:46 NextcloudPi dhcpcd[383]: eth0: soliciting an IPv6 router
Nov 30 16:30:47 NextcloudPi systemd-networkd[152]: eth0: Gained IPv6LL
Nov 30 16:30:47 NextcloudPi systemd-timesyncd[281]: Network configuration changed, trying to establish connection.
Nov 30 16:30:47 NextcloudPi systemd-networkd-wait-online[183]: ignoring: lo
Nov 30 16:30:47 NextcloudPi systemd[1]: Started Wait for Network to be Configured.
Nov 30 16:30:47 NextcloudPi systemd[1]: Reached target Network is Online.
Nov 30 16:30:48 NextcloudPi systemd[1]: Mounting Mount NFS share Music...
Nov 30 16:30:48 NextcloudPi systemd[1]: Started /etc/rc.local Compatibility.
Nov 30 16:30:48 NextcloudPi mount[498]: mount.nfs: Network is unreachable
Nov 30 16:30:48 NextcloudPi systemd[1]: mnt-music.mount: Mount process exited, code=exited, status=32/n/a
Nov 30 16:30:48 NextcloudPi systemd[1]: mnt-music.mount: Failed with result 'exit-code'.
Nov 30 16:30:48 NextcloudPi systemd[1]: Failed to mount Mount NFS share Music.
Nov 30 16:30:48 NextcloudPi systemd[1]: Reached target Remote File Systems.

根据journalctl接口已配置并具有有效的 IP 地址。到底为什么mount.nfs还要抱怨呢?

答案1

由于network-online.target似乎已损坏,因此无论我做什么,我都会开发出不同且可靠的解决方案。

我创建了一个 oneshot systemd 脚本:“ping_barrier”。它会对 NFS 服务器执行 ping 操作,直至成功。这WantedBy=nfs-client.target使得 NFS 等待该服务完成。

[Unit]    
Description=Ping until Success

[Service]
Type=oneshot
ExecStart=/opt/ping_barrier.sh
StandardOutput=journal

[Install]
WantedBy=nfs-client.target

以下是 ping 脚本,该脚本会循环执行,直到 ping 命令成功:

#!/bin/bash    
printf "%s" "waiting for FileServer ..."
while ! ping -c 1 -n -w 1 10.5.0.34 &> /dev/null
do
    printf "%c" "."
done
printf "\n%s\n"  "Server is back online"

相关内容