Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
    
Can you post /etc/fstab? –  Karlson Feb 17 '12 at 18:55

1 Answer 1

up vote 9 down vote accepted

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

share|improve this answer
    
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 at 18:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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