AutoFS : montage et démontage de partages
1 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 thoses files :
/etc/auto.master /etc/auto.smb
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.
2 Installation
Just do :
apt-get |
apt-get install autofs |
3 Configuration
3.1 NFS
3.1.1 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 :
apt-get |
apt-get install portmap |
3.1.2 Configuration
Now edit for example the auto.master file, and add a nfs file line :
/etc/auto.master |
/mnt /etc/auto.nfs --timeout=600 |
This mean it will be mounted in /mnt and will be automatically umounted after 10 min. Now edit your new file :
/etc/auto.nfs |
* -fstype=nfs,rw 192.168.0.187:/home |
With some virtualized systems like OpenVZ, you'll need to add 'nolock' option in addition of fstype options :
/etc/auto.nfs |
* -fstype=nfs,rw,nolock 192.168.0.187:/home |
3.2 CIFS
3.2.1 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 nee smbfs to be isntalled :
apt-get |
apt-get install smbfs cifs-utils |
3.2.2 Configuration
Please store the following file as
/etc/auto.master |
/mnt /etc/auto.cifs |
on your computer. You need root (or sudo) to have the permissions to do this:
/etc/auto.cifs |
share -fstype=cifs,rw,noperm,credentials=/etc/auto.cred ://server/share |
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 |
username=le_login password=le_password |
change the permissions :
chmod |
chmod 755 /etc/auto.cifs chmod a-x /etc/auto.cifs chmod 600 /etc/auto.cred |
Restart service :
/etc/init.d/autofs restart |
That's all.
3.3 SSH
3.3.1 Installation
First we need to install sshfs :
apt-get |
apt-get install sshfs fuse |
3.3.2 Configuration
3.3.2.1 Key exchange
You first need to do key exchange from the root user on remote host.
3.3.2.2 Autofs configuration
Now edit the master file and add this line :
/etc/auto.master |
/mnt/remote_server /etc/auto.sshfs --timeout=360,--ghost |
Now add this and adapt it for your needs :
/etc/auto.sshfs |
myfolder -fstype=fuse,port=22,rw,allow_other :sshfs\#login@remote_host\:/the/share |
- 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 :
/etc/init.d/autofs reload |
Now access to /mnt/remote_server/myfolder it will be automatically mounted.
3.4 FTP
You'll need to install this package :
aptitude |
aptitude install curlftpfs |
Then add this line in /etc/auto.master :
/etc/auto.master |
/mnt/autofs /etc/auto.ftp --timeout=600 |
Now we need to create this file and add a line like that (replace with your informations) :
/etc/auto.ftp |
backups_ftp -fstype=fuse,allow_other,user=user:password :curlftpfs\server |
3.5 Create a mountpoint per home user
To create a home mountpoint per connected user, you have to configure (NFS for example) like this :
/etc/auto.nfs |
* -fstype=nfs,rw 192.168.0.187:/home/& |
& : correspond to each users
4 Verify
Use the command
ls |
ls -als /cifs/FILESERVERNAME/SHARENAME or mount.cifs //server/share /test -o username=login,password=pass |
to check, if it works. If not, consult the system logfiles (usually /var/log/messages or /var/log/syslog) for messages.
5 FAQ
5.1 My NFS connection is very slow
I can see this kind of of things in the syslogs :
/var/log/syslog |
... Jun 6 16:26:40 debusertest kernel: portmap: server localhost not responding, timed out Jun 6 16:26:40 debusertest kernel: RPC: failed to contact portmap (errno -5). |
You just need to install the portmap package :-)
5.2 I encounter NFS delay problem
If you have this kind of problem :
Jul 8 15:50:39 deb-devtest2 automount[8415]: mount(nfs): mkdir_path /mnt/share/drive failed: No such file or directory Jul 8 15:50:39 deb-devtest2 automount[8415]: failed to mount /mnt/share/drive
Grow your auto.nfs file, option timeo :
/etc/auto.nfs |
drive -fstype=nfs,rw,rsize=8192,wsize=8192,timeo=60,intr server:/700G/share/drive |
5.3 My CIFS doesn't want to mount
You may have a problem while automount a cifs share getting this errors in the logs :
Dec 27 11:36:07 pmavro-laptop automount[27824]: lookup(program): lookup for backups failed Dec 27 11:36:07 pmavro-laptop automount[27824]: failed to mount /mnt/backups/backups
As it's recommanded on this documentation, auto.cifs needs execute rights. But depending of the version of autofs you use, you may need to pull off those rights :
chmod |
chmod a-x /etc/auto.cifs |
Then restart autofs daemon.
It is possible to show wished volumes that are not mounted, this is easier to know which ones are available. Do to do it, simple add '--ghost' on a line on auto.master. Example :
/etc/auto.master |
[...] /mnt/mount1 /etc/auto.sshfs --timeout=720,--ghost /mnt/mount2 /etc/auto.cifs --timeout=720,--ghost |