4

Any way to get linux to give up on trying to reconnect nfs shares? I have them in fstab currently. I'd like them to attempt mount at boot and only try to reconnect manually thereafter. The shares it's complaining about below are on a machine that's not turned on all the time.

$ tail /var/log/syslog
Mar 17 10:13:26 Inspiron kernel: [429184.924089] nfs: server 192.168.1.200 not responding, timed out
Mar 17 10:13:30 Inspiron kernel: [429189.132255] nfs: server 192.168.1.200 not responding, timed out
Mar 17 10:13:37 Inspiron kernel: [429196.156051] nfs: server 192.168.1.200 not responding, timed out
Mar 17 10:13:37 Inspiron kernel: [429196.156072] nfs: server 192.168.1.200 not responding, timed out
Mar 17 10:13:42 Inspiron kernel: [429200.364084] nfs: server 192.168.1.200 not responding, timed out
Mar 17 10:13:46 Inspiron kernel: [429204.572092] nfs: server 192.168.1.200 not responding, timed out
Mar 17 10:13:53 Inspiron kernel: [429211.596078] nfs: server 192.168.1.200 not responding, timed out
Mar 17 10:13:53 Inspiron kernel: [429211.596122] nfs: server 192.168.1.200 not responding, timed out
Mar 17 10:13:57 Inspiron kernel: [429215.804094] nfs: server 192.168.1.200 not responding, timed out
Mar 17 10:14:01 Inspiron kernel: [429220.012094] nfs: server 192.168.1.200 not responding, timed out



$ cat /etc/fstab 
192.168.1.200:/mnt/Raid/TV_SHOWS /home/Shares/TV_SHOWS nfs rsize=8192,wsize=8292,timeo=14,intr,rw,user
192.168.1.200:/mnt/Raid/MOVIES /home/Shares/Movies nfs rsize=8192,wsize=8292,timeo=14,intr,rw,user
192.168.1.200:/mnt/Raid/DocuTV /home/Shares/DocuTV nfs rsize=8192,wsize=8292,timeo=14,intr,rw,user

UPDATE:

I've modified my fstab with the additional flags but the problem is still occuring for some reason. Once the shares are mounted and the nfs server goes down it keeps trying to reestablish the connection rather than just unmount them. This problem only occurs if the nfs server goes down while the shares are mounted I believe.

192.168.1.200:/mnt/Raid/TV_SHOWS /home/Shares/TV_SHOWS nfs rsize=8192,wsize=8292,timeo=14,intr,rw,user,retry=0,nofail
192.168.1.200:/mnt/Raid/MOVIES /home/Shares/Movies nfs rsize=8192,wsize=8292,timeo=14,intr,rw,user,retry=0,nofail
192.168.1.200:/mnt/Raid/DocuTV /home/Shares/DocuTV nfs rsize=8192,wsize=8292,timeo=14,intr,rw,user,retry=0,nofail

UPDATE 2: I've tried bg, soft, retrans=100 , retry=0, nofail

It still doesn't seem to be unmounting the share when it loses connection. Every couple of minutes I get a couple of timeout messages for each share.

SOLUTION: I followed antipode's instructions below with a few changes

auto.master
/- /etc/auto.shares --timeout=60

The base mount point is / instead of /home/user/Shares. This fixed some issues I was having using autofs+fstab simultaneously. Shares unmount after 60 seconds.

auto.shares
/home/user/Shares/TV_SHOWS    -rsize=8192,wsize=8292,timeo=14,intr,rw,uid=1000,gid=1000    192.168.1.200:/mnt/Raid/TV_SHOWS
/home/user/Shares/Movies      -rsize=8192,wsize=8292,timeo=14,intr,rw,uid=1000,gid=1000    192.168.1.200:/mnt/Raid/MOVIES
/home/user/Shares/DocuTV      -rsize=8192,wsize=8292,timeo=14,intr,rw,uid=1000,gid=1000    192.168.1.200:/mnt/Raid/DocuTV

Notice the colons after the nfs server IP. UID/GID mounts shares as user instead of root.

1
  • My initial solution only helps with initially mounting the shares. I've edited my answer to include a solution that only mounts the NFS shares as needed, and automatically unmounts them when they're not being used. Let me know if this solution works for you.
    – antipode
    Commented Mar 17, 2015 at 18:06

1 Answer 1

6

Edit: Since the problem only occurs when the NFS server goes down AFTER the share has already been successfully mounted, the previous answer does not help.

My only suggestion now is to use autofs to mount the NFS shares on-demand, instead of mounting them on boot. This way, the system will only attempt to mount the NFS shares when you try to access them, and will automatically unmount them after a period of inactivity.

There is a guide on how to use autofs available here, but below I will list the steps you should need to follow to get something running.

  1. Make sure autofs is installed. The package is usually just called 'autofs'

    On Ubuntu, you can install it by running apt-get install autofs as root.

  2. Add the following entry (as root) to /etc/auto.master

    /home/Shares /etc/auto.shares
    
  3. Create the file /etc/auto.shares (as root), with the following content:

    TV_SHOWS    -rsize=8192,wsize=8292,timeo=14,intr,rw    192.168.1.200:/mnt/Raid/TV_SHOWS
    Movies      -rsize=8192,wsize=8292,timeo=14,intr,rw    192.168.1.200:/mnt/Raid/MOVIES
    DocuTV      -rsize=8192,wsize=8292,timeo=14,intr,rw    192.168.1.200:/mnt/Raid/DocuTV
    
  4. Remove the static mount points for these directories from /etc/fstab

  5. Reload the autofs service. On Ubuntu, you can run service reload autofs as root to do this.

  6. Test to make sure it works. Run ls /home/Shares/TV_SHOWS and see if it lists your files.


Note: Due to additional information added to the question, the following answer no longer applies. I will leave it here, however, in case it helps someone in the future.


You could try adding the nofail option to the entires in /etc/fstab.

From the mount manpage:

nofail

    Do not report errors for this device if it does not exist.

This should cause the system to attempt to mount the device on boot, but give up if it is unable to do so. You can then manually attempt to mount the device later.

There is another option that may be useful: retry (nfs manpage)

retry=n

    The number of minutes that the mount(8) command retries an NFS mount
    operation in the foreground or background before giving up. If this
    option is not specified, the default value for foreground mounts is 2
    minutes, and the default value for background mounts is 10000 minutes
    (80 minutes shy of one week). If a value of zero is specified, the
    mount(8) command exits immediately after the first failure.

By default, NFS mounts are foreground mounts, and thus should fail after 2 minutes of attempts. You could always manually set this to a certain amount of time to cause it to fail more quickly if the NFS server is unavailable, which combined with the nofail option, could get it to work as you want.

0

You must log in to answer this question.

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