7

I have nfs mount to a directory on remote machine. When the remote machine is down or disconnected, any command on the nounted nfs (such as: ls, or open file) is stuck.

I want it to just fail in a few seconds if the nfs dir is not available.

How can I do it?

in /etc/fstab I see

<remote-host-ip>:/path/to/origin /shared/point nfs defaults 0 0

When I run mount I see:

<remote-host-ip>:/path/to/origin on /shared/point type nfs4 (rw,relatime,vers=4.1, rsize=1048576,wsize=1048576,namelen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=<my-ip>,local_loc=none,addr=<remote-ip>)
SHR
  • 293
  • 1
  • 2
  • 10

1 Answers1

12

timeo and retrans are effective only on soft nfs not on hard nfs. Need to change the /etc/fstab like this:

<remote-host-ip>:/path/to/origin /shared/point nfs soft,timeo=30 0 0

timeo is timeout value of 30 deciseconds (3 seconds). there is also the retrans means how much retries to do in case of error.

then in case of server or service down, an error occurred after 9 seconds.

Red15
  • 103
  • 5
SHR
  • 293
  • 1
  • 2
  • 10
  • 2
    Are you certain that *all* the applications that use this filesystem are properly coded to handle the IO errors that a soft NFS mount will return? If not, are you capable of accepting silent data corruption? Are you running binaries from the NFS-mounted filesystem? Are you prepared to handle applications crashing because of network hiccups? Soft-mounted NFS filesystems are EVIL unless you really know what you are doing. **Fix** the reliability issues, don't ignore them. – Andrew Henle Dec 28 '17 at 18:10
  • 1
    As Andrew said above, this is a dangerous thing to do. Make sure you understand the implications! – TheFiddlerWins Feb 25 '20 at 14:40
  • 6
    Why would anyone ever use deciseconds? What was the designer thinking? – Abhilash Kishore May 28 '21 at 18:32
  • Take note that `timeo` is specified in deciseconds (tenths of a second). So you need to set `timeo=number_of_seconds * 10` – Radu Potop Dec 06 '22 at 19:21