Autofs

AutoFS provides automounting of removable media or network shares when they are inserted or accessed.

Installation

Install the autofsAUR package.

Note: You no longer need to load autofs4 module.

Configuration

AutoFS uses template files for configuration which are located in /etc/autofs The main template is called auto.master, which can point to one or more other templates for specific media types.

Open the file /etc/autofs/auto.master with your favorite editor, you will see something similar to this:

/etc/autofs/auto.master
#/media /etc/autofs/auto.media

The first value on each line determines the base directory under which all the media in a template are mounted, the second value is which template to use. The default base path is /media, but you can change this to any other location you prefer. For instance:

/etc/autofs/auto.master
/media/misc     /etc/autofs/auto.misc     --timeout=5
/media/net      /etc/autofs/auto.net      --timeout=60
Note: Make sure the template files ends with a newline (press ENTER after last word). If there is no correct EOF (end of file) line, the AutoFS daemon will not properly load.

The base directory will be created if it does not exist on your system. The base directory will be mounted on to load the dynamically loaded media, which means any content in the base directory will not be accessible while autofs is on. This procedure is however non-destructive, so if you accidentally automount into a live directory you can just change the location in auto.master and restart AutoFS to regain the original contents.

If you still want to automount to a target non-empty directory and want to have the original files available even after the dynamically loaded directories are mounted, you can use autofs to mount them to another directory (e.g. ) and create soft links.

# ln -s /var/autofs/net/share_name /media/share_name

Alternatively, you can have autofs mount your media to a specific folder, rather than inside a common folder.

Open the file /etc/nsswitch.conf and add an entry for automount:

automount: files

When you are done configuring your templates (see below), launch the AutoFS daemon as root by enabling and starting the .

Devices are now automatically mounted when they are accessed, they will remain mounted as long as you access them.

Removable media

Removable devices are assigned block device locations according to the next available spot, e.g. if are already occupied, the next removable media will be given block . Instead of assigning a mount point based on an unreliable block device path, a more robust approach is to use the UUID or PARTUUID of the removable media as the location in the map file.

For example, to mount a specific USB drive to the path , configure the template file and map file:

Use to find the UUID of the partition to mount, then generate the map file:

# _ID=$( blkid --output value --match-tag PARTUUID /dev/sdXY )
# printf "%s %s\n" "black -fstype=auto :PARTUUID=" "${_ID}" >/etc/autofs/auto.mnt

NFS network mounts

AutoFS provides automatically discovering and mounting NFS-shares on remote servers (the AutoFS network template in has been removed in autofs5). To enable automatic discovery and mounting of network shares from all accessible servers without any further configuration, you will need to add the following to the /etc/autofs/auto.master file:

/net -hosts --timeout=60

For instance, if you have a remote server fileserver (the name of the directory is the hostname of the server) with an NFS share named /home/share, you can just access the share by typing:

# cd /net/fileserver/home/share

The -hosts option uses a similar mechanism as the command to detect remote shares. You can see the exported shares by typing:

# showmount servername -e

Manual NFS configuration

To mount a NFS share for file_server on at location , add a new configuration, e.g. :

Single shares

Add the following to /etc/autofs/auto.master:

/media/[my_server] /etc/autofs/auto.[my_server] --timeout 60 --browse

where defines how many seconds to wait before the file system is unmounted. The option creates empty folders for each mount-point in the file in order to prevent timeouts, if a network share cannot be contacted.

Next create a file /etc/autofs/auto.[my_server]

[any_name] -fstype=cifs,[other_options] ://[remote_server]/[remote_share_name]

You can specify a user name and password to use with the share in the section:

[any_name] -fstype=cifs,username=[username],password=[password],[other_options] ://[remote_server]/[remote_share_name]
Note: Escape $, and other characters, with a backslash when necessary.

Multiple shares

You may be specify multiple shares in the /etc/autofs/auto.[my_server], for instance:

[any_name] -fstype=cifs,[other_options] /photos ://[remote_server]/photos /music ://[remote_server]/music /video ://[remote_server]/video

Auto discovery

See the comments in .

FTP and SSH (with FUSE)

Remote FTP and SSH servers can be accessed seamlessly with AutoFS using FUSE, a virtual file system layer.

Remote FTP

First, install the package.

Load the fuse module:

# modprobe fuse

Create a file containg to load it on each system boot.

Next, add a new entry for FTP servers in /etc/autofs/auto.master:

/media/ftp        /etc/autofs/auto.ftp    --timeout=60

