FadaSkeng.com
The Solaris & Linux Professional Resource center
Monday May 21, 2012
Home|Guides|Contact|About


Topics
Secure Shell SSH
Useful Commands

Coming Soon
Regex
Virtualization
SQLite
screen
RCS
Quotas
Remote/Network install
VSFTPD
TCPDump
cron
ettercap
Pam
Xymon/Hobbit
Puppet
Nagios
Nmap
SendMail
ntop
Snort
Squid

Useful Links
AutoFS

AutoFS controls the operation of the automount(8) daemons running on the Linux system. Usually autofs is invoked at system boot time with the start parameter and at shutdown time with the stop parameter. The autofs script can also manually be invoked by the system administrator to shut down, restart or reload the automounters.



Features: 1. Automatically mounts file systems (NFS, local, SMBFS, etc.) upon I/O request.
It Features:
1. Just in time Mounting
2. Controlled by automountd daemon
3. Managed via autofs service
4. references map files to determine file systems to mount
5. Obviates the need to distribute root password to non privileged users

Note: AutoFS must be running in order to auto-mount directories
Note: Do NOT auto-mount directories that are already mounted
On a linux system /etc/default/autofs contains configuration directives for autofs.
On Solaris 10 and most Linux distros /etc/nsswitch.conf used to determine lookup location for automount.
AutoFS defaults to permitting client to browse potential mount points.

---Direct mapping example--
Note: Direct mappings seamlessly merge remote exports with local directories

Example of Indirect Mapping
#mount_point     map_file     mount_points

I will describe how to use AutoFS on Solaris 10, Debian 5.x and an rpm based Linux distribution (OpenSuse 11.x) in this case.


  • enumerate AutoFS package
  • editing config files
  • create nfs shares using autofs file
  • autofs rpm
  • create autofs share for nfs
  • access nfs share via autofs
  • enumerate autofs share
  • create autofs file for share
  • mount nfs share using nfs

On Solaris the file /etc/default/autofs contains configuration directives for autofs.
AutoFS three types for mappings
.
1. Master map - /etc/auto_master
2. Direct map - /etc/auto_direct - facilitates direct mappings
3. Indirect map - /etc/auto* - refrenced from /etc/auto_master

1. To check whether autofs is already installed on your system.

#pkginfo -x | grep -i autofs

SUNWatfsr                         AutoFS, (Root)
SUNWatfsu                         AutoFS, (Usr)

To view information on the autofs packages, the #pkginfo command is used.

#pkginfo -l SUNWatfsr

   PKGINST:  SUNWatfsr
      NAME:  AutoFS, (Root)
  CATEGORY:  system
      ARCH:  i386
   VERSION:  11.10.0,REV=2005.01.21.16.34
   BASEDIR:  /
    VENDOR:  Sun Microsystems, Inc.
      DESC:  configuration and start-up files for the AutoFS filesystem
    PSTAMP:  on10ptchfeatx20080227231335
  INSTDATE:  Dec 12 2008 04:40
   HOTLINE:  Please contact your local service provider
    STATUS:  completely installed
     FILES:       15 installed pathnames
                  10 shared pathnames
                  10 directories
                   1 executables
                  13 blocks used (approx)

#pkginfo -l SUNWatfsu

   PKGINST:  SUNWatfsu
      NAME:  AutoFS, (Usr)
  CATEGORY:  system
      ARCH:  i386
   VERSION:  11.10.0,REV=2005.01.21.16.34
   BASEDIR:  /
    VENDOR:  Sun Microsystems, Inc.
      DESC:  utilities and a daemon (automountd) for the AutoFS filesystem
    PSTAMP:  on10ptchfeatx20080227231335
  INSTDATE:  Dec 12 2008 04:40
   HOTLINE:  Please contact your local service provider
    STATUS:  completely installed
     FILES:       13 installed pathnames
                   4 shared pathnames
                   6 directories
                   6 executables
                 408 blocks used (approx)

To the view files in each package the #pkgchk command is used.

#pkgchk -v SUNWatfsu

