Chapter 19: Network file systems and autofs
More autofs maps: wildcards and direct maps
One map line per share is fine for a single directory. For a site with hundreds of home directories you want one line that serves them all, and sometimes you need a mount point at an exact path in the tree instead of under a parent directory. autofs has maps for both.
- Write a wildcard map that serves a directory per user on demand.
- Write a direct map for a mount at a fixed path.
- Check what autofs has loaded and why a mount fails.
Three kinds of map
Kinds of autofs maps: Select a map type.
Home directories on demand
Suppose serverb exports /srv/homes, with a subdirectory per user, to the lab network (/srv/homes 172.25.250.0/24(rw,sync), then exportfs -ra). On the client, one master entry and one wildcard line serve every user:
[root@servera ~]# echo '/remote/homes /etc/auto.homes' > /etc/auto.master.d/homes.autofs
[root@servera ~]# echo '* -rw,sync serverb:/srv/homes/&' > /etc/auto.homes
[root@servera ~]# systemctl reload autofs
[root@servera ~]# ls /remote/homes
[root@servera ~]# cat /remote/homes/alice/readme
alice home
[root@servera ~]# ls /remote/homes
alice
[root@servera ~]# mount | grep remote | cut -c1-70
/etc/auto.homes on /remote/homes type autofs (rw,relatime,fd=15,pgrp=2
serverb:/srv/homes/alice on /remote/homes/alice type nfs4 (rw,relatimeThe key * matches whatever name you access, and & repeats that name on the right: accessing alice mounts serverb:/srv/homes/alice. Directories are created only when used, so the listing of /remote/homes is empty until somebody enters a home. Because NFS maps numeric IDs, the user must have the same UID on both machines for the files to be theirs.
A direct map
An indirect map always creates the mount points below a directory that autofs owns. A direct map puts them at full paths. The master entry is the special /-:
[root@servera ~]# echo '/- /etc/auto.direct' > /etc/auto.master.d/direct.autofs
[root@servera ~]# echo '/mnt/direct/data -rw serverb:/srv/shared' > /etc/auto.direct
[root@servera ~]# systemctl reload autofs
[root@servera ~]# ls /mnt/direct/data | head -2
alice
hello.txtEach key in a direct map is a complete path. Use it when the mount point must be exactly there.
Looking inside autofs
[root@servera ~]# automount -m | grep -E "Mount point|map:"
Mount point: /misc
map: /etc/auto.misc
Mount point: /net
Mount point: /-
map: /etc/auto.direct
Mount point: /remote/homes
map: /etc/auto.homes
Mount point: /mnt/auto
map: /etc/auto.sharedautomount -m dumps the maps autofs has loaded (the ones named /misc and /net ship with the package and are not used here). findmnt -t autofs,nfs4 shows which are active, and journalctl -u autofs shows the service's own messages. If an entry is missing from the dump, you have not reloaded or the file name does not end in .autofs.
Try it
Check your understanding
- In a wildcard map, what does & stand for?
- Which master map entry introduces a direct map?
- Which command lists the maps autofs has loaded?
- Why is autofs a good fit for home directories?
- A map line has the wrong server path. Where do you see why the mount fails?
- You edited /etc/auto.homes. What next?