https://wiki.archlinux.org/api.php?action=feedcontributions&user=Herr-biber&feedformat=atomArchWiki - User contributions [en]2024-03-29T04:33:41ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Autofs&diff=281440Autofs2013-11-04T20:22:15Z<p>Herr-biber: Change wikipedia link to proper FUSE site.</p>
<hr />
<div>[[Category:File systems]]<br />
[[es:Autofs]]<br />
[[it:Autofs]]<br />
[[ru:Autofs]]<br />
[[uk:Autofs]]<br />
{{Article summary start}}<br />
{{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.}}<br />
{{Article summary end}}<br />
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.<br />
<br />
== Installation ==<br />
<br />
[[pacman|Install]] the {{Pkg|autofs}} package from the [[official repositories]].<br />
<br />
{{Note|You no longer need to load {{ic|autofs4}} module.}}<br />
<br />
== Configuration ==<br />
<br />
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.<br />
<br />
* Open the file {{ic|/etc/autofs/auto.master}} with your favorite editor, you will see something similar to this:<br />
<br />
{{hc|/etc/autofs/auto.master|2=<br />
#/media /etc/autofs/auto.media<br />
<br />
}}<br />
<br />
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:<br />
<br />
{{hc|/etc/autofs/auto.master|2=<br />
/media/misc /etc/autofs/auto.misc --timeout=5<br />
/media/net /etc/autofs/auto.net --timeout=60<br />
<br />
}}<br />
{{Note|Make sure there is an empty line on the end of template files (press {{ic|ENTER}} after last word). If there is no correct EOF (end of file) line, the AutoFS daemon won't properly load.}}<br />
<br />
The optional parameter {{ic|timeout}} sets the amount of seconds after which to unmount directories.<br />
<br />
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.<br />
<br />
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.<br />
<br />
# ln -s /var/autofs/net/share_name /media/share_name<br />
<br />
Alternatively, you can have autofs mount your media to a specific folder, rather than inside a common folder.<br />
<br />
{{hc|/etc/autofs/auto.master|2=<br />
/- /etc/autofs/auto.template<br />
}}<br />
{{hc|/etc/autofs/auto.template|2=<br />
/path/to/folder -options :/device/path<br />
/home/user/usbstick -fstype=auto,async,nodev,nosuid,umask=000 :/dev/sdb1<br />
}}<br />
{{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}}<br />
<br />
* Open the file {{ic|/etc/nsswitch.conf}} and add an entry for automount:<br />
automount: files<br />
<br />
* When you are done configuring your templates (see below), launch the AutoFS daemon as root:<br />
# systemctl start autofs<br />
<br />
To start the daemon on boot:<br />
# systemctl enable autofs<br />
<br />
Devices are now automatically mounted when they are accessed, they will remain mounted as long as you access them.<br />
<br />
=== Removable media ===<br />
<br />
* Open {{ic|/etc/autofs/auto.misc}} to add, remove or edit miscellaneous devices. For instance:<br />
<br />
{{hc|/etc/autofs/auto.misc|<nowiki><br />
#kernel -ro ftp.kernel.org:/pub/linux<br />
#boot -fstype=ext2 :/dev/hda1<br />
usbstick -fstype=auto,async,nodev,nosuid,umask=000 :/dev/sdb1<br />
cdrom -fstype=iso9660,ro :/dev/cdrom<br />
#floppy -fstype=auto :/dev/fd0<br />
</nowiki>}}<br />
<br />
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.<br />
<br />
=== NFS network mounts ===<br />
<br />
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:<br />
<br />
/net -hosts --timeout=60<br />
<br />
'''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. You also have to enable RPC (systemctl start|enable rpcbind) to browse shared Folders.'''<br />
<br />
For instance, if you have a remote server ''fileserver'' with an NFS share named ''/home/share'', you can just access the share by typing:<br />
<br />
# cd /net/fileserver/home/share<br />
<br />
{{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.}}<br />
<br />
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:<br />
<br />
# showmount <servername> -e <br />
<br />
Replacing ''<servername>'' with the name of your own server.<br />
<br />
=== Samba ===<br />
<br />
The Arch package does not provide any [[Samba]] or CIFS templates/scripts (23.07.2009), but the following should work for single shares:<br />
<br />
add the following to {{ic|/etc/autofs/auto.master}}<br />
/media/[my_server] /etc/autofs/auto.[my_server]<br />
and then create a file {{ic|/etc/autofs/auto.[my_server]}}<br />
[any_name] -fstype=cifs,[other_options] ://[remote_server]/[remote_share_name]<br />
<br />
You can specify a user name and password to use with the share in the other_options section<br />
[any_name] -fstype=cifs,username=[username],password=[password],[other_options] ://[remote_server]/[remote_share_name]<br />
<br />
{{Note|Escape &#36;, and other characters, with a backslash when neccessary.}}<br />
<br />
=== FTP and SSH (with FUSE) ===<br />
<br />
Remote FTP and [[SSH]] servers can be accessed seamlessly with AutoFS using [[Wikipedia:Filesystem in Userspace|FUSE]], a virtual file system layer. <br />
<br />
==== Remote FTP ====<br />
<br />
First, install the {{Pkg|curlftpfs}} package.<br />
Load the '''fuse''' module:<br />
<br />
# modprobe fuse<br />
<br />
Create a {{ic|/etc/modules-load.d/fuse.conf}} file containg {{ic|fuse}} to load it on each system boot.<br />
<br />
Next, add a new entry for FTP servers in {{ic|/etc/autofs/auto.master}}:<br />
<br />
/media/ftp /etc/autofs/auto.ftp --timeout=60<br />
<br />
Create the file {{ic|/etc/autofs/auto.ftp}} and add a server using the {{ic|ftp://myuser:mypassword@host:port/path}} format:<br />
<br />
servername -fstype=curl,rw,allow_other,nodev,nonempty,noatime :ftp\://myuser\:mypassword\@remoteserver<br />
<br />
{{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}}.}}<br />
If you want slightly more security you can create the file {{ic|~root/.netrc}} and add the passwords there. <br />
Passwords are still plain text, but you can have mode 600, and {{ic|df}} command will not show them (mounted or not).<br />
This method is also less sensitive to special characters (that else must be escaped) in the passwords. The format is:<br />
<br />
machine remoteserver <br />
login myuser<br />
password mypassword<br />
<br />
The line in {{ic|/etc/autofs/auto.ftp}} looks like this without user and password:<br />
<br />
servername -fstype=curl,allow_other :ftp\://remoteserver<br />
<br />
Create the file {{ic|/sbin/mount.curl}} with this code:<br />
<br />
{{hc|/sbin/mount.curl|<nowiki><br />
#! /bin/sh<br />
curlftpfs $1 $2 -o $5,disable_eprt<br />
</nowiki>}}<br />
<br />
Create the file {{ic|/sbin/umount.curl}} with this code:<br />
<br />
{{hc|/sbin/umount.curl|<nowiki><br />
#! /bin/sh<br />
fusermount -u $1<br />
</nowiki>}}<br />
<br />
Set the permissions for both files:<br />
<br />
# chmod 755 /sbin/mount.curl<br />
# chmod 755 /sbin/umount.curl<br />
<br />
After a restart your new FTP server should be accessible through {{ic|/media/ftp/servername}}.<br />
<br />
==== Remote SSH ====<br />
<br />
These are basic instructions to access a remote filesystem over [[SSH]] with AutoFS. <br />
<br />
{{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.}}<br />
<br />
Install the {{Pkg|sshfs}} package.<br />
<br />
Load the {{ic|fuse}} module:<br />
<br />
# modprobe fuse<br />
<br />
Create a {{ic|/etc/modules-load.d/fuse.conf}} file containg {{ic|fuse}} to load it on each system boot if you have not one yet.<br />
<br />
Install {{Pkg|openssh}}.<br />
<br />
Generate an [[Using SSH Keys|SSH keypair]]:<br />
# ssh-keygen -t dsa<br />
<br />
When the generator ask for a passphrase, just press {{ic|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. <br />
<br />
Next, copy the public key to the remote SSH server:<br />
# ssh-copy-id -i /home/username/.ssh/id_dsa.pub username@remotehost<br />
<br />
See that you can login to the remote server without entering a password:<br />
# sudo ssh -i /home/username/.ssh/id_dsa username@remotehost<br />
<br />
{{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}}.}}<br />
<br />
Create a new entry for SSH servers in {{ic|/etc/autofs/auto.master}}:<br />
/media/ssh /etc/autofs/auto.ssh --timeout=60<br />
<br />
Create the file {{ic|/etc/autofs/auto.ssh}} and add an SSH server:<br />
{{hc|/etc/autofs/auto.ssh|2=<br />
servername -fstype=fuse,rw,allow_other,IdentityFile=/home/username/.ssh/id_dsa :sshfs\#username@host\:/<br />
}}<br />
<br />
After a restart your SSH server should be accessible through {{ic|/media/ssh/servername}}.<br />
<br />
== MTP ==<br />
<br />
Media Transfer Protocol ([[MTP]]) is used in some Android devices.<br />
<br />
Install the {{Pkg|mtpfs}} package.<br />
<br />
Create a new entry for MTP Device in {{ic|/etc/autofs/auto.misc}}:<br />
android -fstype=fuse,allow_other,umask=000 :mtpfs<br />
<br />
== Troubleshooting and tweaks ==<br />
<br />
This section contains a few solutions for common issues with AutoFS.<br />
<br />
=== Using NIS ===<br />
<br />
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}}:<br />
<br />
/home yp:auto_home --timeout=60 <br />
/sbtn yp:auto_sbtn --timeout=60<br />
+auto.master<br />
<br />
On earlier versions of NIS (before 5.0.4), you should add {{ic|nis}} to {{ic|/etc/nsswitch.conf}}:<br />
automount: files nis<br />
<br />
=== Optional parameters ===<br />
<br />
You can set parameters like {{ic|timeout}} systemwide for all AutoFS media in {{ic|/etc/conf.d/autofs}}:<br />
<br />
* Open the {{ic|/etc/conf.d/autofs}} file and edit the {{ic|daemonoptions}} line:<br />
daemonoptions='--timeout=5'<br />
<br />
* 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.:<br />
daemonoptions='--verbose --timeout=5'<br />
<br />
After restarting the {{ic|autofs}} daemon, verbose output is visible in {{ic|/var/log/daemon.log}}.<br />
<br />
=== Identify multiple devices ===<br />
<br />
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.<br />
<br />
=== AutoFS permissions ===<br />
<br />
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:<br />
<br />
*0644 - /etc/autofs/auto.master<br />
*0644 - /etc/autofs/auto.media<br />
*0644 - /etc/autofs/auto.misc<br />
*0644 - /etc/conf.d/autofs<br />
<br />
In general, scripts (like previous {{ic|auto.net}}) should have executable ({{ic|chown a+x filename}}) bits set and lists of mounts shouldn't.<br />
<br />
If you are getting errors in {{ic|/var/log/daemon.log}} similar to this, you have a permissions problem:<br />
<br />
May 7 19:44:16 peterix automount[15218]: lookup(program): lookup for petr failed<br />
May 7 19:44:16 peterix automount[15218]: failed to mount /media/cifs/petr<br />
<br />
=== fusermount problems ===<br />
With certain versions of util-linux, you may not be able to unmount a fuse file system drive mounted by autofs, even if you use the "user=" option. See the discussion here:<br />
http://fuse.996288.n3.nabble.com/Cannot-umount-as-non-root-user-anymore-tp689p697.html<br />
<br />
== Alternatives to AutoFS ==<br />
<br />
* [[Systemd]] can automount filesystems upon demand; see [[Systemd#Automount|here]] for the description and the article on [[Sshfs#On_demand|sshfs]] for an example.<br />
* [[Thunar#Thunar_Volume_Manager|Thunar Volume Manager]] is an automount system for users of the [[Thunar]] file manager.<br />
* Pcmanfm-fuse is a lightweight file manager with built-in support for accessing remote shares: https://aur.archlinux.org/packages.php?ID=22992<br />
* [[udiskie]] is a minimalistic automatic disk mounting service using udisks<br />
<br />
== See also ==<br />
<br />
* AutoFS configuration cookbook: http://www.autofs.org/<br />
* An Ubuntu-based walk though of AutoFS with some useful info: http://blogging.dragon.org.uk/index.php/howtos/howto-setup-and-configure-autofs<br />
* FTP and SFTP usage with AutoFS is based on this Gentoo Wiki article: http://en.gentoo-wiki.com/wiki/Mounting_SFTP_and_FTP_shares<br />
* More information on SSH can be found on the [[SSH]] and [[Using_SSH_Keys|Using SSH Keys]] pages of this wiki.</div>Herr-biber