2

I cannot figure out how to mount an NFS share at boot. I've tried a couple different things (listed below) and nothing has worked. In both instances, they require network-online.target, yet they don't seem to be waiting for the network to be online before starting. Yes, I can indeed communicate with the remote machine, and I can run mount -a after logging in and the shares will mount. I'm at a complete loss.

Attempt #1: I put the following in /etc/fstab:

10.0.10.10:/volume1/Media /mnt/media nfs x-systemd.automount,noauto,nofail,x-systemd.requires=network-online.target,suid,dev,exec,rw,sync,nouser 0 0

The result after rebooting:

root@ubuntu-svr:~# journalctl -b -u mnt-media.mount
-- Logs begin at Mon 2019-08-12 00:00:56 UTC, end at Fri 2019-09-20 22:05:16 UTC. --
Sep 20 21:36:29 ubuntu-svr systemd[1]: Mounting Mounts the '/mnt/media' directory...
Sep 20 21:36:29 ubuntu-svr mount[1528]: mount.nfs: Network is unreachable
Sep 20 21:36:29 ubuntu-svr systemd[1]: mnt-media.mount: Mount process exited, code=exited, status=32/n/a
Sep 20 21:36:29 ubuntu-svr systemd[1]: mnt-media.mount: Failed with result 'exit-code'.
Sep 20 21:36:29 ubuntu-svr systemd[1]: Failed to mount Mounts the '/mnt/media' directory.

Attempt #2: I commented out the fstab entry and created a systemd mnt-media.mount file and enabled the systemd unit to start on boot. This is what the mnt-media.mount file consisted of:

root@ubuntu-svr:~# cat /etc/systemd/system/mnt-media.mount
[Unit]
Description=Mounts the '/mnt/media' directory
Wants=network-online.target
Requires=network-online.target
#After=network-online.target

[Mount]
Where=/mnt/media
What=10.0.10.10:/volume1/Media
Options=auto,x-systemd.automount,nofail,suid,dev,exec,rw,sync,nouser
Type=nfs

[Install]
WantedBy=multi-user.target

I enabled it via systemctl enable mnt-media.mount. I rebooted, and checked the status of it:

root@ubuntu-svr:~# systemctl status mnt-media.mount
● mnt-media.mount - Mounts the '/mnt/media' directory
   Loaded: loaded (/etc/systemd/system/mnt-media.mount; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Fri 2019-09-20 22:28:51 UTC; 1min 12s ago
    Where: /mnt/media
     What: 10.0.10.10:/volume1/Media

Sep 20 22:28:51 ubuntu-svr systemd[1]: Mounting Mounts the '/mnt/media' directory...
Sep 20 22:28:51 ubuntu-svr mount[1206]: mount.nfs: Network is unreachable
Sep 20 22:28:51 ubuntu-svr systemd[1]: mnt-media.mount: Mount process exited, code=exited, status=32/n/a
Sep 20 22:28:51 ubuntu-svr systemd[1]: mnt-media.mount: Failed with result 'exit-code'.
Sep 20 22:28:51 ubuntu-svr systemd[1]: Failed to mount Mounts the '/mnt/media' directory.
5
  • Take a look at autofs. It won't mount anything shares until they're actually used. Not sure why it's trying to mount before the network is up; my Samba mounts don't have this issue. Sep 20, 2019 at 23:14
  • This might also help: unix.stackexchange.com/questions/349264/… Sep 20, 2019 at 23:16
  • @ajgringo619 -- I looked into autofs, but I need it to mount before they're even used because docker I have docker containers that autostart that rely on this share. I checked out that link earlier -- that's how I came up with my fstab entry.
    – beechfuzz
    Sep 20, 2019 at 23:34
  • @beechfuzz Can you try setting the 'after network-online.target' option? If that works out, you could then modify the Docker unit file to have a dependency on this mount point.
    – Haxiel
    Sep 21, 2019 at 3:44
  • I figured it out -- I submitted the answer. I needed to enable systemd-networkd-wait-online.service. I had previously disabled it to speed up boot.
    – beechfuzz
    Sep 23, 2019 at 14:59

2 Answers 2

4

Solved:

Turns out I needed to enabled the systemd-networkd-wait-online.service service. Now both attempts that I tried (/etc/fstab and mnt-media.mount) work as intended.

For anyone else struggling with this, depending on whether you're using systemd-networkd or NetworkManager, you need to make sure that systemd-networkd-wait-online.service or NetworkManager-wait-online.service is enabled on your system. Otherwise, your system will not wait for the network to be up even though your mounts explicitly require it.

I came across this answer via this link: NFS/Troubleshooting - Network is unreachable.

1
  • this needs to be run on the server or the client
    – Coddy
    Oct 8, 2023 at 5:27
0

If the above does not help you i.e me (had the services already enabled and running NetMan)

I added x-systemd.after=network-online.target to the fstab entry and rebooted and it worked. not sure if the _netdev helps but its part of my entry aswell.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .