Understanding NFS mount with systemd

Hi folks,

i try to use systemd to mount two NFS shares in my notebook, because the method of fstab is not working fine. The main problem is that the wifi connection is established later after logging in.

I read about the method of systemd. I understand to create the mount-file in “/etc/systemd/system/” and using the path of mount for the name of the mount-file. I can set the mount-options in the file, too. But i dont understand, if i have to use the entries in the fstab, too. And which options i have to set in the mount-file and the fstab-file.
Note: I want to mount the share after the wifi-connection is established.

systemd-networkd-wait-online will help here → https://www.freedesktop.org/software/systemd/man/systemd-networkd-wait-online.service.html

https://wiki.archlinux.org/index.php/NFS#Mount_using_/etc/fstab_with_systemd

so you can using /etc/fstab with systemd or a systemd unit

1 Like

systemd is doing the work either way. It converts all the entries in /etc/fstab into mount units dynamically. The advantage of using /etc/fstab is that you can see them all in one place.

In your case, there are a lot of options but for network shares I always recommend a systemd automount. It gets dynamically mounted on access so you don’t have to worry about dependencies.

I use something like this in /etc/fstab for my nfs mounts.

server:/share /mnt/mountpoint nfs x-systemd.automount,x-systemd.device-timeout=10,timeo=14,x-systemd.idle-timeout=1min 0 0
1 Like

Thanks for your ideas.
I used now this line in my fstab:

192.168.XXX.XX:/volume/nfsshare   /mnt/nfsshare   nfs   x-systemd.automount,x-systemd-networkd-wait-online,x-systemd-idle-timeout=1min,x-systemd.device-timeout=10,timeo=14   0   0

After reboot i can see the share in Dolphin, but cannot access to it. Dolphin show the error:

mount.nfs: failed to prepare mount. Operation not permitted

If i “ask” systemctl with

systemctl --failed

i see no error.

But if i enter:

sudo mount -a

the share mounts and i can access to the share.

Can you tell me, which error logs i can look at to find the problem?
Thanks

Is it related to this bug?

What does pacman -Qi util-linux return?

@dalto
pacman -Qi util-linux returns (note: i use the german version):

Name                     : util-linux
Version                  : 2.35.1-1
Beschreibung             : Miscellaneous system utilities for Linux
Architektur              : x86_64
URL                      : https://github.com/karelzak/util-linux
Lizenzen                 : GPL2
Gruppen                  : Nichts
Stellt bereit            : rfkill
Hängt ab von             : pam  shadow  coreutils  systemd-libs  libcap-ng
                           libutil-linux
Optionale Abhängigkeiten : python: python bindings to libmount [Installiert]
                           words: default dictionary for look
Benötigt von             : f2fs-tools  fakeroot  gupnp  jfsutils  mkinitcpio
                           nilfs-utils  ntfs-3g  rasqal  reiserfsprogs  systemd
                           tlp  zeromq
Optional für             : syslinux
In Konflikt mit          : rfkill
Ersetzt                  : rfkill
Installationsgröße       : 13,00 MiB
Packer                   : Christian Hesse <arch@eworm.de>
Erstellt am              : Sa 01 Feb 2020 19:36:16 CET
Installiert am           : Sa 08 Feb 2020 14:43:25 CET
Installationsgrund       : Ausdrücklich installiert
Installations-Skript     : Nein
Verifiziert durch        : Signatur

Let me tell you: I tested this entry in the FSTAB on my desktop-PC, in the same home network (without wifi but wired!) i use EndeavourOS, too, just with XFCE instead of plasma. The FSTAB contains exactly the same entry for the same NFS-share. On this desktop PC the fstab works fine.

Thanks for this tip about dynamically mounting nfs shares using systemd in fstab on the client.

Speaking of dependencies however, I still have an issue on the nfs server side (‘VEBODROID’) which also leads to a problem on the client: when the server is freshly booted, Thunar file manager is hanging when browsing an nfs share and must be killed. First I must restart the nfs-server on the server to make things work again. Looking for a solution for this, I came across a how-to where it explicitely says that the rpcbind service must always be started before the nfs-server service:

[ROOT@VEBODROID ~]# showmount -a localhost
clnt_create: RPC: Program not registered
[ROOT@VEBODROID ~]# systemctl restart nfs-server
[ROOT@VEBODROID ~]# showmount -a localhost
All mount points on localhost:
192.168.0.150:/
192.168.0.150:/srv/nfs
192.168.0.99:/srv/nfs
192.168.0.99:/srv/nfs/LaCie
[ROOT@VEBODROID ~]# 

So, now I’m looking for a way to automate this on the server. I can’t find out how to manipulate the order in which services are started.

Make copy of the service in /etc/systemd/system/. and add an After directive to the service so it starts after rpcbind.

There is no nfs-server.service file in '/etc/systemd/system/.` to copy.
In stead I used ‘systemctl edit nfs-server’ and added ‘After’ directive:

[Unit]
Description=nfs-server Service
After=rpcbind.target

This resulted in a new directory in ’ /etc/systemd/system’ called ‘nfs-server.service.d’.
In this directory there is a file ‘override.conf’ with the ‘After’ directive.
However the issue persists; I still have to restart nfs-server to get things working.
What can I do?

Edit: now I understand there are two ways to accomplish this; either copy /usr/lib/systemd/system/nfs-server.service to /etc/systemd/system/. and edit this file OR using ‘systemctl edit nfs-server’.
I prefer the ‘systemctl edit’ way and added Requires=rpcbind.target and After=rpcbind.target
Still no luck…

Perhaps the issue isn’t actually related to rpcbind starting but something else?

Hey guys,
Ok, @dalto jumps in my thread - its ok, but i did not have a solution for my problem yet.

The wifi-connection on my laptop is established very late - after loggin in. The option in the fstab “systemd-networkd-wait-online” is correct, but i think there must be another problem.

I want to use error logs or start logs for finding the problem. I just need a little starting help.

journald with the correct filter could be the right way. Can someone give me a tip?

I always start with sudo journalctl -b -p err which should show all the errors since the most recent boot.

1 Like

Thank you @dalto.
journalctl give me an error:

/etc/systemd/system/mnt-nfsshare.mount:3: Failed to add dependency on network.target,network-online.target, ignoring: Invalid argument

Is it possible, that i have a spelling error in my fstab? this is the line copied from fstab:

192.168.XXX.XX:/volume1/nfsshare  /mnt/nfsshare     nfs      x-systemd.automount,x-systemd-networkd-wait-online,x-systemd-idle-timeout=1min,x-systemd.device-timeout=10,timeo=14    0       0

Can we see the contents of this file?

/etc/systemd/system/mnt-nfsshare.mount

I wonder if there is a special character in there that isn’t obvious?

Damn, i think a made an error: Days before i tested the way of creating the file “mnt-nfsshare.mount” manually, before i try to use the fstab only. The manual created file was already there.

I deleted the file now an restart the system. As i understand, the mount-file will be created automatically by systemd from the entries of fstab?

But after the restart of system, there is no file mnt-nfsshare.mount. The problem is not solved, yet.

Are you still getting an error?

What happens when you try to access it?

HI @dalto,
thanks for you patience.
I still get an error in Dolphin. The NFS-Share is listed in the left tab, but if i click on it, Dolphin shows the message

An error occurred while accessing 192.168.XXX... The message is "mount.nfs: failed to prepare mount: Operation not permitted"

But if i remount with

sudo mount -a

the access ist successful.