AutoFS

AutoFS is a program that uses the Linux kernel automounter to automatically mount filesystems on demand. It works with USB flash drives and external hard drives, network shares, CD-Rom/DVD/BluRay, and so on.

AutoFS works by monitoring directories on the local filesystem. Whenever a program tries to access one of those directories, AutoFS will mount something on that directory. The directories to monitor, as well as what to mount on them, are specified in the AutoFS configuration files such as. Examples of how to configure AutoFS mounts are given down the page, under.

Installation
AutoFS requires a kernel module and a userspace program.

Kernel configuration
The following kernel option activates the kernel functionality required for automounting.

Userspace program
As with most Linux filesystems, in addition to the relevant option being enabled in the kernel, the userspace package must be installed to actually handle the mounting.

Install it with the following command:

Service
The AutoFS daemon needs to be running for automounting to work.

OpenRC
Add AutoFS to the default runlevel:

To begin using the automounter before rebooting, start it manually:

Of course it is advisable to edit the configuration files first, as described below. If AutoFS is already running when the configuration is edited, run

to make it reload the configuration.

Files
The default installation of AutoFS provides the following four configuration files:

/etc/conf.d/autofs
is the configuration file that corresponds to the initscript. For basic AutoFS usage, there is no need to modify this file.

The file defines two variables:


 * USE_MISC_DEVICE : If this is set to, the initscript will create the device file.
 * OPTIONS : This contains command-line arguments to be passed to . Run   to view the manual page which lists all the allowed options.

/etc/autofs/autofs.conf
is AutoFS's own configuration file. The default installation is well commented, and the options that can be specified in this file are also documented in the manual page, which can be viewed by running

For basic AutoFS usage, there is no need to modify this file.

/etc/autofs/auto.master
is the (default) "master map". Each line describes an AutoFS mount.

Typically, the lines in this file take the following format:

In brief,  specifies a directory for AutoFS to watch, and   that tells AutoFS what to mount there. For details, see below, or view the manual page by running. Neither of these fields may contain spaces.

After handling the first two (whitespace-separated) fields as  and   respectively, anything else on the line is treated as an option to be passed to either AutoFS's  (if it starts with a dash), or  (if it does not). Options passed to will follow the   switch. See for an example.

/etc/autofs/auto.misc
is an example of a "map file". Only those map files actually referenced in the master map file are actually used by AutoFS, so it is safe to rename or delete this file as long as you edit to match. You can also create additional map files following the same syntax. By convention, map files are named with the pattern.

Lines in this file take the following format:

Here  specifies a unique key associated with the AutoFS mount, which forms part or all of the path at which the filesystem will be mounted. tells AutoFS what filesystem to mount there. is a comma-separated list of options to pass to, except for some special options which are handled by AutoFS (such as ). For details, see below, or view the manual page by running .

Usage
AutoFS mounts are specified by lines in. As a reminder, lines in this file take the format

Normally,  is the full path to a map file, such as, which contains lines of the format

Here the  field takes the format. The  component may be left empty to refer to a path on the local machine. Otherwise, the named path from the named remote host will be mounted using NFS.

and  are parsed as described above:


 * is a space-separated list of options to pass to either (if they begin with a dash) or  (if not)
 * is a comma-separated list of options, most of which are passed to

There are two kinds of AutoFS mounts, direct and indirect.

Direct AutoFS mounts
For a direct AutoFS mount, the  is , and   in the map file is the full path at which the filesystem will be mounted. For example, the manual pages for AutoFS include an example like this:

These lines tell AutoFS to watch the directory. If a program tries to access anything in that directory, AutoFS will mount the directory  from the remote host   on the local directory. In other words, it will effectively execute the command

An example of mounting a local device might look like this:

This will effectively execute the command

Indirect AutoFS mounts
For an indirect AutoFS mount, the  is a directory path, and   is the full path to a file which describes rules for mounting devices inside that directory. For example, the default installation includes the following line (though it is commented out):

This line would tell AutoFS to watch files and directories under for filesystem accesses. When a program tries to access something under, AutoFS will use the configuration in to determine whether to automatically mount something. Each (non-comment, non-empty) line in that file corresponds to something that AutoFS will be able to mount under. For example, the line

tells AutoFS to watch. When a program tries to access this directory, AutoFS will effectively run the command

Here are some other examples:

Indirect mounts allow AutoFS to use wildcards. For example, if users' home directories are stored on a different machine and mounted over NFS, AutoFS could be configured as follows:

This way, when a user  logs in and accesses some files in their home directory, AutoFS will effectively run the command

Useful options
These options can be given in the master map file.


 * specifies the number of seconds that an automounted filesystem can go unused before AutoFS unmounts it.
 * or  (no dash in the latter form) can be useful for indirect mounts. It causes AutoFS to create the directory on which something would be mounted when the  daemon starts up, rather than only when the directory is accessed.

For a full description of options, run

Non-file maps
In, instead of merely specifying , the second column can take a more complicated form such as  , which allows the map to be something other than a file. For instance, it can be an executable which prints out map specifications (the lines that would be included in a map file), or any of various types of databases. For a full description of recognized types, run

Simple Windows-like Samba share mounting
Here is a way to automatically mount network Samba shares, as Windows does. This configuration allows automounting a share by issuing the following command in a shell:

or navigatint to in a filesystem browser or dialog. The files inside will appear as if they were located on the local machine.

External resources

 * Automount mini-Howto on The Linux Documentation Project website
 * AutoFS page on the Ubuntu Community Help Wiki