Previous Page | Next Page

  1. Introduction
  2. Boot Process
  3. Init and System Initialization
  4. rc.sysinit script
  5. rc script
  6. functions script
  7. Services
  8. apm daemon
  9. network startup
  10. The network script file
  11. The network-functions file
  12. Portmap startup
  13. Random initialization
  14. Syslog initialization
  15. Gated
  16. Atd
  17. cron initialization
  18. pcmcia
  19. inetd daemon
  20. named daemon
  21. lpd daemon
  22. mars-nwe
  23. netfs startup
  24. dhcpd daemon
  25. autofs daemon
  26. keytable daemon
  27. sendmail daemon
  28. gpm daemon
  29. httpd daemon
  30. xfs startup
  31. smb startup
  32. innd startup
  33. linuxconf startup
  34. rc.local script
  35. Init, Getty, Login
  36. The shell
  37. Shutting down
  38. X
  39. Conclusions
  40. App A. rc.sysinit listing
  41. App B. functions listing
  42. App C. rc listing
  43. Credits
Linux autofs

Linux autofs

This the automount daemon used for remote filesystem mounting such as nfs along with mounting CDROM and floppy drives automatically. It uses the automount(8) program to run as a background task to perform the automatic mounts when required. There is a man page on the autofs(8) script. This script basically will read the configuration file, /etc/auto.master and pass parameters from this file to the automount program. An example file:

# $Id: auto.master,v 1.2 1997/10/06 21:52:03 hpa Exp $
# Sample auto.master file
# Format of this file:
# mount point map options
# For details of the format look at autofs(8).
/mnt	/etc/auto.misc	--timeout 20

There is a man page for auto.master(5). This file specifies the file /etc/auto.misc for device mounts. The /etc/auto.misc on my system is:

# $Id: auto.misc,v 1.2 1997/10/06 21:52:04 hpa 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

#kernel		-ro,soft,intr		ftp.kernel.org:/pub/linux
cd		-fstype=iso9660,ro	:/dev/cdrom

# the following entries are samples to pique your imagination
fl		-fstype=auto		:/dev/fd0
#floppy		-fstype=ext2		:/dev/fd0
#e2floppy	-fstype=ext2		:/dev/fd0
#jaz		-fstype=ext2		:/dev/sdc1

This file controls the devices to be mounted and specifies the directory used for that device.

The autofs startup script

#! /bin/bash
#
#       $Id: rc.autofs,v 1.4 1998/11/03 21:05:18 hpa Exp $
#
#	/etc/rc.d/init.d/autofs
#
#	rc file for automount using a Sun-style "master map".
#	We first look for a local /etc/auto.master, then a YP
#	map with that name
#
# chkconfig: - 72 08
# description: automatically mounts filesystems when you use \
#   them, and unmounts them later when you are not using them.
# processname: automount
#   Note that there may be multiple processes names automount
# config: /etc/auto.master
#   Note that all other config files are automatically reloaded
#   and may be different on different systems; we can ignore them
#   here

# Source function library.
. /etc/rc.d/init.d/functions

test -f /usr/sbin/automount || exit 0

#
# 	We can add local options here
#	e.g. localoptions='rsize=8192,wsize=8192'
#
localoptions=''

