DistributedNetworks DistributedNetworks


Network File Services  «Prev 

Mounting NFS volumes automatically

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.

When a user accesses an automount directory, the system consults the /etc/auto.master file .This file pairs automount points to map files.

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.

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

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.