This program allows one to automate mounting and unmounting of different types of filesystems, be it a usb drive, samba share or nfs, and for sure others. It is like fstab but on demand.
What you will need
- A kernel with the option "Kernel automounter"
File Systems ---> <*> Kernel automounter version 4 support (also supports v3)
- The program autofs
apt-get install autofs
- Stuff to cope with the filesystems you want to mount
For example: for a USB drive you will need the appropriate kernel modules (mass storage + filesystem support), for a samba share you will need the kernel options AND the program smbfs.
To configure autofs edit the master file /etc/auto.master, in this file we shall declare which configuration files to use with some options.
Ok, so in /etc/auto.master add a line according to the following example (you can add as many as you need):
/mnt/autofs-user /etc/auto.user --timeout=3 --ghost
Explanation (in order of appearance):
- the root folder where we shall mount things
- the configuration file for these mountings
- some additional options
--timeout : as it sounds, timeout option defines how much time (in seconds) before a resource is unmounted when not in use.
--ghost : this option creates a "ghost" folder of each defined mount point, whether it is mounted or not, as long as autofs is running it will create the folder. If you don't have this option you will need to specify precisely the path to indicate to autofs that it must attempt to mount the filesystem you are trying to access. (reading on might help to understand this)
Now we need to create the root folder for our mounts:
mkdir -p /mnt/autofs-user
It is here that we define the crap we want to mount, in this case some usbdrive:
usb1 -fstype=auto,rw,uid=1000,gid=1000 :/dev/sda1
usb2 -fstype=auto,rw,uid=1000,gid=1000 :/dev/sdb1
It is in /mnt/autofs-user/sda1 that we will mount /dev/sda1 with the same type of options as you would put in fstab.. ..
uid and gid : here we put the uid and gid of the user who is supposed to access this resource, if you don't mount will belong to root and the user won't be able to write to his usbdrive.
now if all is good, restart autofs
Now all you need to do is goto /mnt/autofs-user/, you should see the folders usb1 and usb2 which should be "empty".
By entering /mnt/autofs-user/usb1 (or listing it's contents etc etc.) autofs will mount /dev/sda1 in the folder usb1 as defined in the file /etc/auto.user and /etc/auto.master. To be clear, /etc/auto.master defines the root for mounting things according to a sub configuration file (in this case /etc/auto.user) and /etc/auto.user defines the subfolder only.
And what about not using --ghost
The option --ghost will automatically create the folders
What i do is create a folder from which i want to access the autofs mounts, in my case this is what i do:
ln -s /mnt/autofs-user/usb1 .
ln -s /mnt/autofs-user/usb2 .
This creates some links to inexistent folders Except when sda1 OR sda2 is mounted.
lrwxrwxrwx 1 manu manu 21 2005-08-14 09:53 usb1 -> /mnt/autofs-user/sda1
lrwxrwxrwx 1 manu manu 21 2005-08-14 09:53 usb2 -> /mnt/autofs-user/sdb1
This way when i list the contents of /home/manu/autofs/ autofs will try to mount sda1 and sdb1... the subtle part is what you see as a result of this.
For example, i have a colored bash, if the link points to an existing resource it shows up in yellow for me, if the link points to an inexistent resource it shows up red, this way i know right away what is mounted. Plus with a file navigator such as Konqueror you will see a regular "folder link" if it is mounted or a "?" icon if it is not.
AutoFS and samba and/or NFS
AutoFS is like fstab just that it is on demand, hence you can mount network file systems too.
zik -fstype=smbfs,credentials=/etc/smb.auth.manu,uid=1000,gid=1000 ://192.168.0.100/zik
nfs -rsize=8192,wsize=8192,soft,timeo=14,rw 192.168.0.100:/chemin/nfs
Note for the samba share, the file /etc/smb.auth.manu must existe and be chmod 600 and it must contain samba authentication info, example:
now everything should work fine, the sun should shine brighter than the usual and something good will happen to you in less than two weeks if you forward this article to at least 15 people from your contact list. .. . .: ]