0

I would like to automount a nfs share using autofs but it doesn't work.

This works :

mount -vvv -t nfs -o vers=3 192.168.0.12:/share /local/data/mydir

But when I put this line in my /etc/auto.master, it doesn't work, there is nothing in mydir after autofs restarted.

/etc/auto.master

/local/data/mydir 192.168.0.12 -vers=3

Thanks for your help.

tonio94
  • 145
  • 3
  • 8
  • Looks like you can't put direct map entries in auto_master, it has to be in a separate file (at least in some versions of Linux/BSD). If this is true, I'm surprised. – Sridhar Sarnobat Jul 05 '17 at 00:11

1 Answers1

1

Generally, auto.master contains a mapping of local dir to config file:

/misc  /etc/auto.misc

In your case, probably you would want something like

/local/data /etc/auto.local_data --timeout=60 --ghost

You would then create /etc/auto.local_data like so:

mydir 192.168.0.12:/share

As you noted, this does basically hand over /local/data to autofs. If /local/data has actual local dirs in its, a bind mount might work better.

For that, amend /etc/auto.master:

/mount/data /etc/auto.local_data --timeout=60 --ghost

Then, you can bind-mount the required folders via /etc/fstab:

/mount/data/mydir /local/data/mydir none _netdev,bind 0 0

Edit: re-read question, amended config suggestion

iwaseatenbyagrue
  • 3,688
  • 15
  • 24
  • Thanks for your answer. I tried it but it doesn't work. /etc/auto.local_data is mounted on /local/data so the content of /local/data disappears, only mydir directory stays and I can't access it "-bash: cd: mydir/: No such file or directory". Any idea ? – tonio94 Feb 28 '17 at 14:10
  • Right - sorry, I had assumed /local/data was only used to mount NFS/autofs dirs. You do need to provide the full path on your remote node for the mount - not sure if you have. If you do have a bunch of other things in /local/data, you might consider using autofs to mount NFS elsewhere (e.g. /mount/local_data) and add an entry in /etc/fstab to bind-mount any paths to where you need them. – iwaseatenbyagrue Feb 28 '17 at 14:12
  • Did you check you can mount the folder without autofs? e.g. `sudo mkdir -p /mount/test && sudo mount 192.168.0.12:/path/to/data /mount/test`. EDIT: sorry re-read your question.. sec – iwaseatenbyagrue Feb 28 '17 at 14:15
  • Without autofs it's ok, I can mount it. Strangely I tried to add it in fstab and it doesn't work too, don't know why. I have this message : "mount.nfs: mount(2): Permission denied mount.nfs: access denied by server while mounting 192.168.0.12:/share" in fstab : 192.168.0.12:/share /local/data/mydir nfs vers=3 0 0 – tonio94 Feb 28 '17 at 15:05
  • OK - do you actually mean to use autofs here, or did you want to use fstab? Both can mount a remote volume at boot, AFAIK autofs is considered 'better' because it doesn't risk locking the system while waiting for a mountpoint. But, as you saw, it does tend to want to do things a certain way... Maybe worth your while to re-run your original mount command, and see if you can glean anything from the `mount -vvv` output (notably, what settings are used). – iwaseatenbyagrue Feb 28 '17 at 15:17
  • I'd prefer to use autofs actually, but in the meanwhile if I can't find a solution or automount it in a used directory (and not a dedicated nfs directory) I'm ok to use fstab. – tonio94 Feb 28 '17 at 15:20
  • Can't find a definitive reference, but my understanding is that the 'root' dirs for autofs should be empty. So (again, AFAIK) unless /local/data is contains only autofs mounts, you will need to involve fstab somehow. As mentionned, you can either do what you have done, and mount nfs via fstab directly, or you can use autofs, and create a bind in fstab. – iwaseatenbyagrue Feb 28 '17 at 15:28
  • In passing - not sure you need `-ver=3`, I think it is still the default for most linuxen. – iwaseatenbyagrue Feb 28 '17 at 15:29
  • So I'm going to use fstab. But, this works : mount -t nfs -o vers=3 192.168.0.12:/share /local/data/mydir, but this in /etc/fstab doesn't work : 192.168.0.12:/share /local/data/mydir nfs vers=3 0 0. As I said I have a permission denied, don't know why. When I try to mount with -vvv, output is exactly the same, except that with fstab I have this permission denied... – tonio94 Feb 28 '17 at 15:32
  • It might help to share the server config, I guess, but checking root_squash and/or allowing insecure mounts might be worth a go – iwaseatenbyagrue Feb 28 '17 at 15:45
  • Ok I'll ask for the config (don't have access), for now I mounted it manually. Thanks for your help! – tonio94 Feb 28 '17 at 15:55
  • Good luck - I did have something like this happen a while back, but I can't find my notes just now. Definitely ask the people running the server to check their logs for anything that might help. – iwaseatenbyagrue Feb 28 '17 at 15:58