How to mount a NFS share in Ubuntu 16.04?

48,512

Solution 1

I found the following solution here. Apparrently, you have to use specific systemd options in fstab.

servername:/home   /mountpoint/on/client  nfs  noauto,x-systemd.automount,x-systemd.device-timeout=10,timeo=14,x-systemd.idle-timeout=1min 0 0

Solution 2

Had the same problem and have read all the posts on askubuntu.com and elsewhere on it. I finally found a wiki https://wiki.ubuntu.com/systemd#Remote_filesystem_mounts explaining the issue quite well, except for little changes necessary for Ubuntu 16.04. What was not that clear to me after reading this, was that it seems to be necessary to have both, the entry in fstab (pretty standard) AND the .mount file in /etc/systemd/system.

Entry in my fstab:

myserver:/export/work    /mnt/work       nfs     auto    0       0

The mount unit file for systemd /etc/systemd/system/mnt-work.mount (mention the naming convention /mnt/work ==> mnt-work.mount

[Unit]
Description=/mnt/work
Wants=network-online.target rpc-statd.service
After=network-online.target rpc-statd.service

[Mount]
What=myserver:/export/work
Where=/mnt/work
Type=nfs
StandardOutput=syslog
StandardError=syslog
TimeoutSec=50

As you might note, I had to change statd.service to rpc-statd.service and network.target to network-online.target (which I don't know if its necessary).

In addition, I added a timeout of 50 seconds. Nevertheless, when I switch of networking via hardware switch, shutdown will hang.

My problem was, when the fstab entry is missing, the mount unit won't be executed on startup!

Solution 3

It took me ages to fix it, and meantime I was locked out of my nfs shares. I changed the 4th field in /etc/fstab from defaults to user. The problem is that only superuser can mount the shared files. Adding user means that anyone can mount files, including nfs.

Solution 4

I had the same problem, and found this very useful digitalocean article which gives the correct mount options

hostname:/path /mount/path nfs auto,nofail,noatime,nolock,intr,tcp,actimeo=1800 0 0
Share:
48,512

Related videos on Youtube

CaptainPlanet
Author by

CaptainPlanet

Updated on September 18, 2022

Comments

  • CaptainPlanet
    CaptainPlanet over 1 year

    I made a fresh install of Xubuntu 16.04 recently. Before I used 14.04 and mounted a a NFS share with the following line in the /etc/fstab

    192.168.178.66:/media/user/drive /media/user/banana nfs rw 0 0
    

    What should happen?

    The nfs share should be mounted on startup into the given location.

    What happens?

    Boot takes very long and the nfs share is not mounted. A greyed symbol for the share appears on my desktop. When I click on it it says something like "Only root can mount". When I press an arrow during boot I can see the systemd log (I suppose) it says ~ "Startjob for /media/user/banane (30s/1,31s)" It wait’s the whole 91s and the it finally boots. Mounting the nfs manually works. But then shutdown does not end. Looking at the systemd output again: "Stop job for /media/netzwerkfreigabe (30s/2m)" The shutdown does not end at the given limit. Instead another longer limit appears. At least three times.

    Additional Information

    • the package nfs-common is installed on the client computer
    • the nfs server is a BananaPi running BananianLinux (a modified Debian Jessy)
    • I can mount the nfs-share using the same /etc/fstab line from another computer using Xubuntu 14.04

    As far as I know systemd is introduced in Ubuntu 16.04. This may be a systemd issues. Should my fstab config work? Do you mount nfs in a different way these days? I found several reports about similar problems of other users at other forums. Should I file a bug?

    Thank you for your answer!

  • cloud81
    cloud81 almost 8 years
    If you have (like me) /home mounted with encrypted lvm and you're trying to mount a password protected network share, if you have smbcredentials file inside your home, may be changing the location of the credentials file outside the home partition fix the issue (for me, it did!).
  • David Okwii
    David Okwii almost 7 years
    This finally worked for me on Ubuntu 16.04 LTS
  • sheridp
    sheridp over 6 years
    I think I am running into this now. I don't understand why an fstab entry is necessary if I've already systemctl enabled the mount unit file.