Difference between revisions of "Autofs"

From ArchWiki
Jump to: navigation, search
m (Bot: Removing from Category:HOWTOs (English))
Line 244: Line 244:
*[[Thunar#Thunar_Volume_Manager|Thunar Volume Manager]] is an automount system for users of the [[Thunar]] file manager.
*[[Thunar#Thunar_Volume_Manager|Thunar Volume Manager]] is an automount system for users of the [[Thunar]] file manager.
* Pcmanfm-fuse is a lightweight file manager with built-in support for accessing remote shares: http://aur.archlinux.org/packages.php?ID=22992
* Pcmanfm-fuse is a lightweight file manager with built-in support for accessing remote shares: http://aur.archlinux.org/packages.php?ID=22992
* [[udiskie]] is a minimalistic automatic disk mounting service using udisks

Revision as of 19:07, 21 August 2011

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.

Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어

External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

Template:Article summary start Template:Article summary text Template:Article summary 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.


# pacman -S autofs
# modprobe autofs4


AutoFS uses template files for configuration which are located in Template:Filename The main template is called Template:Filename, which can point to one or more other templates for specific media types.

  • Open the file Template:Filename with your favorite editor, you will see something similar to this:


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 Template:Filename, but you can change this to any other location you prefer. For instance:


The optional parameter Template:Codeline sets the amount of seconds after which to unmount directories. The parameter Template:Codeline 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 Template:Filename and restart AutoFS to regain the original contents.

Note: Make sure there is an empty line on the end of template files (press Template:Keypress after last word). If there is no correct EOF line, the AutoFS daemon won't properly load.
automount: files
  • When you are done configuring, launch the AutoFS daemon as root:
# rc.d start autofs

To start the daemon on boot you can add Template:Codeline to the Template:Codeline array in Template:Filename, and Template:Codeline to the modules array in the same file.

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

Removable media


If you have a CD/DVD combo-drive you can change the Template:Codeline line with Template:Codeline to have the media type autodetected.

NFS Network mounts

AutoFS provides a new way of automatically discovering and mounting NFS-shares on remote servers (the AutoFS network template in Template:Filename has been removed in autofs5). To enable automagic discovery and mounting of network shares from all accessible servers without any further configuration, you'll need to add the following to the Template:Filename file:

/net -hosts --timeout=60

Each host name needs to be resolveable, e.g. the name an IP address in /etc/hosts or via DNS and please make sure you have at least Template:Package Official installed and working.

For instance, if you have a remote server fileserver with an NFS share named /home/share, you can just access the share by typing:

# cd /net/fileserver/home/share
Note: Please note that ghosting, i.e. automatically creating directory placeholders before mounting shares is enabled by default, although AutoFS installation notes claim to remove that option from Template:Filename in order to start the AutoFS daemon.

The Template:Codeline option uses a similar mechanism as the Template:Codeline command to detect remote shares. You can see the exported shares 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 Template:Filename

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

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

[any_name] -fstype=cifs,[other_options] [server_ip_or_hostname]:/[remote_share_name]
Note: Escape $, and other characters, with a backslash when neccessary.

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 Template:Package Official package from the Community repository:

# pacman -S curlftpfs

Load the Template:Codeline module:

# modprobe fuse

Add fuse to the Template:Codeline array in Template:Filename to load it on each system boot.

Next, add a new entry for FTP servers in Template:Filename:

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

Create the file Template:Filename and add a server using the Template:Codeline format:

servername -fstype=curl,rw,allow_other,nodev,nonempty,noatime    :ftp\://myuser\:mypassword\@remoteserver
Note: Your passwords are plainly visible for anyone that can run Template:Codeline (only for mounted servers) or view the file Template:Filename.

If you want slightly more security you can create the file Template:Filename and add the passwords there. Passwords are still plain text, but you can have mode 600, and Template:Codeline 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 Template:Filename looks like this without user and password:

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

Create the file Template:Filename with this code:


Create the file Template:Filename 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 Template:Filename.

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 Template:Package Official package from the Extra repository:

# pacman -S sshfs

Load the Template:Codeline module:

# modprobe fuse

Add fuse to the Template:Codeline array in Template:Filename 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 Template:Keypress. 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 /home/username/.ssh/id_dsa.pub username@remotehost

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

# sudo ssh -i /home/username/.ssh/id_dsa username@remotehost
Note: The above command is needed to add the remote server to the root's list of Template:Filename. Alternatively, hosts can be added to Template:Filename.

Create a new entry for SSH servers in Template:Filename:

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

Create the file Template:Filename and add an SSH server: Template:File

After a restart your SSH server should be accessible through Template:Filename.

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 Template:Codeline in front of the template names in Template:Filename:

/home   yp:auto_home    --timeout=60 
/sbtn   yp:auto_sbtn    --timeout=60

On earlier versions of NIS (before 5.0.4), you should add Template:Codeline to Template:Filename:

automount: files nis

Optional parameters

You can set parameters like Template:Codeline systemwide for all AutoFS media in Template:Filename:

daemonoptions='--verbose --timeout=5'

After restarting the Template:Codeline daemon, verbose output is visible in Template:Filename.

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 Map Custom Device Entries with udev 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/auto.media
  • 0644 - /etc/autofs/auto.misc
  • 0644 - /etc/conf.d/autofs

In general, scripts (like previous Template:Filename) should have executable (Template:Codeline) bits set and lists of mounts shouldn't.

If you are getting errors in Template:Filename 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