Blocking or disabling autofs automounts with the -null map
Suppose you have a linux network setup with automounter maps that come from the network (via nis, sssd, LDAP etc.) and you want to block some of them acting on a particular system. In our case we have an automount map that acts on /opt and mounts various software packages from network shares. The problem with this is that you can’t then install your own stuff locally to /opt, which is what a lot of Debian/Ubuntu packages expect to be able to do.
It turns out there is a option in the automounter for this sort of situation. There is a built-in map called -null that blocks any further automounts to a particular mountpoint. In our case we want to block auto.opt, so we add a line to auto.master (somewhere before the bottom +auto.master line)
/opt -null
Then restart the autofs service (if stuff was mounted on /opt then unmount it). Or reboot the system. You should find that you can put stuff in the local /opt.
To check the map is blocked you can also run
automount --dumpmaps
(also handy for checking what is actually meant to be mapped where).
Another way of doing this that leaves the system auto.master untouched is to create a file /etc/auto.master.d/opt.autofs (the first part of the name can be anything you want). Put the same contents in the file, e.g.
/opt -null
Note that using this mechanism normally requires two files – one in /etc/auto.master.d/ and a map file that it refers to. In this case -null is a built-in map.
Unfortunately this option is not well documented. Places where it is referred to are:
- https://www.vibrantbootcamp.com/Networking%20Guide/autoD.about_builtin.html
- http://osr507doc.xinuos.com/en/NetAdminG/autoC.maps.html#autoD.about_null
- https://bugzilla.redhat.com/show_bug.cgi?id=856296
- https://bugzilla.redhat.com/show_bug.cgi?id=214800
There are also other built-in maps, e.g. -passwd, -hosts, -fedfs. Of these only the -hosts map is documented in the auto.master(5) man page.
-null is confirmed to work in CentOS 7, CentOS 8, Ubuntu 20.04, Debian 10.