AutoFS: Mounting and Unmounting Shares
Introduction
You already installed Linux on your networked desktop PC and now you want to work with files stored on some other PCs in your network. This is where autofs comes into play. This tutorial shows how to configure autofs to use CIFS to access Windows or Samba shares from Linux Desktop PCs. It also includes a tailored configuration file.
If autofs Version 4.0 or newer is already installed, you should find these files:
on your system. Otherwise start the package manager of your distribution (e.g. YaST on SuSE, synaptic on Debian or Ubuntu, ...) and install it. When you are at it, also install the Samba client package (look for smbclient), because we will also need this.
Installation
Just do:
Configuration
NFS
Installation
For NFS, it's not very hard, just be sure it works fine when you mount it manually. You also need to install portmap:
Configuration
Now edit for example the auto.master file, and add a nfs file line (/etc/auto.master
):
This means it will be mounted in /mnt
and will be automatically unmounted after 10 min. Now edit your new file (/etc/auto.nfs
):
With some virtualized systems like OpenVZ, you'll need to add 'nolock' option in addition to fstype options (/etc/auto.nfs
):
CIFS
Installation
If autofs is already installed, it is probably still not configured and not working. Assuming your Linux Distribution contains a Linux 2.6.x kernel I recommend to use the common internet file system (cifs) module to access files on the network. You also need smbfs to be installed:
Configuration
Please store the following file as (/etc/auto.master
):
on your computer. You need root (or sudo) to have the permissions to do this (/etc/auto.cifs
):
This file must be executable to work (chmod 755)!
Just create a /etc/auto.cred file where credentials will be added. Then add those 2 lines (/etc/auto.cred
):
Change the permissions:
Restart service:
That's all.
SSH
Installation
First we need to install sshfs:
Configuration
Key exchange
You first need to do key exchange from the root user on remote host.
Autofs configuration
Now edit the master file and add this line (/etc/auto.master
):c/
Now add this and adapt it for your needs (/etc/auto.sshfs
):
- myfolder: folder will be accessible in /mnt/remote_server/myfolder
- login: type your ssh login
- /the/share: set the remote share
Do not forget to create the folder on your client machine.
Now reload autofs:
Now access to /mnt/remote_server/myfolder it will be automatically mounted.
FTP
You'll need to install this package:
Then add this line in /etc/auto.master:
Now we need to create this file and add a line like that (replace with your information):
Create a mountpoint per home user
To create a home mountpoint per connected user, you have to configure (NFS for example) like this:
&: corresponds to each user
Verify
Use the command:
or
to check if it works. If not, consult the system logfiles (usually /var/log/messages or /var/log/syslog) for messages.
FAQ
My NFS connection is very slow
I can see this kind of things in the syslogs:
You just need to install the portmap package :-)
I encounter NFS delay problem
If you have this kind of problem:
Grow your auto.nfs file, option timeo:
My CIFS doesn't want to mount
You may have a problem while automounting a cifs share getting these errors in the logs:
As recommended in this documentation, auto.cifs needs execute rights. But depending on the version of autofs you use, you may need to remove those rights:
Then restart autofs daemon.
Why autofs volumes are hidden when not mounted?
It is possible to show wished volumes that are not mounted, this is easier to know which ones are available. To do it, simply add '--ghost' on a line on auto.master. Example: