Google


ADBRITE ads links
You are here: CodeIdol.com > Unix > Linux® Quick Fix > Remote Disk Access With NFS > The NFS Automounter

SAVE
Digg
Shown on del.icio.us del.icio.us
See Whos Talking About This on Technorati Technorati
I've Reddit reddit

The NFS automounter

The permanent mounting of filesystems has its disadvantages. For example, the /etc/fstab file is unique per Linux server and has to be individually edited on each. NFS client management, therefore, becomes more difficult. Also, the mount is permanent, tying up system resources even when the NFS server isn't being accessed.

NFS uses an automounter feature that overcomes these shortcomings by allowing you to bypass the /etc/fstab file for NFS mounts, instead using an NFS-specific map file that can be distributed to multiple clients. In addition, you can use the file to specify the expected duration of the NFS mount, after which time it is unmounted automatically. However, automounter continues to report to the operating system kernel that the mount is still active. When the kernel makes an NFS file request, automounter intercepts it and mounts the remote directory on the mount point defined in the map file. The mount point directory is dynamically created by the automounter when needed, after the timeout period the remote directory is unmounted and the mount point is deleted.

automounter Map Files

The master map file of automounter has a simple format that defines the name of the mount point directory in the first column and the subsidiary map file that controls its mounting in the second. You can add mounting options to a third column.

In the example, the /home directory needs to be automounted on an NFS server and the configuration information is defined in the /etc/auto.home file. Finally, the mount will only last for five minutes (300 seconds), and this value will act as a default for all the entries in the /etc/auto.home file.

Irregular entries that don't match /home are placed in the /etc/auto.direct file.

     #
     # File: /etc/auto.master
     #
     /home   /etc/auto.home --timeout=300
     /-      /etc/auto.direct

Direct Maps

Direct maps are used to define NFS filesystems that are mounted on different servers or that don't all start with the same prefix.

Indirect Maps

Indirect maps define directories that can be mounted under the same mount point. A good example would be all the users' directories under /home.

Note

Based on preliminary testing, an early release of Fedora Core 3 doesn't appear to work correctly with automounter. You have to have one indirect map defined to avoid startup errors, and after doing so, the maps don't appear to be activated. No errors occur in the logs either.


The Structure of Direct and Indirect Map Files

The format of these map files is similar to that of the /etc/auto.master file, except that columns two and three have been switched.

Column one lists all the directory keys that will activate the automounter feature. It is also the name of the mount point under the directory listed in the /etc/auto.master file. The second column provides all the NFS options to be used, and the third column lists the NFS servers and the filesystems that map to the keys.

When the NFS client accesses a file, it refers to the keys in the /etc/auto.master file to see whether any fall within the realm of the automounter's responsibility. If one does, then automounter checks the subsidiary map file for a subdirectory mount point key. If it finds one, then automounter mounts the files for the system.

Indirect Map File Example

In the previous example, the /etc/auto.master file redirected all references to the /home directory to the /etc/auto.home file. This second file has entries for peter, bob, and bunny; these directories are actually mount points for directories on servers Bigboy, Ochorios, and Waitabit.

     #
     # File: /etc/auto.home
     #
     peter   bigboy:/home/peter
     bob     ochorios:/home/bob
     bunny   waitabit:/home/bunny

Direct Map File Example

The second entry in the /etc/auto.master file was specifically created to handle all references to one of a kind directory prefixes. In the example the /data/sales and /sql/database are the mount points for directories on servers Bigboy and Waitabit.

     #
     # File: /etc/auto.direct
     #
     /data/sales          -rw          bigboy:/disk1/data/sales
     /sql/database        -ro,soft     waitabit:/var/mysql/database

Note

The automounter treats direct mounts as if they were files in a directory, not as individual directories. This means all direct mount points in the same directory are mounted simultaneously even if only one of them is being accessed. This can cause excessive mounting activity that can slow response times. There are tricks you can use to avoid this, perhaps the simplest is just to place direct mount points in different directories.


Note

Direct map entries in the /etc/auto.master file must all begin with /-, and you can use absolute path names with direct map files only, if you don't then you'll get an error like this in your /var/log/messages file:

     Nov  7 19:24:12 smallfry automount[31801]: bad map format:
     found indirect, expected direct exiting


Wildcards in Map Files

You can use two types of wildcards in a map file. The asterisk (*), which means all, and the ampersand (&), which instructs automounter to substitute the value of the key for the character.

Using the Ampersand Wildcard

In the example below, the key is peter, so the ampersand wildcard is interpreted to mean peter too. This means you'll be mounting the bigboy:/home/peter directory.

     #
     # File: /etc/auto.home
     #
     peter   bigboy:/home/&

Using the Asterisk Wildcard

In the example below, the key is *, meaning that automounter will attempt to mount any attempt to enter the /home directory. But what's the value of the ampersand? It is actually assigned the value of the key that triggered the access to the /etc/auto.home file. If the access was for /home/peter, then the ampersand is interpreted to mean peter, and bigboy:/home/peter is mounted. If access was for /home/bob, then bigboy:/home/bob would be mounted.

     #
     # File: /etc/auto.home
     #
     *   bigboy:/home/&

Starting automounter

Fedora Linux installs the automounter RPM, called autofs, by default. Here are some quick steps to get automounter started:

1.
Use the chkconfig command to configure the automounter daemons to start at boot. Activate NFS file locking to reduce the risk of corrupted data.

[root@bigboy tmp]# chkconfig autofs on

2.
Use the init scripts in the /etc/init.d directory to start the automounter daemons. The example uses the start option, but you can also stop and restart the process with the stop and restart options.

[root@bigboy tmp]# service autofs start

3.
Use the pgrep command to determine whether automounter is running. If it is, the command will return the process ID of the automount daemon.

[root@bigboy tmp]# pgrep automount
32261
[root@bigboy tmp]#

As you can see, managing the startup of automounter is very similar to that of other Linux applications and should be easy to remember.

automounter Examples

Now that you understand NFS automounter, you may benefit from an example. Chapter 30, "Centralized Logins Using NIS," contains a full scenario in which a school computer laboratory uses automounter to centrally house all the home directories of its students. Additional centralization is also achieved by using NIS for login authentication, access, and accounting control.

    SAVE
    Digg
    Shown on del.icio.us del.icio.us
    See Whos Talking About This on Technorati Technorati
    I've Reddit reddit

    You are here: CodeIdol.com > Unix > Linux® Quick Fix > Remote Disk Access With NFS > The NFS Automounter
       
    Related tags







    Popular Categories
    Unix books and guides
    AJAX popular information
    C# language guides
    Windows books and cookbooks
    .......






    © CodeIdol Labs, 2007