Network File Services  «Prev  Next»

Lesson 8 Automounting NFS filesystems
Objective Use automounter to mount remote filesystems automatically

Automounting NFS Filesystems(Use Automounter to mount remote filesystems)

The Linux automounter automatically mounts filesystems the first time you access them. You can configure the automounter to mount remote filesystems as well, using NFS. If network activity is costly, such as when you pay by the minute, you might want to configure the automounter to mount NFS filesystems. The automounter works by monitoring a particular directory (called an automount point) and taking action whenever a user changes into one of its subdirectories.

The automount Process

What is the process for Automounting NFS filesystems in Red Hat Linux?
In Red Hat Linux, automounting NFS filesystems can be achieved using the autofs service. Here are the general steps to configure automounting of NFS filesystems in Red Hat Linux:
  1. Install the autofs package using the package manager of your choice, if it's not already installed.
  2. Edit the "/etc/auto.master" file to add a line that specifies the mount point for the NFS filesystems. For example, to mount the NFS filesystem at "/mnt/nfs", add the following line to the end of the file:
    /mnt/nfs /etc/auto.nfs
    

  3. Create a new file named "/etc/auto.nfs" (or whatever name you specified in step 2) and add a line for each NFS filesystem that you want to mount. Each line should specify the mount point, the server and path of the NFS share, and any options that should be passed to the NFS client. For example:
    sharename -fstype=nfs server:/path/to/share
    

    Note that "sharename" can be any name that you want to use to identify the share.
  4. Save the changes to the "/etc/auto.nfs" file.
  5. Start the autofs service using the following command:
    systemctl start autofs
    
    You can also enable the service to start automatically at boot time using the following command:
    systemctl enable autofs
    
After completing these steps, the NFS filesystem should be automatically mounted at the specified mount point when accessed by a user or application. If there are any issues with the configuration, you can check the logs in "/var/log/messages" or use the "systemctl status autofs" command to view the status of the autofs service.

The following series of imagesillustrates how the automount process works:
1) When a user accesses an automount directory, the system consults the /etc/auto.master file This file pairs automount points to map files.
1) When a user accesses an automount directory, the system consults the /etc/auto.master file .This file pairs automount points to map files.

2) The system looks up the automount point in /etc/auto.master file, then consults the associated map file. In this example, Linux consults the /etc/auto.rmt map
2) The system looks up the automount point in /etc/auto.master file, then consults the associated map file. In this example, Linux consults the /etc/auto.rmt map.

3) The map file pairs keys to locations. When the user accesses on the listed keys, the automounter pulls files from the associated location.
3) The map file pairs keys to locations. When the user accesses on the listed keys, the automounter pulls files from the associated location.

4) In this example, the files were located on a network server.
4) In this example, the files were located on a network server. The name serv:/home specified the /home directory on serv. automounter interprets this naming convention as an NFS location, and gets the file from here. The user then has full access to the files on the server.
Workflow Summary
  1. When a user accesses an automount directory, the system consults the /etc/auto.master file
  2. The system looks up the automount point in /etc/auto.master file, then consults the associated map file. In this example
  3. The map file pairs keys to locations. When the user accesses on the listed keys, the automounter pulls files from the associated location.
  4. In this example, the files were located on a network server.


Auto-Mounting an NFS Share

The following procedure illustrates how to configure autofs to auto-mount an NFS share available on your network. It assumes you are familiar with NFS exports.
  1. Edit the master map file /etc/auto.master:
    sudo vim /etc/auto.master
    

    Add a new entry for the new NFS mount at the end of /etc/auto.master:
    /nfs/etc/auto.nfs --timeout=10
    

    It tells autofs that the base mount point is /nfs, the NFS shares are specified in the /etc/auto.nfs map, and that all shares in this map will be automatically unmounted after 10 seconds of inactivity.
  2. Create a new map file for NFS shares:
    	
    sudo vim /etc/auto.nfs
    

    /etc/auto.nfs normally contains a separate line for each NFS share.
    Add the line describing the mount point and the NFS share network address:
    	
    export jupiter.com:/home/geeko/doc/export
    

    The above line means that the /home/geeko/doc/export directory on the jupiter.com host will be auto-mounted to the /nfs/export directory on the local host (/nfs is taken from the auto.master map) when requested. The /nfs/export directory will be created automatically by autofs.
  3. Optionally comment out the related line in /etc/fstab if you previously mounted the same NFS share statically. The line should look similar to this:
    #jupiter.com:/home/geeko/doc/export /nfs/export nfs defaults 0 0
  4. Reload autofs and check if it works:
    sudo systemctl restart autofs
    # ls -l /nfs/export
    total 20
    drwxr-xr-x  6 1001 users 4096 Oct 25 08:56 ./
    drwxr-xr-x  3 root root     0 Apr  1 09:47 ../
    drwxr-xr-x  5 1001 users 4096 Jan 14  2013 .images/
    drwxr-xr-x 10 1001 users 4096 Aug 16  2013 .profiled/
    drwxr-xr-x  3 1001 users 4096 Aug 30  2013 .tmp/
    drwxr-xr-x  4 1001 users 4096 Oct 25 08:56 SLE-12-manual/
    

    If you can see the list of files on the remote share, then autofs is functioning.

Configuring the automounter

To get automounting working, you need to:
  1. Configure /etc/auto.master to monitor directories you wish to automount. The format for this file is: automount_point map_file. To monitor /proj for accesses, you'd put /proj /etc/auto.proj.
  2. Configure each map file. For example, /etc/auto.proj might contain docs serv:/proj/docs and
    open serv:/proj/open_projects
    
    .
    Whenever a user accesses /proj/docs or /proj/open, automounter will mount the filesystems via NFS.
The next lesson discusses how to resolve NFS problems.

Using NFS Automounter

Before moving on to the next lesson, click the Exercise link below to practice using the Automounter to configure automatic remote file access.

Using NFS Automounter

This exercise asked you to configure the /etc/auto.master file to monitor the /projects directory on your local machine. You have opened the /etc/auto.master file, now you need to add the automount point to map file association by typing
/projects/etc/auto.projects
.
You save the file and then open /etc/auto.projects. Mount the server's directories whenever users access docs or sources. First, type
serv:/export/docs

and press Enter. Then type sources serv:/export/source and press Enter.
This is the end of the Simulation.

Mounting NFS File Systems using autofs

A third option for mounting an NFS share is the use of the autofs service. Autofs uses the automount daemon to manage your mount points by only mounting them dynamically when they are accessed. Autofs consults the master map configuration file /etc/auto.master to determine which mount points are defined. It then starts an automount process with the appropriate parameters for each mount point. Each line in the master map defines a mount point and a separate map file that defines the file systems to be mounted under this mount point. For example, the
 /etc/auto.misc 
 

file might define mount points in the /misc directory; this relationship would be defined in the
/etc/auto.master file. 

Each entry in auto.master has three fields. The first field is the mount point. The second field is the location of the map file, and the third field is optional. The third field can contain information such as a timeout value. For example, to mount the directory /proj52 on the remote machine penguin.example.net at the mount point /misc/myproject on your machine, add the following line to auto.master:

SEMrush Software 7 SEMrush Banner 7