Create the file and add a server using the format:

servername -fstype=curl,rw,allow_other,nodev,nonempty,noatime    :ftp\://myuser\:mypassword\@remoteserver

If you want slightly more security you can create the file ~root/.netrc and add the passwords there. Passwords are still plain text, but you can have mode 600, and command will not show them (mounted or not). This method is also less sensitive to special characters (that else must be escaped) in the passwords. The format is:

machine remoteserver
login myuser
password mypassword

The line in looks like this without user and password:

servername -fstype=curl,allow_other    :ftp\://remoteserver

Create the file with this code:

Create the file /sbin/umount.curl with this code:

Set the permissions for both files:

# chmod 755 /sbin/mount.curl
# chmod 755 /sbin/umount.curl

After a restart your new FTP server should be accessible through .

Remote SSH

These are basic instructions to access a remote filesystem over SSH with AutoFS.

Install the package.

Load the module:

# modprobe fuse

Create a file containing to load it on each system boot if you have not one yet.

Install openssh.

Generate an SSH keypair:

$ ssh-keygen

When the generator ask for a passphrase, just press . Using SSH keys without a passphrase is less secure, yet running AutoFS together with passphrases poses some additional difficulties which are not (yet) covered in this article.

Next, copy the public key to the remote SSH server:

$ ssh-copy-id username@remotehost

As root, see that you can login to the remote server:

# ssh username@remotehost

Create a new entry for SSH servers in /etc/autofs/auto.master:

/media/ssh		/etc/autofs/auto.ssh	--timeout=60

Create the file and add an SSH server:

After a restart your SSH server should be accessible through .

MTP

Media Transfer Protocol (MTP) is used in some Android devices.

Install the mtpfs package.

Create a new entry for MTP Device in :

android -fstype=fuse,allow_other,umask=000     :mtpfs

Troubleshooting and tweaks

This section contains a few solutions for common issues with AutoFS.

Using NIS

Version 5.0.5 of AutoFS has more advanced support for NIS. To use AutoFS together with NIS, add in front of the template names in /etc/autofs/auto.master:

/home   yp:auto_home    --timeout=60
/sbtn   yp:auto_sbtn    --timeout=60
+auto.master

On earlier versions of NIS (before 5.0.4), you should add to /etc/nsswitch.conf:

automount: files nis

Optional parameters

You can set parameters like systemwide for all AutoFS media in /etc/default/autofs:

  • Open the /etc/default/autofs file and edit the line:
  • To enable logging (default is no logging at all), uncomment and add to the line in /etc/default/autofs e.g.:

After restarting the daemon, verbose output is visible in the unit status or in the journal.

Identify multiple devices

If you use multiple USB drives/sticks and want to easily tell them apart, you can use AutoFS to set up the mount points and Udev to create distinct names for your USB drives. See udev#Setting static device names for instructions on setting up Udev rules.

AutoFS permissions

If AutoFS is not working for you, make sure that the permissions of the templates files are correct, otherwise AutoFS will not start. This may happen if you backed up your configuration files in a manner which did not preserve file modes. Here are what the modes should be on the configuration files:

  • /etc/autofs/auto.master

In general, scripts (like previous auto.net) should have executable bits set and lists of mounts should not.

If you are getting errors in /var/log/daemon.log similar to this, you have a permissions problem:

May  7 19:44:16 peterix automount[15218]: lookup(program): lookup for petr failed
May  7 19:44:16 peterix automount[15218]: failed to mount /media/cifs/petr

fusermount problems

With certain versions of , you may not be able to unmount a fuse file system drive mounted by autofs, even if you use the option. See the discussion on the mailing list.

Debugging auto mount issues

For better debugging, try running automount in the foreground.

Stop , then run:

# automount -f -v

Or if you want more debug info then try:

# automount -f --debug

Alternatives to AutoFS

  • Systemd can automount filesystems upon demand; see here for the description and the article on sshfs for an example.
  • Thunar Volume Manager is an automount system for users of the Thunar file manager.
  • PCManFM is a lightweight file manager with built-in support for accessing remote shares
  • Udisks is a minimalistic automatic disk mounting service
gollark: True, editing that.
gollark: I am still buying gold directly (1.5 KST per ingot) though not automatically since hydro is keeping private the sell shop program.
gollark: That's a margin of 1.4 KST per ingot, I think.
gollark: So you won't *actually* buy one?
gollark: You mean, you want 800KST for one you have?

See also

This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.