#
#	This function will build a list of automount commands to execute in
#	order #	to activate all the mount points. It is used to figure out
#	the difference of automount points in case of a reload
#
function getmounts()
{
#
#	Check for local maps to be loaded
#
if [ -f /etc/auto.master ] ; then
    cat /etc/auto.master | sed -e '/^#/d' -e '/^$/d'| (
	while read dir map options ;  do
	    if [ ! -z "$dir" -a ! -z "$map" \
			-a x`echo "$map" | cut -c1` != 'x-' ]
	    then
 		# special: treat -t or --timeout (or any reasonable derivative)
 		# specially, since it can't be made a normal mount option.
 		if echo $options | grep -- '-t' >/dev/null 2>&1 ; then
 		    mountoptions="--timeout $(echo $options | \
 		      sed 's/^.*-t\(imeout\)*[ \t]*\([0-9][0-9]*\).*$/\2/g')"
 		fi
 		options=`echo "$options" | sed -e '
 		  s/--*t\(imeout\)*[ \t]*[0-9][0-9]*//g
 		  s/\(^\|[ \t]\)-/\1/g'`
		basecommand="/usr/sbin/automount $mountoptions $dir"
		maptype=
		if echo $map | grep -- ':' ; then
		    maptype=`echo $map | cut -d ':' -f 1`
		    map=`echo $map | cut -d ':' -f 2-`
		fi
		case $map in
		    /*)	
		        if [ -n "$maptype" ] ; then
			    echo "$basecommand $maptype $map $options $localoptions"
			else
			    if [ -x $map ]; then
			        echo "$basecommand program $map $options $localoptions"
			    elif [ -f $map ]; then
			        echo "$basecommand file $map $options $localoptions"
			    else
			        echo "$basecommand `basename $map` $options $localoptions"
			    fi
			fi
			;;
		    *)
		        if [ -n "$maptype" ] ; then
			    echo "$basecommand $maptype $map $options $localoptions"
			else
			    if [ -f /etc/$map ] ; then
			        echo "$basecommand file /etc/$map $options $localoptions"
			    else
			        echo "$basecommand yp $map $options $localoptions"
			    fi
			fi
			;;
		esac
		unset basecommand
	    fi
	done
    )
else
#
#	Next to check for YellowPage maps to be loaded
#
  if [ -e /usr/bin/ypcat ] && [ `ypcat -k auto.master 2>/dev/null | wc -l` -gt 0 ]
  then
    ypcat -k auto.master | (
	while read dir map options
	do
	    if [ ! -z "$dir" -a ! -z "$map" \
			-a x`echo "$map" | cut -c1` != 'x-' ]
	    then
		map=`echo "$map" | sed -e 's/^auto_/auto./'`
		if echo $options | grep -- '-t' >/dev/null 2>&1 ; then
		    mountoptions="--timeout $(echo $options | \
		      sed 's/^.*-t\(imeout\)*[ \t]*\([0-9][0-9]*\).*$/\2/g')"
		fi
		options=`echo "$options" | sed -e '
		  s/--*t\(imeout\)*[ \t]*[0-9][0-9]*//g
		  s/\(^\|[ \t]\)-/\1/g'`
		echo "/usr/sbin/automount $mountoptions $dir yp $map $options $localoptions"
	    fi
	done
    )
  fi
fi
}

#
#	See how we were called.
#
case "$1" in
  start)
	# Check if the automounter is already running?
	if [ ! -f /var/lock/subsys/autofs ]; then
	    echo 'Starting automounter: '
	    getmounts | sh
	    touch /var/lock/subsys/autofs
	fi
	;;
  stop)
	kill -TERM $(/sbin/pidof /usr/sbin/automount)
	rm -f /var/lock/subsys/autofs
	;;
  reload|restart)
	if [ ! -f /var/lock/subsys/autofs ]; then
		echo "Automounter not running"
		exit 1
	fi
	echo "Checking for changes to /etc/auto.master ...."
	TMP1=`mktemp /tmp/autofs.XXXXXX` || { echo "could not make temp file" >&2; exit 1; }
	TMP2=`mktemp /tmp/autofs.XXXXXX` || { echo "could not make temp file" >&2; exit 1; }
	getmounts >$TMP1
	ps axw|grep "[0-9]:[0-9][0-9] /usr/sbin/automount " | (
	    while read pid tt stat time command; do
		echo "$command" >>$TMP2
		if ! grep -q "^$command" $TMP2; then
			kill -USR2 $pid
			echo "Stop $command"
		fi
	    done
	)
	cat $TMP1 | ( while read x; do
		if ! grep -q "^$x" $TMP2; then
			$x
			echo "Start $x"
		fi
        done )
	rm -f $TMP1 $TMP2
	;;
  status)
	echo "Configured Mount Points:"
	getmounts
	echo ""
	echo "Active Mount Points:"
	ps axw|grep "[0-9]:[0-9][0-9] /usr/sbin/automount " | (
		while read pid tt stat time command; do echo $command; done
	)
	;;
  *)
	echo "Usage: /etc/rc.d/init.d/autofs {start|stop|restart|reload|status}"
	exit 1
esac

exit 0