Difference between revisions of "Autofs"

From ArchWiki
Jump to: navigation, search
m (Identify multiple devices)
(Alternatives to AutoFS)
(37 intermediate revisions by 23 users not shown)
Line 1: Line 1:
[[Category:Auto-mounting (English)]]
+
[[Category:File systems]]
[[Category:File systems (English)]]
+
[[es:Autofs]]
[[Category:HOWTOs (English)]]
+
[[it:Autofs]]
{{i18n|Autofs}}
+
[[ru:Autofs]]
 +
[[uk:Autofs]]
 
{{Article summary start}}
 
{{Article summary start}}
 
{{Article summary text|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.}}
 
{{Article summary text|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.}}
 
{{Article summary end}}
 
{{Article summary end}}
 
== Introduction ==
 
 
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.
 
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.
  
 
== Installation ==
 
== Installation ==
*Install the {{Package Official|autofs}} package:
+
*Install the {{Pkg|autofs}} package:
 
  # pacman -S autofs
 
  # pacman -S autofs
  
*Load the {{Codeline|autofs4}} module as root:
+
*Load the {{ic|autofs4}} module as root:
 
  # modprobe autofs4
 
  # modprobe autofs4
  
 
== Configuration ==
 
== Configuration ==
AutoFS uses template files for configuration which are located in {{Filename|/etc/autofs}} The main template is called {{Filename|auto.master}}, which can point to one or more other templates for specific media types.
+
AutoFS uses template files for configuration which are located in {{ic|/etc/autofs}} The main template is called {{ic|auto.master}}, which can point to one or more other templates for specific media types.
  
* Open the file {{Filename|/etc/autofs/auto.master}} with your favorite editor, you will see something similar to this:
+
* Open the file {{ic|/etc/autofs/auto.master}} with your favorite editor, you will see something similar to this:
  
{{File|name=/etc/autofs/auto.master|content=
+
{{hc|/etc/autofs/auto.master|2=
/var/autofs/misc /etc/autofs/auto.misc
+
#/media /etc/autofs/auto.media
/var/autofs/net /etc/autofs/auto.net
+
  
 
}}
 
}}
  
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 {{Filename|/var/autofs}}, but you can change this to any other location you prefer. For instance:
+
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 {{ic|/media}}, but you can change this to any other location you prefer. For instance:
  
