paulgorman.org/technical

Linux Autofs

(July 2017)

Autofs automatically mounts filesystems on an as-needed basis. Automounting network filesystems can be more performant and resilient than mounting them in fstab.

The autofs program controls automount daemons. One automount daemon spaws for each map.

# apt-get install autofs

(If mounting SMB shares, install the samba and cifs-utils packages too.)

Configure autofs using the /etc/auto.* config files. Each line in the /etc/auto.master file matches a local mount-point with its map file, like:

# mount-point [map-type[,format]:] map [options]
/smb    /etc/auto.smb

Maps can be “direct” or “indirect”. The example above is an indirect map, because it tells autofs to create mount-points as subdirectories of /smb. Direct maps create a mount-point at the path specified (not below it). The mount-point entry in auto.master is always “/-”. For example, the following line instructs autofs to create a mount-point at the place specified in /etc/auto.foo:

/-    /etc/auto.foo

Map files look like:

# key [-options] location
user1 -type=nfs  myserver:/home/user1
mycifs -fstype=cifs,rw,uid=myuserid,gid=mygrpid ://example.com/sharename
backup -fstype=cifs,rw,file_mode=0600,dir_mode=0700,nounix,uid=0,gid=0,forceuid,forcegid,credentials=/root/etc/autofs-secret-storage-backup.txt ://storage.example.com/linux_backups
myssh -fstype=fuse,allow_other :sshfs\#user@example.com\:/path/to/mount
tunes -fstype=ext4 :/dev/sda4

(Escape map locations beginning with “/” with a colon “:”.)

For an indirect mount, the “key” can be a single directory name (as shown above). For a direct mount, it should be the full path of the mount point.

Debugging Auto Mount Problems

  1. Stop the autofs daemon:

    systemctl stop autofs

  2. Run automount in the foreground:

    automount -f -v

  3. Test by cd’ing (or whatever) into the mount point.