/usr
/usr/lib
/usr/lib/autofs
/usr/lib/autofs/automountd
/usr/lib/fs
/usr/lib/fs/autofs
/usr/lib/fs/autofs/automount
/usr/lib/fs/autofs/dfshares
/usr/lib/fs/autofs/mount
/usr/lib/fs/autofs/share
/usr/lib/fs/autofs/unshare
/usr/sbin
/usr/sbin/automount

#pkgchk -v SUNWatfsr

/etc
/etc/auto_home
/etc/auto_master
/etc/default
/etc/default/autofs
/lib
/lib/svc
/lib/svc/method
/lib/svc/method/svc-autofs
/var
/var/svc
/var/svc/manifest
/var/svc/manifest/system
/var/svc/manifest/system/filesystem
/var/svc/manifest/system/filesystem/autofs.xml

2. The file /etc/auto_master is always read by autofs(automountd daemon) and the file /etc/nsswitch.conf is used to determine lookup location for automount.

#grep auto /etc/nsswitch.conf

automount:  files

3. To view the status of the autofs service on solaris the following command is used.

#svcs -a | grep autofs

online         Jul_22   svc:/system/filesystem/autofs:default

For more information on the service, the followimg command is used.

#svcs -l autofs

fmri         svc:/system/filesystem/autofs:default
name         automounter
enabled      true
state        online
next_state   none
state_time   22 July 2010 22:28:30 WEST
logfile      /var/svc/log/system-filesystem-autofs:default.log
restarter    svc:/system/svc/restarter:default
contract_id  111
dependency   require_all/none svc:/system/filesystem/local (online)
dependency   require_all/restart svc:/milestone/name-services (online)
dependency   optional_all/none svc:/network/nfs/client (online)
dependency   require_all/restart svc:/network/rpc/bind (online)

For information on the PID the #ps command is used.

#ps -ef | grep autofs

    root   869     1   0   Jul 22 ?           0:00 /usr/lib/autofs/automountd
    root   870   869   0   Jul 22 ?           0:04 /usr/lib/autofs/automountd

4. To create a share using autos a mount point is required in this case I'll create a directory /Music in the root directory.

#mkdir /Music

5. Then for indirect sharing a mapping file /etc/auto_share is created in the /etc directory. This entry in the auto_master files points the /Music directory.

The syntax for auto_mount files is as follows:

<mount-point>  <options>  <location>
nfs-share -fstype=nfs 192.168.1.5:/Music

Then in the /etc/auto_share file the following entry created, which creates a share mp3 in the /Music directory, the NFS mount share and any potential options.

###Export from Music NFS box share ####

mp3     192.168.1.5:/Music      -vers=3

6. A restart of the autofs service is then required.

#svcadm restart autofs

#echo $?

Then view the exit status.

0

To view the status of the autofs daemon.

#svcs -l autofs

fmri         svc:/system/filesystem/autofs:default
name         automounter
enabled      true
state        online
next_state   none
state_time   17 August 2010 13:16:47 WEST
logfile      /var/svc/log/system-filesystem-autofs:default.log
restarter    svc:/system/svc/restarter:default
contract_id  29903
dependency   require_all/none svc:/system/filesystem/local (online)
dependency   require_all/restart svc:/milestone/name-services (online)
dependency   optional_all/none svc:/network/nfs/client (online)
dependency   require_all/restart svc:/network/rpc/bind (online)

To view the log file for the autofs daemon.

#tail /var/svc/log/system-filesystem-autofs\:default.log

umount: /Music busy
[ Aug 17 13:12:49 Method "stop" exited with status 0 ]
[ Aug 17 13:12:50 Executing start method ("/lib/svc/method/svc-autofs start") ]
[ Aug 17 13:12:50 Method "start" exited with status 0 ]
[ Aug 17 13:16:42 Stopping because service restarting. ]
[ Aug 17 13:16:42 Executing stop method ("/lib/svc/method/svc-autofs stop 29897") ]
umount: /Music busy
[ Aug 17 13:16:47 Method "stop" exited with status 0 ]
[ Aug 17 13:16:47 Executing start method ("/lib/svc/method/svc-autofs start") ]
[ Aug 17 13:16:47 Method "start" exited with status 0 ]

8. An ls -l of the /Music mount point returns, the mp3 share name.

#ls -l /Music/

total 8
drwxr-xr-x   6 root     root        4096 Jul 25 22:02 mp3

9. The contents of the mp3 directory reveals the contents of the remote NFS share.

#ls -l /Music/mp3/

total 88
drwxr-xr-x   2 root     root        4096 Jun 10 11:40 deb-packages
drwx------   2 root     root       16384 Mar 21 12:28 lost+found
-rwxrwxrwx   1 500      root          35 Mar 21 12:33 musix.txt
drwxr-xr-x 274 root     root       16384 Mar 23 04:35 SoulRnB
drw-r-xr-x  11 root     root        4096 Jul  3 23:21 Reggae





1. To check whether autofs is installed on your system.


#rpm -qa | grep -i autofs

autofs-5.0.3-82.28.1

To see more information on the autofs rpm.

#rpm -qi autofs

or

#rpm -qa | grep -i autofs | xargs rpm -qi

Name        : autofs                       Relocations: (not relocatable)
Version     : 5.0.3                             Vendor: openSUSE
Release     : 82.28.1                       Build Date: Wed 14 Jan 2009 13:07:40 GMT
Install Date: Wed 09 Jun 2010 14:37:24 BST      Build Host: berg
Group       : System/Daemons                Source RPM: autofs-5.0.3-82.28.1.src.rpm
Size        : 1353113                          License: GPL v2 or later
Signature   : RSA/8, Wed 14 Jan 2009 13:07:49 GMT, Key ID b88b2fd43dbdc284
Packager    : http://bugs.opensuse.org
URL         : http://www.kernel.org/pub/linux/daemons/autofs/v5/
Summary     : A Kernel-Based Automounter
Description :
Autofs is a kernel-based automounter for Linux.  It is still under
development, although the features currently implemented seem to work
well.  There is nowhere near enough documentation available yet. Help
in getting some written would be appreciated. This package replaces the
amd package.



Authors:
--------
    H. Peter Anvin 
    Ian Kent 
Distribution: openSUSE 11.1

2. The important files for configuring AutoFS are located in the /etc/ folder. These are the files, auto.master and the auto.share file.
For indirect sharing an entry /home/skeng/remote-mount /etc/auto.shares is included.
This maps the share referred to in the auto.shares file to the directory for the user skeng in the directory /home/skeng/remote-mount.

#cat auto.master

#
# Sample auto.master file
# This is an automounter map and it has the following format
# key [ -mount-options-separated-by-comma ] location
# For details of the format look at autofs(5).
#
#/misc  /etc/auto.misc
#
####AutoFS for Music shares####
/home/skeng/remote-mount       /etc/auto.shares



# NOTE: mounts done from a hosts map will be mounted with the
#       "nosuid" and "nodev" options unless the "suid" and "dev"
#       options are explicitly given.
#
#/net   -hosts
#
# Include central master map if it can be found using
# nsswitch sources.
#
# Note that if there are entries for /net or /misc (as
# above) in the included master map any keys that are the
# same will not be seen as the first read key seen takes
# precedence.
#
+auto.master

3. The /etc/auto.share file is created from copying the /etc/auto.misc and the following entry created.
The syntax for creating these shares is
<mount-point>  <options>  <location>
music -fstype=nfs 192.168.1.5:/Music

#cat auto.shares

#
# This is an automounter map and it has the following format
# key [ -mount-options-separated-by-comma ] location
# Details may be found in the autofs(5) manpage

music   -fstype=nfs             192.168.1.5:/Music


#cd             -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom

# the following entries are samples to pique your imagination
#linux          -ro,soft,intr           ftp.example.org:/pub/linux
#boot           -fstype=ext2            :/dev/hda1
#floppy         -fstype=auto            :/dev/fd0
#floppy         -fstype=ext2            :/dev/fd0
#e2floppy       -fstype=ext2            :/dev/fd0
#jaz            -fstype=ext2            :/dev/sdc1
#removable      -fstype=ext2            :/dev/hdd

