Automount – Making Remote Mounts, Easy!

As a part of the many tasks assigned for my new position of Administering and Managing a new and up-and-coming Linux Virtualized platforms are backups. I’ve have a good chance to see how not to run backups at my last position and it’s given me a lot of insight into the process – stale mounts are one of the many issues to overcome. Mounting a remote file-system on the local machine and maintaining stability is hard enough between two Linux machines – let alone having to mount a remote NTFS Windows File server.

Here comes Automount! I quite literally stumbled on to this while looking to solve another un-related problem (Mounting a remote linux file system with SSHFS). What is automount? It’s a daemon that runs on Linux systems and whenever a user attempts to access an “automount” monitored mount point it will ensure it is mounted (if not already) and when a mount is not in use will unmount it. This takes care of most situations where a stale mount (When the local system thinks it still is mounted, but the remote system is unavailable or has been restarted) – perfect for this application.

This was configured on a CentOS machine and here is how I did it. Make sure you have cifs (or smbfs if you are using an older distro) installed. Install autofs:

yum install autofs

First I needed to make a directory for which to mange my mount.

mkdir /media/auto

Though you can use any existing folder. Once you have done so we’ll need to setup automount to know about the mount point – open /etc/auto.master and add the following to the bottom:

/media/auto /etc/auto.media

Replace /media/auto with the directory and you can call the file which ever you like “auto.windows” “auto.servername” etc.

Next open the file you referenced. In this case: /etc/auto/media and add the following formatted string:

MOUNTNAME -fstype=, :

So for my example I want it mounted to /media/auto/windows1 using cifs and my username: halle password: swordfish and domain: berry on the windows share //10.10.0.2/travolta

windows1  -fstype=cifs,rw,noperm,user=halle,pass=swordfish,domain=berry ://10.10.0.2/travolta

Now in the above example can be customized for all sorts of mount types found in fstab – this is just an example for Linux to remote windows share.

Once you’ve completed that, restart autofs:

/etc/init.d/autofs restart

and navigate to the created folder:

cd /media/auto

If you do an ls you should see nothing. Because the mount is only accessed when needed. If you cd in to the mount name (defined above in the auto.media file) and do an ls you’ll now be on the Windows share.