From ArchWiki
Revision as of 20:58, 23 July 2009 by Uwinkelvos (Talk | contribs) (Configuration)

Jump to: navigation, search

Template:I18n links start Template:I18n entry Template:I18n links end


This document outlines the procedure needed to set up AutoFS, a package that provides support for automounting removable media or network shares when they are inserted or accessed.


  • Install the AutoFS package:
# pacman -S autofs
  • Load the autofs4 module as root:
# modprobe autofs4


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:
/var/autofs/misc	/etc/autofs/auto.misc
/var/autofs/net	/etc/autofs/

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

/media/misc     /etc/autofs/auto.misc     --timeout=5,ghost
/media/net      /etc/autofs/      --timeout=60,ghost

The optional parameter timeout sets the amount of seconds after which to unmount directories. The parameter ghost determines that configured mounts will always be shown, instead of only when they are inserted and accessed. This can be useful since you won't have to remember or guess the names of removable media and network shares.

The target directories have to exist on your system and need to be empty, since their contents will be swapped with the dynamically loaded media. 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.

Note: Make sure there is an empty line on the end of template files (press ENTER after last word). If there is no correct EOF line, the AutoFS daemon won't properly load.

Removable media

  • Open /etc/autofs/auto.misc to add, remove or edit miscellaneous devices. For instance:
#kernel   -ro                              
#boot     -fstype=ext2                               :/dev/hda1
usbstick  -fstype=auto,async,nodev,nosuid,umask=000  :/dev/sdb1
cdrom     -fstype=iso9660,ro                         :/dev/cdrom
#floppy   -fstype=auto                               :/dev/fd0

If you have a CD/DVD combo-drive you can change the cdrom line with "-fstype=auto" to have the media type autodetected.

NFS Network mounts

The AutoFS network template in /etc/autofs/ automatically detects NFS-shares on remote servers, so you will generally not have to edit this manually. For instance, if you have a remote server fileserver with an NFS share named myshare, you can just enter the corresponding local directory:

# cd /media/net/fileserver/myshare

The script uses the showmount command to detect remote shares. You can test this manually by typing:

# showmount <servername> -e 

Replacing <servername> with the name of your own server.


The Arch package does not provide any samba or cifs templates/scripts (23.07.2009), but the following should work for single shares:

add the following to /etc/autofs/auto.master

/media/[my_server] /etc/autofs/auto.[my_server]

and then create a file /etc/autofs/auto.[my_server]

[my_share] -fstype=cifs,[other_options] ://[my_server_ip]/[my_share]

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 curlftpfs package from the Community repository:

# pacman -S curlftpfs

Load the Fuse module:

# modprobe fuse

Add fuse to the modules array in /etc/rc.conf 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,ghost

Create the file /etc/autofs/auto.ftp and add a server using the ftp://user:password@host:port/path format:

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

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

#! /bin/sh
curlftpfs $1 $2 -o $4,disable_eprt

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

#! /bin/sh
fusermount -u $1

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 /media/ftp/servername

Remote SSH

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

Note: The example below does not use an ssh-passphrase to simplify the installation procedure, please note that this may be a security risk in case your local system gets compromised.

Install the sshfs package from the Extra repository:

# pacman -S sshfs

Load the Fuse module:

# modprobe fuse

Add fuse to the modules array in /etc/rc.conf to load it on each system boot:

Install OpenSSH:

# pacman -S openssh

Generate an SSH keypair:

# ssh-keygen -t dsa

When the generator ask for a passphrase, just press enter. 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 -i ~/.ssh/ username@remotehost

Copy the private key to the root's home directory so that AutoFS can find it:

# sudo cp ~/.ssh/id_dsa /root/.ssh/id_dsa

The above is a workaround since AutoFS runs as root and has no default access to the user's home directory containing the private key.

See that you can login to the remote server without entering a password:

# ssh username@remotehost

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

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

Create the file /etc/autofs/auto.ssh and add an SSH server:

servername     -fstype=fuse,rw,nodev,nonempty,allow_other,max_read=65536 :sshfs\#username@host\:/

After a restart your SSH server should be accessible through /media/ssh/servername

Starting AutoFS

  • When you are done configuring, launch the AutoFS daemon as root:
# /etc/rc.d/autofs start

To start the daemon on boot you can add autofs to the DAEMONS array in /etc/rc.conf, and autofs4 to the modules array in the same file.

If you change the auto.master template while AutoFS is running, you will have to restart the daemon for the changes to become effective:

# /etc/rc.d/autofs restart

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

Troubleshooting and tweaks

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

Optional parameters

You can set parameters like timeout and ghost systemwide for all AutoFS media in /etc/conf.d/autofs:

  • Open the /etc/conf.d/autofs file and edit the daemonoptions line:

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 Using udev to map multiple entries to a device for instructions on setting up udev rules.

AutoFS permissions

If AutoFS isn't 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:

  • 0644 - /etc/autofs/auto.master
  • 0644 - /etc/autofs/
  • 0644 - /etc/autofs/auto.misc
  • 0755 - /etc/autofs/
  • 0644 - /etc/conf.d/autofs

In general, scripts (like should have executable (chown a+x filename) bits set and lists of mounts shouldn't.

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

External links and resources

Alternatives to AutoFS