Automount filesystems with flexible AutoFS tool
Takeaway: Vincent Danen describes the AutoFS automounter and walks you through setup and configuration.
In a previous tip, 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).
Delivered each Tuesday, TechRepublic's free Linux NetNote provides tips, articles, and other resources to help you hone your Linux skills. Automatically sign up today!
Print/View all Posts Comments on this article
SponsoredWhite Papers, Webcasts, and Downloads
- TCP/IP Troubleshooting Global Knowledge
- Eleven Myths about 802.11 Wi-Fi Networks Global Knowledge
- Preparing for and Taking the PMP Certification Exam Global Knowledge
- 2008 IT Salary and Skills Report Global Knowledge
- Vista SP1: What You Need To Know Before You Deploy Global Knowledge
Article Categories
- Security
- Security Solutions, IT Locksmith
- Networking and Communications
- E-mail Administration NetNote, Cisco Routers and Switches
- CIO and IT Management
- Project Management, CIO Issues, Strategies that Scale
- Desktops, Laptops & OS
- Windows 2000 Professional, Microsoft Word, Microsoft Excel, Microsoft Access, Windows XP,
- Data Management
- Oracle, SQL Server
- Servers
- Windows NT, Linux NetNote, Windows Server 2003
- Career Development
- Geek Trivia
- Software/Web Development
- Web Development Zone, Visual Basic, .NET
