Previously, I looked at the Amd automounting daemon and how to use it to provide on-demand access to remote NFS shares. Amd is purely a user-space tool, available for Linux and other UNIX operating systems. AutoFS, on the other hand, is partially user-space and partially kernel-space on Linux systems. Unlike Amd, AutoFS comes standard on almost every Linux system.

If it isn't already on your system, install the AutoFS package. Using apt, urpmi, or yum, all the required dependencies will be installed. Next, edit /etc/autofs/auto.master:

# mount point config file options
/net /etc/autofs/autofs.net --timeout=30 --ghost
/home /etc/autofs/autofs.home --timeout=60 --ghost

This edit defines two master mount points where all automounted directories will live. In this case, both /net and /home are top-level directories that will contain the automounted directories. They are defined by the /etc/autofs/autofs.net and /etc/autofs/autofs.home configuration files, respectively. Finally, the /net tree has an inactivity timeout of 30 seconds, whereas the /home tree has a timeout of 60 seconds. Both create ghost (empty) directories of the mount points listed in the configuration files. This prevents the directories from being removed when they are unmounted.

Make sure the defined top-level directories exist; you will need to create both the /net and /home directories.

The /etc/autofs/autofs.net configuration might look like the following:

# directory mount options device to mount
remote_nfs -rsize=8192,wsize=8192,soft,timeo=30,rw nfs.host:/srv
remote_smb -fstype=smbfs,credentials=/etc/smb.auth ://win.host/Share

Here, two different types of remote directories are defined. The first is a remote NFS directory, and the second is a remote Samba share. In this case, the first will be mounted as /net/remote_nfs/ and the second as /net/remote_smb/. For the Samba share, credentials are required and are defined in /etc/smb.auth, which would look like:

username=user
password=secret

Make sure this file is mode 0600 and owned by root so the credentials aren't exposed.

Unlike Amd, AutoFS can also be used to automount local devices. You can use it to automount CD-ROM or floppy devices as well. For instance, to automount a floppy, you would use the following definition:

floppy -fstype=auto :/dev/fd0

Another difference from Amd is that with AutoFS, the mount program will not show remotely mounted directories. Instead, you will need to peek at /proc/mounts to see what's mounted:

# cat /proc/mounts | grep autofs

AutoFS is pretty flexible in that you can use it to automount CD-ROMs, remote NFS and Samba shares, even ISO images. Some distributions include "magic" configuration files that will automount any network mounts available on the network without any preconfiguration. Simply start AutoFS, point to one of these configuration files, and start changing to directories (for example, /net/titan if the remote host's name is titan).

Open Sourcery This was published in Open Sourcery, check every Monday for more stories

Related links

Leave a comment

You must read and type the 6 chars within 0..9 and A..F

* indicates mandatory fields.

Log in


Sign up | Forgot your password?

  • Staff Aussies to pay more for Win 7

    If you are looking to make some money in these troubled times, perhaps importing copies of Windows 7 could be for you. Read more »

    -- posted by Staff

  • Staff Firefox: Greens want it, 3.5rc2 not up to par

    This week's roundup looks at the situation surrounding a campaign to change Outlook HTML renderer, a Greens MP wants to install Firefox but is restricted and all the photos from the iPhone 3GS launch. Read more »

    -- posted by Staff

  • Chris Duckett Microsoft misses the Outlook point

    Ask designers which mail program is the bane of their existence, and you'll find that Outlook tops the list. The reason why the most popular email reader is also the most painful is simple: it uses Word to render HTML emails. Read more »

    -- posted by Chris Duckett

What's on?