Note: Do NOT auto-mount directories that are already mounted

4. To view the runtime levels for the autofs daemon we use the #chkconfig command.

#chkconfig --list autofs

autofs                    0:off  1:off  2:off  3:off  4:off  5:off  6:off

To start the service on suse the #rcautofs command is used as root. On Fedora and Centos the command to start the services are /etc/init.d/autofs start and #service autofs start.

#rcautofs status

Checking for service automount                                                                                     running

Options for the autofs daemon are show below.

#/etc/init.d/autofs

Usage: /etc/init.d/autofs {start|stop|force-stop|status|try-restart|restart|force-reload|reload|force-expire}

6. The autofs feature set includes

1 Just in time Mounting.
2 Controlled by automountd daemon
3 Managed via autofs service
4 references map files to determine file systems to mount
5 Obviates the need to distribute root password to non privileged users

The file /etc/default/autofs contains configuration directives for autofs.
There are types of share options.
1. Master map - /etc/auto_master
2. Direct map - /etc/auto_direct - facilitates direct mappings
3. Indirect map - /etc/auto* - refrenced from /etc/auto_master
7. To view the mounted directive the mount command is used, this illustrates the mounted nfs share.

#mount

192.168.1.5:/Music on /home/skeng/remote-mount/music type nfs (rw,addr=192.168.1.5,nfsvers=3,proto=tcp,mountproto=udp)

8. To view the NFS share on the local system.

#ls -l remote-mount

total 0
dr-xr-xr-x 2 root root 0 2010-08-21 16:45 music

9. Then listing the contents of the share name music.

#ls -l /home/skeng/remote-mount/music/

total 44
drwxr-xr-x   2 root root  4096 2010-06-10 11:40 deb-packages
drwx------   2 root root 16384 2010-03-21 12:28 lost+found
-rwxrwxrwx   1  500 root    35 2010-03-21 12:33 musix.txt
drwxr-xr-x 274 root root 16384 2010-03-23 04:35 SoulRnB
drw-r-xr-x  11 root root  4096 2010-07-03 23:21 Reggae


1. To check whether autofs is installed.

#dpkg -l | grep -i autofs

2. If it is not aleardy installed then locate and install the package from your install directory.

#dpkg -i autofs

Alternatively you may use

#apt-cache search autofs

afuse - automounting file system implemented in user-space using FUSE
autofs-hesiod - Hesiod map support for autofs
autofs-ldap - LDAP map support for autofs
autofs - kernel-based automounter for Linux
autofs5-hesiod - Hesiod map support for autofs, version 5
autofs5-ldap - LDAP map support for autofs, version 5
autofs5 - kernel-based automounter for Linux, version 5
obexfs - mount filesystem of ObexFTP capable devices

#apt-get install autofs

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed
  autofs
0 upgraded, 1 newly installed, 0 to remove and 14 not upgraded.
Need to get 112kB of archives.
After this operation, 397kB of additional disk space will be used.
Get: 1 http://ftp.uk.debian.org lenny/main autofs 4.1.4+debian-2.1 [112kB]
Fetched 112kB in 0s (154kB/s)
Selecting previously deselected package autofs.
(Reading database ... 92145 files and directories currently installed.)
Unpacking autofs (from .../autofs_4.1.4+debian-2.1_i386.deb) ...
Processing triggers for man-db ...
Setting up autofs (4.1.4+debian-2.1) ...

Creating config file /etc/auto.master with new version

Creating config file /etc/auto.misc with new version

Creating config file /etc/auto.net with new version

Creating config file /etc/auto.smb with new version

Creating config file /etc/default/autofs with new version
Starting automounter: loading autofs4 kernel module, no automount maps defined.

The file /etc/auto.master primary configuration file also contains mount points and their mappings.

The file /etc/sysconfig/autofs contains the default startup directives.

