Score:0

How to mount NFS share automatically via WiFi?

jp flag

I'm trying to mount a local network NFS share on a laptop connected via WiFi.

The NFS server is set up correctly as far as I'm aware and it's possible to connect to it manually with:

sudo mount -t nfs4 -o proto=tcp,port=2049 192.168.(Server IP):/share /mnt/share

Then, the share is mounted to /mnt/share and immediately accessible.

However, when I try to add the share to /etc/fstab, Dolphin (on Kubuntu) always shows the following error:

An error occurred while accessing '/mnt/share', the system responded: mount.nfs4: failed to prepare mount: Operation not permitted

So far, I've tried various fstab entries, such as:

192.168.(Server IP):/share /mnt/share nfs4 _netdev,x-systemd.after=network-online.target 0 0

nfs://192.168.(Server IP):/share /home/usr/share nfs vers=4,uid=(User ID),gid=(Group ID) 0 0

And other variations of these. The error is always the same (except for the different paths).

Kerberos is not used for authentication.

I am not sure if the issue is that WiFi is not connected when the fstab entry is accessed or something else is the problem.

How can I automatically mount this NFS share using a WiFi connection?

Prototype700 avatar
jp flag
This changed nothing, unfortunately.
Terrance avatar
id flag
I tested it with my system and it worked great, but you might want to see https://itsfoss.community/t/help-with-nfs-share-will-not-mount-automatically/3256/2 where after you manually mount your NFS mount, you can run `tail -1 /etc/mtab | sudo tee -a /etc/fstab` that will add the entry that should work to your fstab.
Terrance avatar
id flag
Or a more accurate command for adding in the mount for NFS4 to the fstab file that is similar: `grep nfs4 /etc/mtab | sudo tee -a /etc/fstab` where it will look for your manually mounted NFS4 that works, then add that to your fstab that should allow for the mounting automatically instead of trying to guess.
Score:1
in flag

I have this working on my laptop. my fstab entry is :

192.168.68.99:/data/nfs_root/files /home/john/nfs nfs _netdev,noauto,x-systemd.automount,x-systemd.mount-timeout=10,timeo=14,x-systemd.idle-timeout=1min 0 0

This is based on the Arch wiki:

The noauto mount option will not mount the NFS share until it is accessed: use auto for it to be available immediately. If experiencing any issues with the mount failing due to the network not being up/available, enable NetworkManager-wait-online.service. It will ensure that network.target has all the links available prior to being active.

The users mount option would allow user mounts, but be aware it implies further options as noexec for example.

The x-systemd.idle-timeout=1min option will unmount the NFS share automatically after 1 minute of non-use. Good for laptops which might suddenly disconnect from the network.

If shutdown/reboot holds too long because of NFS, enable NetworkManager-wait-online.service to ensure that NetworkManager is not exited before the NFS volumes are unmounted.

Do not add the x-systemd.requires=network-online.target mount option as this can lead to ordering cycles within systemd [4]. systemd adds the network-online.target dependency to the unit for _netdev mount automatically.

Using the nocto option may improve performance for read-only mounts, but should be used only if the data on the server changes only occasionally.

Prototype700 avatar
jp flag
Hi, to clarify, `x-systemd.automount` was the culprit. I was reluctant to accept this answer, because I wasn't sure what constitutes as "automount access" for this option and wanted to test it. I have media libraries in VLC and Clementine and didn't know if I had to manually open the share in the file manager for them to work, but this is not the case, the programs will also cause the share to be mounted when accessed, so that does solve the issue. I still get that error sometimes though, I don't know why that's the case.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.