Tuesday, 3 January 2012

How to setup automounters on a Redhat Linux System

AUTOFS -- To automatically mount devices(floppy/cdrom) or nfs mount points

RPM Required : - autofs  ( On my box its   autofs-5.0.1-0.rc2.102 )

Config Files:

#rpm -qc autofs-5.0.1-0.rc2.102

/etc/auto.master --Master Map for automounter
The  auto.master  map  is  consulted to set up automount managed mount points when the autofs(8) script is invoked or the automount(8) program is
       run. Each line describes a mount point and refers to an autofs map describing file systems to be mounted under the mount point.

/etc/auto.misc
/etc/auto.net
/etc/auto.smb
/etc/autofs_ldap_auth.conf
/etc/rc.d/init.d/autofs
/etc/sysconfig/autofs


What Does automount means:
 An automount daemon mounts and unmounts filesystem when they are accessed as and when required. This minimizes the no of active mount pts and is mostly  transparent to users


                       automount - autofs - /etc/auto.master
   ==========================================

/usr/sbin/automount*       - User-land automounter process or Binary
/etc/auto.master           - Master config file
/etc/auto.misc             - Later
/etc/rc.d/init.d/autofs    - InitScript to start/stop autofs

* automount is a bg process that configures a single mt pt for autofs, the
  kernel portion of the Linux automounter

* The startup script /etc/rc.d/init.d/autofs starts the automount* daemon which
  parses a master file - /etc/auto.master - and runs the automount* daemon for
  each of the listed mounts

     It's typical to see a running instance of the automount* daemon for each
  automatic mt pt that has been configured in /etc/auto.master

                                /etc/auto.master
                                ----------------------

* The /etc/auto.master file associates a mount point with a map.

* The map translates the dir name accessed - the key - into a cmd line that
  mount* can use to perform the real mount

Format : Consists of 3 fields :

    1. The key - Specifies the mount root dir to use for FSs specified in the
                 map file [next field]

    2. The map file - which can be a text file, an exec prg, a NIS or LDAP DB

    3. Timeout value used to determine when to unmount the automounted FS

*  Eg

                        /etc/auto.master
                        ----------------

        # Mt Pt            File to consult    options
        # ---------              ---------------        -------
          /mnt             /etc/auto.misc       --timeout 60
          /funny           /etc/auto.misc      --timeout 60


                        /etc/auto.misc
                        --------------

Format : Consists of 3 fields :

    1. The key - Usually also the name of the subdir that you would access
                 to cause the device or FS specified in the 3rd field to be
                 mounted

    2. Comma-seperated list of options to pass to the mount prg

    3. Device driver/ Target NFS Server

                        /etc/auto.misc
                        --------------

        floppy      -fstype=auto,user           :/dev/fd0
        cdrom     -fstype=iso9660,ro,user :/dev/cdrom
        smile                                                nfsserver:/jokes
                           /|\
Note:                   |
        You could leave this blank or put soft,intr,rsize=8192,wsize=8192 etc
        This corresponds to the "-o" options given when mounting a NFS share
        on a client from the CLI


        Finally do a service autofs restart

        service autofs status or ps -el to check

---> If a user accesses the cdrom dir [ by doing cd /mnt/cdrom ], the
     automounter will construct a mount cmd and mount the device driver -
     /dev/cdrom -  on /mnt/cdrom and time out after 60 secs

=================================================

EXAMPLE 1:
-------

---> On nfsserver, set up an NFS server and export /jokes
     Do not forget portmap on both places

---> On nfsclient, do this : [ Do not forget to create dirs "/funny/smile"

     # cd /funny/smile
     # ls
      and you will be automounting the nfsserver:/jokes on nfsclient's local
      /funny/smile

MO:  When you do a /funny/smile, the automount* daemon, which is monitoring
     you, will, then, construct a mount command like this :

          from                                                from              from
      /etc/auto.misc                              auto.master          auto.misc
            |                                                     |                          |
           \|/                                                   \|/                        \|/
  mount nfsserver:/jokes                    /funny                  /smile


So eventually automount will mount nfsserver:/jokes to /funny/smile

=================================================
EXAMPLE 2: Automounting HomeDirs of Users from master nfsserver -- Indirect maps

On nfsserver export /home

On nfsclient
/etc/auto.master
        # Mt Pt            File to consult    options
        # ---------        ---------------    -------
         /home           /etc/auto.home      --timeout=60


/etc/auto.home
#User directory       NFSMountOptions                               Target Server
*                         -rw,soft,intr,rsize=8192,wsize=8192            nfsserver:/home/&



 Explanation:
So when a user foo logs into the system (nfsclient) his home directory /home/foo get automounted from nfsserver:/home/foo with mount options -rw,soft,intr,rsize=8192,wsize=8192


================================================= 
EXAMPLE 3: Automounting -- Direct Maps with /





On nfsserver export /data

On nfsclient
/etc/auto.master
        # Mt Pt            File to consult    options
        # ---------               ---------------    -------
         /-                  /etc/auto.direct      --timeout=60



/etc/auto.direct

#Mount directory       NFSMountOptions                               Target Server
/data                       -rw,soft,intr,rsize=8192,wsize=8192        nfsserver:/data


^ Don't forget this front slash ( else it will never work).


 Explanation:
So when a user foo cd to /data onto the system (nfsclient)  /data get automounted from nfsserver:/data with mount options -rw,soft,intr,rsize=8192,wsize=8192




===============================================
Quick Tips:
1) Make sure portmap and autofs is started on client for autofs to work properly.







No comments:

Post a Comment