3. I will create a mount point directory /Music, then modify the /etc/auto.shares file to refer to this share directive.

#
# $Id: auto.master,v 1.4 2005/01/04 14:36:54 raven Exp $
#
# Sample auto.master file
# This is an automounter map and it has the following format
# key [ -mount-options-separated-by-comma ] location
# For details of the format look at autofs(5).
#/misc  /etc/auto.misc --timeout=60
#/smb   /etc/auto.smb
#/misc  /etc/auto.misc
#/net   /etc/auto.net

###Shares for Music from Media Server####
/Music  /etc/auto.shares

4. The syntax for specfifying a share is as follows.

<mount-point>  <options>  <location>
music -fstype=nfs 192.168.1.5:/Music

I will copy the /etc/auto.misc file to /etc/auto.shares; Then edit the /etc/auto.shares and add the share directive
 mp3     -fstype=nfs             192.168.1.5:/Music
.


# $Id: auto.misc,v 1.2 2003/09/29 08:22:35 raven Exp $
#
# This is an automounter map and it has the following format
# key [ -mount-options-separated-by-comma ] location
# Details may be found in the autofs(5) manpage

##Share directive for NTFS Music Share###


mp3     -fstype=nfs             192.168.1.5:/Music



#cd             -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom

# the following entries are samples to pique your imagination
#linux          -ro,soft,intr           ftp.example.org:/pub/linux
#boot           -fstype=ext2            :/dev/hda1
#floppy         -fstype=auto            :/dev/fd0
#floppy         -fstype=ext2            :/dev/fd0
#e2floppy       -fstype=ext2            :/dev/fd0
#jaz            -fstype=ext2            :/dev/sdc1
#removable      -fstype=ext2            :/dev/hdd

5. Without a restart of autofs the mounted filesystems are shown below.

#mount

/dev/sda1 on / type ext3 (rw,errors=remount-ro)
tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
procbususb on /proc/bus/usb type usbfs (rw)
udev on /dev type tmpfs (rw,mode=0755)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=620)
/dev/sda6 on /home type ext3 (rw)
debian:/# /etc/init.d/autofs start
Starting automounter: done.

6. Restarting the autofs daemon causes thse changes to take effect.

First for the autofs daemon status.

#/etc/init.d/autofs status

Configured Mount Points:
------------------------
/usr/sbin/automount --timeout=300 /Music file /etc/auto.shares

Active Mount Points:
--------------------

Then to start the daemon.

#/etc/init.d/autofs start

Starting automounter: done.

Now the daemon status.

#/etc/init.d/autofs status

Configured Mount Points:
------------------------
/usr/sbin/automount --timeout=300 /Music file /etc/auto.shares

Active Mount Points:
--------------------
/usr/sbin/automount --pid-file=/var/run/autofs/_Music.pid --timeout=300 /Music file /etc/auto.shares

7. A mount will echo to standard out the entry for the mounted filesystem /Music with pid8493.

#mount

/dev/sda1 on / type ext3 (rw,errors=remount-ro)
tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
procbususb on /proc/bus/usb type usbfs (rw)
udev on /dev type tmpfs (rw,mode=0755)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=620)
/dev/sda6 on /home type ext3 (rw)
automount(pid8493) on /Music type autofs (rw,fd=4,pgrp=8493,minproto=2,maxproto=4)
192.168.1.5:/Music on /Music/mp3 type nfs (rw,addr=192.168.1.5)

8. An #ls -l against this directory shows.

#ls -l /Music/mp3/

total 44
drwxr-xr-x   2 root root  4096 2010-06-10 11:40 deb-packages
drwx------   2 root root 16384 2010-03-21 12:28 lost+found
-rwxrwxrwx   1  500 root    35 2010-03-21 12:33 musix.txt
drwxr-xr-x 274 root root 16384 2010-03-23 04:35 SoulRnB
drw-r-xr-x  11 root root  4096 2010-07-03 23:21 Reggae


All brands, products or company names are trademarks or registered trademarks of their respective companies