6

This is my first nfs / autofs configuration, so I probably configured something wrong. When I navigate to directory, which I added to /etc/auto.master I can't see any mount points, but when I issue cd with full path to expected mount point, than it tunes out, that I can access it. I think, that outputs below are self explanatory:

user@user-desktop:~/mnt/shares/autofs$ ls
user@user-desktop:~/mnt/shares/autofs$ ls ./backup_tmp
lost+found  test.file

This is how /etc/auto.master file looks like (on the receiver machine). First two lines comes by default, so I was not sure if I should touch them:

+dir:/etc/auto.master.d
+auto.master
/home/user/mnt/shares/autofs /etc/auto.misc --timeout=20

And this is how /etc/auto.misc looks like (first line comes by default):

cd      -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom
data_archive           -fstype=nfs4     192.168.1.140:/mnt/data_archive
data_file-resources    -fstype=nfs      192.168.1.140:/mnt/data_file-resources
backup_tmp             -fstype=nfs      192.168.1.140:/mnt/backup_tmp

Can anyone please help me debug this problem?

s-kaczmarek
  • 145
  • 2
  • 7

2 Answers2

6

This is by design, but autofs provides ways to change this behavior.

You can use the browse option, which only applies to particular entries in your autofs maps, or the browse_mode option, which is system-wide.


Option 1: Add the browse option in your /etc/auto.master map:

/home/user/mnt/shares/autofs /etc/auto.misc --timeout=20 browse

From man auto.master:

[no]browse: This is an autofs specific option that is a pseudo mount option and so is given without a leading dash. Use of the browse option pre-creates mount point directories for indirect mount maps so the map keys can be seen in a directory listing without being mounted. Use of this option can cause performance problem if the indirect map is large so it should be used with caution. The internal program default is to enable browse mode for indirect mounts but the default installed configuration overrides this by setting BROWSE_MODE to "no" because of the potential performance problem. This option does the same as the deprecated --ghost option, the browse option is preferred because it is used by other autofs implementations.


Option 2: Change the value of browse_mode in /etc/autofs.conf.

From man autofs.conf:

browse_mode: Maps are browsable by default (program default "yes").


These man page excerpts are from Ubuntu 20.04, so it is possible that your system's version of autofs differs slightly in config file location or default configuration.

Arnon
  • 173
  • 1
  • 4
3

That's how autofs is supposed to work. The autofs directories are mounted when they are first accessed (that's why there is "auto" in the name). When you do a ls of the parent directory, there is no system call that would access the actual mountpoint path, so they are not visible. When you access explicitly the mountpoint path, it gets mounted. Try to do ls of the parent directory again, and you'll see that the mountpoint has appeared. After the mounted directory is not used by any process for 20 seconds (that's the timeout you have set in the config file), it gets unmounted again and is not visible anymore.

raj
  • 542
  • 2
  • 8
  • Thanks for this explanation. I was rather expecting mount points to be present in my filesystem and than, autofs to mount shares inside of them once accessed. The way it turned out to work is very unintuitive. I think, I will create links to that shares and use such work around. – s-kaczmarek Jan 21 '21 at 20:13
  • Traditionally, autofs was used mainly to mount users' home directories under `/home`, while the actual directories, often located on some NFS share, were located under some other path, like `/export/home`. When the user logged in, the shell tried to go to his/her home directory, so it was automatically mounted. After user logged out, after some time the directory was unmounted. So if you did `ls /home`, you would see only the directories of currently "active" users, and not hundreds or thousands of directories of all users in the system. – raj Jan 21 '21 at 20:19