3.3. Configuring automount

Mounting can be automated using a mechanism called automount or autofs.

The /usr/sbin/automount is invoked with the rc-script /etc/init.d/autofs.

service autofs start

or, on some systems:

/etc/init.d/autofs start

This script reads the configuration file /etc/auto.master also called a map. The map file defines mount points to be monitored by individual automount daemons.

Sample /etc/auto.master

/extra /etc/auto.extra
/home /etc/auto.home

When autofs is started it will invoke an instance of /usr/sbin/automount for each mount point defined in the master map /etc/auto.master. When the map file /etc/auto.master is changed it is necessary to restart autofs. For example if mount points have been deleted, then the associated automount daemon is terminated. Likewise, new daemons are started for newly defined mount points.

Multiple filesystems can be mounted on a single mount point. These filesystems as well as the mount options needed (filesystem type, read-write permissions, etc) are defined in a separate file.

Sample /etc/auto.extra

cdrom   -fstype=iso9660,ro,user,exec,nodev,nosuid               :/dev/cdrom
nfs     -fstype=nfs,soft,intr,rsize=8192,wsize=8   192.168.3.100:/usr/local

The CDROM will automatically be accessible in /extra/cdrom and the NFS share is mounted as soon as the /extra/nfs directory is accessed.

[Note]Note

In the above example:

  • The directories /extra/cdrom and /extra/nfs must not be created

  • New entries in /etc/auto.extra are immediately made available: adding

    new -fstype=ext3     :/dev/hda2

    to the file will automatically make /extra/new available

  • By default a mounted device will stay mounted for 5 minutes: if we uncomment the cdrom device in the map file /etc/auto.extra shortly after the CDROM has been accessed, then the device will still be available for approximately 5 minutes in /extra/cdrom