{{File|name=/etc/autofs/auto.master|content=
+
{{hc|/etc/autofs/auto.master|2=
/media/misc    /etc/autofs/auto.misc    --timeout=5 --ghost
+
/media/misc    /etc/autofs/auto.misc    --timeout=5
/media/net      /etc/autofs/auto.net      --timeout=60 --ghost
+
/media/net      /etc/autofs/auto.net      --timeout=60
  
 
}}
 
}}
 +
{{Note|Make sure there is an empty line on the end of template files (press {{Keypress|ENTER}} after last word). If there is no correct EOF line, the AutoFS daemon won't properly load.}}
  
The optional parameter {{Codeline|timeout}} sets the amount of seconds after which to unmount directories. The parameter {{Codeline|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 optional parameter {{ic|timeout}} sets the amount of seconds after which to unmount directories.
  
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 {{Filename|auto.master}} and restart AutoFS to regain the original contents.
+
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 {{ic|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 {{Keypress|ENTER}} after last word). If there is no correct EOF line, the AutoFS daemon won't properly load.}}
+
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. /var/autofs/net) and create soft links.
  
* Open the file {{Filename|/etc/nsswitch.conf}} and add an entry for automount:
+
# 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.
 +
 
 +
{{hc|/etc/autofs/auto.master|2=
 +
/-    /etc/autofs/auto.template
 +
}}
 +
{{hc|/etc/autofs/auto.template|2=
 +
/path/to/folder    -options :/device/path
 +
/home/user/usbstick  -fstype=auto,async,nodev,nosuid,umask=000  :/dev/sdb1
 +
}}
 +
{{Note|This can cause problems with resources getting locked if the connection to the share is lost. When trying to access the folder, programs will get locked into waiting for a response, and either the connection has to be restored or the process has to be forcibly killed before unmounting is possible. To mitigate this, only use if you will always be connected to the share, and don't use your home folder or other commonly used folders lest your file browser reads ahead into the disconnected folder}}
 +
 
 +
* Open the file {{ic|/etc/nsswitch.conf}} and add an entry for automount:
 
  automount: files
 
  automount: files
  
* When you are done configuring, launch the AutoFS daemon as root:
+
* When you are done configuring your templates (see below), launch the AutoFS daemon as root:
  # /etc/rc.d/autofs start
+
  # systemctl start autofs
 +
 
 +
To start the daemon on boot:
 +
# systemctl enable autofs
  
To start the daemon on boot you can add {{Codeline|autofs}} to the {{Codeline|DAEMONS}} array in {{Filename|/etc/rc.conf}}, and {{Codeline|autofs4}} to the modules array in the same file.
+
And add the {{ic|autofs4}} [[Systemd#Kernel_modules|kernel module]] to {{ic|/etc/modules-load.d/}}
 +
{{hc|/etc/modules-load.d/autofs.conf|
 +
# Load autofs4 at boot
 +
autofs4}}
  
 
Devices are now automatically mounted when they are accessed, they will remain mounted as long as you access them.
 
Devices are now automatically mounted when they are accessed, they will remain mounted as long as you access them.
  
 
=== Removable media ===
 
=== Removable media ===
* Open {{Filename|/etc/autofs/auto.misc}} to add, remove or edit miscellaneous devices. For instance:
+
* Open {{ic|/etc/autofs/auto.misc}} to add, remove or edit miscellaneous devices. For instance:
  
{{File|name=/etc/autofs/auto.misc|content=
+
{{hc|/etc/autofs/auto.misc|<nowiki>
 
#kernel  -ro                                        ftp.kernel.org:/pub/linux
 
#kernel  -ro                                        ftp.kernel.org:/pub/linux
 
#boot    -fstype=ext2                              :/dev/hda1
 
#boot    -fstype=ext2                              :/dev/hda1
Line 61: Line 79:
 
cdrom    -fstype=iso9660,ro                        :/dev/cdrom
 
cdrom    -fstype=iso9660,ro                        :/dev/cdrom
 
#floppy  -fstype=auto                              :/dev/fd0
 
#floppy  -fstype=auto                              :/dev/fd0
}}
+
</nowiki>}}
  
If you have a CD/DVD combo-drive you can change the {{Codeline|cdrom}} line with {{Codeline|-fstype<nowiki>=</nowiki>auto}} to have the media type autodetected.
+
If you have a CD/DVD combo-drive you can change the {{ic|cdrom}} line with {{ic|-fstype<nowiki>=</nowiki>auto}} to have the media type autodetected.
  
 
=== NFS Network mounts ===
 
=== NFS Network mounts ===
  
AutoFS provides a new way of automatically discovering and mounting [[NFS]]-shares on remote servers (the AutoFS network template in {{Filename|/etc/autofs/auto.net}} 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 {{Filename|/etc/autofs/auto.master}} file:
+
AutoFS provides a new way of automatically discovering and mounting [[NFS]]-shares on remote servers (the AutoFS network template in {{ic|/etc/autofs/auto.net}} 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 {{ic|/etc/autofs/auto.master}} file:
  
 
  /net -hosts --timeout=60
 
  /net -hosts --timeout=60
  
Each host name needs to be resolveable, e.g. the name an IP address in <code>/etc/hosts</code> or via [[Wikipedia:Domain_Name_System|DNS]] and please make sure you have at least {{Package Official|nfs-common}} installed and working.
+
'''Each host name needs to be resolveable, e.g. the name an IP address in {{ic|/etc/hosts}} or via [[Wikipedia:Domain_Name_System|DNS]] and please make sure you have at least {{Pkg|nfs-common}} 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:
 
For instance, if you have a remote server ''fileserver'' with an NFS share named ''/home/share'', you can just access the share by typing:
Line 77: Line 95:
 
  # cd /net/fileserver/home/share
 
  # 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 {{Filename|/etc/conf.d/autofs}} in order to start the AutoFS daemon.}}
+
{{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 {{ic|/etc/conf.d/autofs}} in order to start the AutoFS daemon.}}
  
The {{Codeline|-hosts}} option uses a similar mechanism as the {{Codeline|showmount}} command to detect remote shares. You can see the exported shares by typing:
+
The {{ic|-hosts}} option uses a similar mechanism as the {{ic|showmount}} command to detect remote shares. You can see the exported shares by typing:
  
 
  # showmount <servername> -e  
 
  # showmount <servername> -e  
Line 89: Line 107:
 
The Arch package does not provide any [[Samba]] or CIFS templates/scripts (23.07.2009), but the following should work for single shares:
 
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 {{Filename|/etc/autofs/auto.master}}
+
add the following to {{ic|/etc/autofs/auto.master}}
 
  /media/[my_server] /etc/autofs/auto.[my_server]
 
  /media/[my_server] /etc/autofs/auto.[my_server]
and then create a file <code>/etc/autofs/auto.[my_server]</code>
+
and then create a file {{ic|/etc/autofs/auto.[my_server]}}
  [my_share] -fstype=cifs,[other_options] ://[my_server_ip]/[my_share]
+
[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 other_options section
 +
  [any_name] -fstype=cifs,username=[username],password=[password],[other_options] ://[remote_server]/[remote_share_name]
 +
 
 +
{{Note|Escape &#36;, and other characters, with a backslash when neccessary.}}
  
 
=== FTP and SSH (with Fuse) ===
 
=== FTP and SSH (with Fuse) ===
Line 99: Line 122:
  
 
==== Remote FTP ====
 
==== Remote FTP ====
First, install the {{Package Official|curlftpfs}} package from the Community repository:
+
First, install the {{Pkg|curlftpfs}} package from the Community repository:
  
 
  # pacman -S curlftpfs
 
  # pacman -S curlftpfs
  
Load the {{Codeline|fuse}} module:
+
Load the {{ic|fuse}} module:
  
 
  # modprobe fuse
 
  # modprobe fuse
  
Add fuse to the {{Codeline|MODULES}} array in {{Filename|/etc/rc.conf}} to load it on each system boot.
+
Add fuse to the {{ic|MODULES}} array in {{ic|/etc/rc.conf}} to load it on each system boot.
  
Next, add a new entry for FTP servers in {{Filename|/etc/autofs/auto.master}}:
+
Next, add a new entry for FTP servers in {{ic|/etc/autofs/auto.master}}:
  
  /media/ftp        /etc/autofs/auto.ftp    --timeout=60 --ghost
+
  /media/ftp        /etc/autofs/auto.ftp    --timeout=60
  
Create the file {{Filename|/etc/autofs/auto.ftp}} and add a server using the {{Codeline|ftp://myuser:mypassword@host:port/path}} format:
+
Create the file {{ic|/etc/autofs/auto.ftp}} and add a server using the {{ic|ftp://myuser:mypassword@host:port/path}} format:
  
 
  servername -fstype=curl,rw,allow_other,nodev,nonempty,noatime    :ftp\://myuser\:mypassword\@remoteserver
 
  servername -fstype=curl,rw,allow_other,nodev,nonempty,noatime    :ftp\://myuser\:mypassword\@remoteserver
  
{{Note| Your passwords are plainly visible for anyone that can run {{Codeline|df}} (only for mounted servers) or view the file {{Filename|/etc/autofs/auto.ftp}}.}}
+
{{Note| Your passwords are plainly visible for anyone that can run {{ic|df}} (only for mounted servers) or view the file {{ic|/etc/autofs/auto.ftp}}.}}
If you want slightly more security you can create the file {{Filename|~root/.netrc}} and add the passwords there.  
+
If you want slightly more security you can create the file {{ic|~root/.netrc}} and add the passwords there.  
Passwords are still plain text, but you can have mode 600, and {{Codeline|df}} command will not show them (mounted or not).
+
Passwords are still plain text, but you can have mode 600, and {{ic|df}} 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:
 
This method is also less sensitive to special characters (that else must be escaped) in the passwords. The format is:
  
Line 126: Line 149:
 
  password mypassword
 
  password mypassword
  
The line in {{Filename|/etc/autofs/auto.ftp}} looks like this without user and password:
+
The line in {{ic|/etc/autofs/auto.ftp}} looks like this without user and password:
  
 
  servername -fstype=curl,allow_other    :ftp\://remoteserver
 
  servername -fstype=curl,allow_other    :ftp\://remoteserver
  
Create the file {{Filename|/sbin/mount.curl}} with this code:
+
Create the file {{ic|/sbin/mount.curl}} with this code:
  
{{File|name=/sbin/mount.curl|content=
+
{{hc|/sbin/mount.curl|<nowiki>
 
  #! /bin/sh
 
  #! /bin/sh
  curlftpfs $1 $2 -o $4,disable_eprt
+
  curlftpfs $1 $2 -o $5,disable_eprt
}}
+
</nowiki>}}
  
Create the file {{Filename|/sbin/umount.curl}} with this code:
+
Create the file {{ic|/sbin/umount.curl}} with this code:
  
{{File|name=/sbin/umount.curl|content=
+
{{hc|/sbin/umount.curl|<nowiki>
 
  #! /bin/sh
 
  #! /bin/sh
 
  fusermount -u $1
 
  fusermount -u $1
}}
+
</nowiki>}}
  
 
Set the permissions for both files:
 
Set the permissions for both files:
Line 149: Line 172:
 
  # chmod 755 /sbin/umount.curl
 
  # chmod 755 /sbin/umount.curl
  
After a restart your new FTP server should be accessible through {{Filename|/media/ftp/servername}}.
+
After a restart your new FTP server should be accessible through {{ic|/media/ftp/servername}}.
  
 
==== Remote SSH ====
 
==== Remote SSH ====
Line 156: Line 179:
 
{{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.}}
 
{{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 {{Package Official|sshfs}} package from the Extra repository:
+
Install the {{Pkg|sshfs}} package from the Extra repository:
  
 
  # pacman -S sshfs
 
  # pacman -S sshfs
  
Load the {{Codeline|fuse}} module:
+
Load the {{ic|fuse}} module:
  
 
  # modprobe fuse
 
  # modprobe fuse
  
Add fuse to the {{Codeline|MODULES}} array in {{Filename|/etc/rc.conf}} to load it on each system boot:
+
Add fuse to the {{ic|MODULES}} array in {{ic|/etc/rc.conf}} to load it on each system boot:
  
 
Install OpenSSH:
 
Install OpenSSH:
Line 180: Line 203:
 
  # sudo ssh -i /home/username/.ssh/id_dsa username@remotehost
 
  # 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 {{Filename|known_hosts}}. Alternatively, hosts can be added to {{Filename|/etc/ssh/ssh_known_hosts}}.}}
+
{{Note|The above command is needed to add the remote server to the root's list of {{ic|known_hosts}}. Alternatively, hosts can be added to {{ic|/etc/ssh/ssh_known_hosts}}.}}
  
Create a new entry for SSH servers in {{Filename|/etc/autofs/auto.master}}:
+
Create a new entry for SSH servers in {{ic|/etc/autofs/auto.master}}:
  /media/ssh /etc/autofs/auto.ssh --timeout=60 --ghost
+
  /media/ssh /etc/autofs/auto.ssh --timeout=60
  
Create the file {{Filename|/etc/autofs/auto.ssh}} and add an SSH server:
+
Create the file {{ic|/etc/autofs/auto.ssh}} and add an SSH server:
{{File|name=/etch/autofs/auto.ssh|content=
+
{{hc|/etc/autofs/auto.ssh|2=
 
  servername    -fstype=fuse,rw,allow_other,IdentityFile=/home/username/.ssh/id_dsa :sshfs\#username@host\:/
 
  servername    -fstype=fuse,rw,allow_other,IdentityFile=/home/username/.ssh/id_dsa :sshfs\#username@host\:/
 
}}
 
}}
  
After a restart your SSH server should be accessible through {{Filename|/media/ssh/servername}}.
+
After a restart your SSH server should be accessible through {{ic|/media/ssh/servername}}.
 +
 
 +
== MTP ==
 +
Media Transfer Protocol ([[MTP]]) is used in some Android devices.
 +
 
 +
Install the {{Pkg|mtpfs}} package from the Community repository:
 +
 
 +
# pacman -S mtpfs
 +
 
 +
Create a new entry for MTP Device in {{ic|/etc/autofs/auto.misc}}:
 +
android -fstype=fuse,allow_other,umask=000    :mtpfs
  
 
== Troubleshooting and tweaks  ==
 
== Troubleshooting and tweaks  ==
Line 197: Line 230:
 
=== Using NIS ===
 
=== Using NIS ===
  
Version 5.0.5 of AutoFS has more advanced support for [[NIS]]. To use AutoFS together with NIS, add {{Codeline|yp:}} in front of the template names in {{Filename|/etc/autofs/auto.master}}:
+
Version 5.0.5 of AutoFS has more advanced support for [[NIS]]. To use AutoFS together with NIS, add {{ic|yp:}} in front of the template names in {{ic|/etc/autofs/auto.master}}:
  
 
  /home  yp:auto_home    --timeout=60  
 
  /home  yp:auto_home    --timeout=60  
Line 203: Line 236:
 
  +auto.master
 
  +auto.master
  
On earlier versions of NIS (before 5.0.4), you should add {{Codeline|nis}} to {{Filename|/etc/nsswitch.conf}}:
+
On earlier versions of NIS (before 5.0.4), you should add {{ic|nis}} to {{ic|/etc/nsswitch.conf}}:
 
  automount: files nis
 
  automount: files nis
  
 
=== Optional parameters ===
 
=== Optional parameters ===
You can set parameters like {{Codeline|timeout}} systemwide for all AutoFS media in {{Filename|/etc/conf.d/autofs}}:
+
You can set parameters like {{ic|timeout}} systemwide for all AutoFS media in {{ic|/etc/conf.d/autofs}}:
  
* Open the {{Filename|/etc/conf.d/autofs}} file and edit the {{Codeline|daemonoptions}} line:
+
* Open the {{ic|/etc/conf.d/autofs}} file and edit the {{ic|daemonoptions}} line:
 
  daemonoptions='--timeout=5'
 
  daemonoptions='--timeout=5'
  
* To enable logging (default is no logging at all), add {{Codeline|--verbose}} to the {{Codeline|daemonoptions}} line in {{Filename|/etc/conf.d/autofs}} e.g.:
+
* To enable logging (default is no logging at all), add {{ic|--verbose}} to the {{ic|daemonoptions}} line in {{ic|/etc/conf.d/autofs}} e.g.:
 
  daemonoptions='--verbose --timeout=5'
 
  daemonoptions='--verbose --timeout=5'
  
After restarting the {{Codeline|autofs}} daemon, verbose output is visible in {{Filename|/var/log/daemon.log}}.
+
After restarting the {{ic|autofs}} daemon, verbose output is visible in {{ic|/var/log/daemon.log}}.
  
 
=== Identify multiple devices ===
 
=== 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.
+
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 ===
 
=== AutoFS permissions ===
Line 228: Line 261:
 
*0644 - /etc/conf.d/autofs
 
*0644 - /etc/conf.d/autofs
  
In general, scripts (like previous auto.net) should have executable (chown a+x filename) bits set and lists of mounts shouldn't.
+
In general, scripts (like previous {{ic|auto.net}}) should have executable ({{ic|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:
+
If you are getting errors in {{ic|/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]: lookup(program): lookup for petr failed
 
  May  7 19:44:16 peterix automount[15218]: failed to mount /media/cifs/petr
 
  May  7 19:44:16 peterix automount[15218]: failed to mount /media/cifs/petr
  
== External links and resources ==
+
==See also==
*The original information on this page is based on this topic: http://bbs.archlinux.org/viewtopic.php?t=7630, with additional information found on this page: http://libranet.com/support/2.8/0381
+
* AutoFS configuration cookbook: http://www.autofs.org/
 +
* An Ubuntu-based walk though of AutoFS with some useful info: http://blogging.dragon.org.uk/index.php/howtos/howto-setup-and-configure-autofs
 
* FTP and SFTP usage with AutoFS is based on this Gentoo Wiki article: http://en.gentoo-wiki.com/wiki/Mounting_SFTP_and_FTP_shares
 
* FTP and SFTP usage with AutoFS is based on this Gentoo Wiki article: http://en.gentoo-wiki.com/wiki/Mounting_SFTP_and_FTP_shares
 
* More information on SSH can be found on the [[SSH]] and [[Using_SSH_Keys|Using SSH Keys]] pages of this wiki.
 
* More information on SSH can be found on the [[SSH]] and [[Using_SSH_Keys|Using SSH Keys]] pages of this wiki.
Line 242: Line 276:
  
 
== Alternatives to AutoFS ==
 
== Alternatives to AutoFS ==
*[[Thunar#Thunar_Volume_Manager|Thunar Volume Manager]] is an automount system for users of the [[Thunar]] file manager.
+
* [[systemd]] can automount filesystems upon demand; see [[Systemd#Automount|here]] for the description and the article on [[Sshfs#On_demand for an example|sshfs]] for an example.
* Pcmanfm-fuse is a lightweight file manager with built-in support for accessing remote shares: http://aur.archlinux.org/packages.php?ID=22992
+
* [[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: https://aur.archlinux.org/packages.php?ID=22992
 +
* [[udiskie]] is a minimalistic automatic disk mounting service using udisks

Revision as of 14:51, 14 March 2013

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.

Installation

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

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 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.

The optional parameter timeout sets the amount of seconds after which to unmount directories.

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. /var/autofs/net) 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.

/etc/autofs/auto.master
/-     /etc/autofs/auto.template
/etc/autofs/auto.template
/path/to/folder     -options :/device/path
/home/user/usbstick  -fstype=auto,async,nodev,nosuid,umask=000  :/dev/sdb1
Note: This can cause problems with resources getting locked if the connection to the share is lost. When trying to access the folder, programs will get locked into waiting for a response, and either the connection has to be restored or the process has to be forcibly killed before unmounting is possible. To mitigate this, only use if you will always be connected to the share, and don't use your home folder or other commonly used folders lest your file browser reads ahead into the disconnected 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:
# systemctl start autofs

To start the daemon on boot:

# systemctl enable autofs

And add the autofs4 kernel module to /etc/modules-load.d/

/etc/modules-load.d/autofs.conf
# Load autofs4 at boot
autofs4

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

Removable media

  • Open /etc/autofs/auto.misc to add, remove or edit miscellaneous devices. For instance:
/etc/autofs/auto.misc
#kernel   -ro                                        ftp.kernel.org:/pub/linux
#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

AutoFS provides a new way of automatically discovering and mounting NFS-shares on remote servers (the AutoFS network template in /etc/autofs/auto.net 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 /etc/autofs/auto.master 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 nfs-common 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 /etc/conf.d/autofs in order to start the AutoFS daemon.

The -hosts option uses a similar mechanism as the showmount 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.

Samba

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]

[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 other_options 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 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 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

Create the file /etc/autofs/auto.ftp and add a server using the ftp://myuser:mypassword@host:port/path 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 df (only for mounted servers) or view the file /etc/autofs/auto.ftp.

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 df 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 /etc/autofs/auto.ftp looks like this without user and password:

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

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

/sbin/mount.curl
 #! /bin/sh
 curlftpfs $1 $2 -o $5,disable_eprt

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

/sbin/umount.curl
 #! /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 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 known_hosts. Alternatively, hosts can be added to /etc/ssh/ssh_known_hosts.

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

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

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

/etc/autofs/auto.ssh
servername     -fstype=fuse,rw,allow_other,IdentityFile=/home/username/.ssh/id_dsa :sshfs\#username@host\:/

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

MTP

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

Install the mtpfs package from the Community repository:

# pacman -S mtpfs

Create a new entry for MTP Device in /etc/autofs/auto.misc:

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 yp: 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 nis to /etc/nsswitch.conf:

automount: files nis

Optional parameters

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

  • Open the /etc/conf.d/autofs file and edit the daemonoptions line:
daemonoptions='--timeout=5'
  • To enable logging (default is no logging at all), add --verbose to the daemonoptions line in /etc/conf.d/autofs e.g.:
daemonoptions='--verbose --timeout=5'

After restarting the autofs daemon, verbose output is visible in /var/log/daemon.log.

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 auto.net) 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

See also

Alternatives to AutoFS