18

I have a somewhat interesting setup: A server with multiple remote NFS servers mounted in a folder, with that folder then being re-exported over Samba. Think of it as a share proxy, keeping all the shared folders in one place.

My issue though is that whenever one of the mounts goes down (server restarted, service restarted, external hard drive that the server was exporting removed, etc) any attempt to read the mount blocks forever. This also means that running ls in that directory freezes and users connecting over Samba also freeze. This has also caused a few times one of my cron jobs to block which almost crashed the server because it had hundreds of blocked processes. This is getting very annoying as I usually have to bring up a terminal that isn't waiting for ls to finish (can't cancel it), run for i in *; do sudo umount -l -f $i; done;, hope that it works, fix the issue, then remount everything.

Is there a way to mount an NFS share with the stipulation that if the connection fails for whatever reason (preferably with a retry period) then the mount un-mount's itself or at least doesn't block?

1
  • Can you post /etc/fstab? – Karlson Feb 17 '12 at 18:55
23

Normally when mounting NFS it's a good idea to have flags set similar to this:

bg,intr,soft
   bg      If  the  first  NFS  mount  attempt times out, retry the mount in the 
           background.  After a mount operation is backgrounded, all subsequent mounts
           on the same NFS  server  will  be  backgrounded immediately, without first
           attempting the mount.  A missing mount point is treated as a timeout, to
           allow for nested NFS mounts.
   soft    If  an  NFS  file operation has a major timeout then report an I/O error
           to the calling program.  The default is to continue retrying NFS file
           operations indefinitely.
   intr    If  an  NFS  file  operation  has  a major timeout and it is hard mounted,
           then allow signals to interupt the file operation and cause it to return
           EINTR to the calling program.  The default is to not allow file operations
           to be interrupted.

You can in addition set:

timeo=5,retrans=5,actimeo=10,retry=5

which should allow the NFS mount to timeout and make the directory inaccessible if the NFS server drops the connection rather then waiting in retries.

Take a look at this link for more information about NFS mount options

4
  • using only bg,intr,soft still leaves a hang of 120 seconds in Fedora 20. But adding timeo=5,retrans=5,actimeo=10,retry=5 makes it nice and quick. Thanks! – Greg Sheremeta Jun 19 '14 at 18:17
  • 6
    "The intr / nointr mount option is deprecated after kernel 2.6.25. Only SIGKILL can interrupt a pending NFS operation on these kernels, and if specified, this mount option is ignored to provide backwards compatibility with older kernels." "This option is provided for backward compatibility. It is ignored after kernel 2.6.25." – David C. Bishop May 2 '16 at 23:46
  • 1
    @DavidC.Bishop where is that quote from? Can you give a link? Thanks. – becko Oct 4 '16 at 18:06
  • 3
    @becko: The SIGKILL quote is from the nfs man page (just search down for 'nointr'). The newer versions, such as the one on my system now simply read "This option is provided for backward compatibility. It is ignored after kernel 2.6.25." linky. – David C. Bishop Oct 9 '16 at 1:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.