0

I have a home network with two Debian 9 PCs. I'm using NFS to share a folder from each PC with the other, both read-only. The config files are:

/etc/exports on Machine1:

/path/on/machine1/share machine.2.ip(ro,sync,no_subtree_check)

/etc/fstab on Machine1:

machine.2.ip:/path/on/machine2/share    /path/on/machine1/machine2-share    nfs

When both computers are on, it works fine. However, when one computer is off, the other take two minutes waiting to find the other PC, so it can mount the shared directory. I would like to reduce this time to something more practical, like 5 seconds. I haven't found anything in the manual. How can I do that?

Rodrigo
  • 1,832

2 Answers2

4

If automounting isn’t appropriate, you can use x-systemd.mount-timeout= to specify a shorter timeout:

machine.2.ip:/path/on/machine2/share /path/on/machine1/machine2-share nfs x-systemd.mount-timeout=5

The bg NFS mount option might be useful: it forks a mount which retries in the background. systemd understands this option and configures the mount appropriately.

Stephen Kitt
  • 434,908
  • This works when I turn my machine on with the other turned off. But if both are on and then the other goes off (i.e. the share is already mounted), then Nautilus, a Firefox "send file" window, and even a single ls get frozen. – Rodrigo Sep 11 '18 at 13:14
  • @Rodrigo yes, that’s a feature of NFS and there isn’t much that can be done about it other than ensuring the shared volume is unmounted before the machine serving it is switched off. But you didn’t mention that requirement in your question :-/. – Stephen Kitt Sep 11 '18 at 13:18
  • 1
    @Rodrigo the question doesn’t mention that this is on a home network where machines are liable to be switched off with little warning. The question is about NFS mounts taking too long when the exporting machine is off; that has been addressed. If you have another question about dealing with mounted NFS volumes “going away”, I suggest you ask a new question. A similar question exists already but it doesn’t have a satisfying answer IMO. – Stephen Kitt Sep 12 '18 at 08:04
  • Is there a home network where machines are never turned off? Yes, it seems I need to ask a new question, since in your country the energy seems to be "free". Tip: it's never free. – Rodrigo Sep 12 '18 at 12:45
  • @Rodrigo I’m not arguing about the energy part, I’m just saying that you’re changing the question. You could edit your question to turn it into “Please help me fix all the issues I have running NFS on a home network”, but that would be unfair to the authors of the existing answers. You asked a question, got answers, one of which was good enough for you to accept it; then you came up with another question, and decided to re-use your existing one. That doesn’t work too well with the Q&A format of StackExchange (but I imagine you know that given your SO experience). – Stephen Kitt Sep 12 '18 at 12:48
  • I just thought that home networks were common enough so that NFS should simply work in all usual cases, without me having to describe what the usual cases are. Nevermind, I'll ask another question. Thank you. – Rodrigo Sep 12 '18 at 12:54
2

Perhaps consider using systemd automount?

I am using it and am happy with the way it works:

<ip-address>:/home/export/nfs /home/share/nfs nfs x-systemd.automount,noauto,_netdev 0 0

With this setup, the NFS share is not mounted at boot time, but automounts when you try to access the share (/home/share/nfs) in this trivial example.

  • Thank you. Do I necessarily need the noauto and _netdev options as well? From the manual it isn't clear to me. – Rodrigo Sep 01 '18 at 01:26
  • @Rodrigo This was just an example, you can try to run without those options. –  Sep 01 '18 at 05:01
  • I was too fast accepting your answer. When the other PC went off, Nautilus won't respond ever. Not even save as windows work. I had to use the other answer to make it work. – Rodrigo Sep 02 '18 at 06:55
  • @Rodrigo Yes, the x-systemd.mount-timeout option can be useful as well. –  Sep 02 '18 at 07:13
  • Now, testing the other answer for a few days, I discovered it doesn't work either! – Rodrigo Sep 11 '18 at 23:53