Sunday, August 19, 2012

The automounter

I had gotten a question on automount the other day, and while the set-up is relatively simple, I thought I might take this weekend to post a quick write up on it.

Once you install autofs, there are two configuration files to pay attention to; these are auto.master, and auto.misc.  (As you will read in the configuration files, auto.misc can be replaced with any file of your choosing, to keep things simple, I'll set up a an automount with the default files).

I'll start by adding a single line to auto.master.

/mnt    /etc/auto.misc

The first field specifies my parent mountpoint, the secondline specifies the configuration file to be used for this mountpoint.  Inside this parent mountpoint /mnt, child directories will be created. Check out the line that's added to the /etc/auto.misc file below.

public    -fstype=nfs    station11.vmnet.local:/public

The first field is the child directory that will be created inside of /mnt (specified above in /etc/auto.master), the second field specifies that this is an NFS mount.  Finally, the third field indicates the source for child mountpoint 'public', which is an NFS server.  If I had placed another line in auto.misc, the first field would be a second directly in /mnt, with two fields describing the type, and location, respectively.

That's it.  Now that I've gone over the ease of the configuration, let me go through a few things to keep in mind.

1. The child mount point will not be visible until you move into that directory.  If I did an 'ls' on /mnt, I need not worry if the 'public' directory is visible.  I will only see it after I execute 'cd /mnt/public.

2. For your remote NFS server, ensure that rpcbind service is going, and that ports 111 for both TCP and UDP are open, in addition to the native port for NFS traffic, 2049.  (I had noticed during some testing that Fedora 16 will mount NFS shares just find using UDP 111, a Red Hat 6.3 base installed needed the same port using TCP on the remote server to be open).

3. If you're not using automount for an NFS share, there are examples in the default /etc/auto.misc file (which are commented out) to get you started. There are also plenty of help pages from both Red Hat, CentOS, Ubuntu and others if you get stuck.

2 comments:

  1. So why would you use autofs instead of fstab?

    ReplyDelete
  2. That's a good question, I don't normally find myself using autofs personally, but can come in handy in specific cases. Most notably NFS can cause problems if there are network connection issues, or corruption can occur on a USB key filesystem if it is removed prior to unmounting. In these cases, with autofs, the needed filesystem is only mounted (and done so automatically) while in use. After it is no longer accessed, and a time-out period expires, it automatically unmounts.

    ReplyDelete