\documentclass{ictlab}

\RCS $Revision: 1.4 $

\usepackage{alltt,key,xr,cols}
\externaldocument[lt-]%
{../../linux_training-plus-config-files-ossi/build/masterfile}

\usepackage[pdfpagemode=None,pdfauthor={Nick Urbanik}]{hyperref}

\newcommand*{\labTitle}{The Automounter, and automating its
  Installation}
\renewcommand*{\subject}{Operating Systems and Systems Integration}

\providecommand*{\RPM}{\acro{RPM}\xspace}
\providecommand*{\CD}{\acro{CD}\xspace}

\begin{document}
\Large
%\tableofcontents

\section{Aim}
\label{sec:aim}

After successfully working through this exercise, You will:
\begin{itemize}
\item understand what the automounter does
\item be able to set up the automounter manually
\item be able to write a shell script suitable for use with
  \texttt{kickstart} to automatically configure the automounter as
  part of an unattended installation.
\end{itemize}

\section{Background}
\label{sec:background}

The automounter provides a convenient way of accessing network
drives.  You use it when you log into your network account to access
your home directory.  It is often used with \NFS (Network File
System), but can also be used to mount local disks such as floppy
disks or removable media such as Zip disks and \CDROM{}s.

Currently your home directory is mounted by the automounter when you
log into your netork account.  The configuration parameters for the
automounter are provided by our \LDAP directory server.  You may see
some information about the current automonter configuration by typing:
\begin{verbatim}
$ service autofs status
\end{verbatim}%$

\subsection{Advantages of the Automounter compared with putting
  entries in /etc/fstab}
\label{sec:advantages-of-autofs}

You can always put an entry into \texttt{/etc/fstab} that permanently
mounts a network partition on boot.  But \texttt{autofs} is much more
flexible.
\begin{itemize}
\item Any user can mount the drive automatically when they need it
\item Does not use the system resources when it does not need to be
  mounted
\end{itemize}

\subsection{The way it is configured}
\label{sec:configuration}

There are two sets of configuration files used by \texttt{autofs}: the
master file, \texttt{/etc/auto.master}, described by \texttt{man
  auto.master}, and the \emph{map} files used to define what can be
mounted on individual entries listed in \texttt{/etc/auto.master}.
These are described in \texttt{man 5 autofs}.

The \texttt{/etc/auto.master} file has the format:
\begin{alltt}
\emph{directory}   \emph{mapfile} \emph{options}
\end{alltt}
The options are optional.

The directory is the top-level directory where automatic mounts
occur.  This entry points to another file (your map), which takes care
of individually defining these mounts and their file system types.
See \texttt{/etc/auto.misc} as an example of a map file.


%\clearpage
\section{Procedure}
\label{sec:procedure}

\begin{enumerate}
\item Identify the documentation that comes with the \texttt{autofs}
  package with the \RPM command:
\begin{verbatim}
$ rpm -qld autofs
\end{verbatim}%$
To read the manual pages for the \texttt{/etc/auto.master}
configuration file:
\begin{verbatim}
$ man auto.master
\end{verbatim}%$
and for the other \texttt{/etc/auto.*} configuration files:
\begin{verbatim}
$ man 5 autofs
\end{verbatim}%$
Read the documentation.

\item Change to the root directory of your file system, and create a
  directory called \texttt{.auto} there:
\begin{verbatim}
$ sudo mkdir /.auto
\end{verbatim}%$

\item create a dangling symbolic link;
\begin{verbatim}
$ sudo ln -s .auto/ftp /ftp
\end{verbatim}%$
If you type \texttt{ls} here, you will see that the link is shown in
red, perhaps blinking, to indicate that the link does not point
anywhere.  The automounter will actually mount the network drive on
this.


\item edit the master automounter file, \texttt{/etc/auto.master}:
\begin{verbatim}
$ xhost +localhost
$ sudo -v
$ sudo emacs /etc/auto.master
\end{verbatim}%$

\item Edit a line there to read:
\begin{verbatim}
/.auto    /etc/auto.ftp   --timeout 60
\end{verbatim}
and make sure there is a newline at the end, and save it.
\item Create a file \texttt{/etc/auto.ftp} that contains this line:
\begin{verbatim}
ftp     -ro,soft,intr   nicku.org:/var/ftp/pub
\end{verbatim}
and make sure there is a newline at the end, and save it.

\item Restart the automounter, and change to that directory:
\begin{verbatim}
$ sudo service autofs restart
$ cd /ftp/redhat-7.2
$ ls -l
\end{verbatim}%$

\item If the automounter is not working properly, try seeing what the
  status of it is.  Here is the output from a machine which is working
  correctly:
{\small
\begin{verbatim}
$ service autofs status
Configured Mount Points:
------------------------
/usr/sbin/automount --timeout 60 /.auto file /etc/auto.ftp
/usr/sbin/automount --timeout 60 /home ldap nicku.org:ou=auto.home,
dc=tyict,dc=vtc,dc=edu,dc=hk
/usr/sbin/automount --timeout 60 /usr/local ldap nicku.org:
ou=auto.practical,dc=tyict,dc=vtc,dc=edu,dc=hk

Active Mount Points:
--------------------
/usr/sbin/automount --timeout 60 /.auto file /etc/auto.ftp
/usr/sbin/automount --timeout 60 /home ldap nicku.org:ou=auto.home,
dc=tyict,dc=vtc,dc=edu,dc=hk
/usr/sbin/automount --timeout 60 /usr/local ldap nicku.org:
ou=auto.practical,dc=tyict,dc=vtc,dc=edu,dc=hk
\end{verbatim}}%$
\end{enumerate}
Please note that I have broken the long lines here into two so that
they can fit on the page.

Note too that anything which prevents \NFS, such as a firewall, will
stop you from mounting a network drive.  This should not be the case
with you.  Here is how to test if you have a firewall.
\begin{verbatim}
$ sudo ipchains -L -n
\end{verbatim}
Output that looks like this:
\begin{verbatim}
ipchains: Incompatible with this kernel
\end{verbatim}
or that looks like this:
\begin{verbatim}
$ sudo ipchains -L -n
Chain input (policy ACCEPT):
Chain forward (policy ACCEPT):
Chain output (policy ACCEPT):
\end{verbatim}
show that your firewall is turned off.

\section{Automating this with a shell script}
\label{sec:scripting}

The next step is to automate this.  The aim is to use this script with
\texttt{kickstart}\footnote{Kickstart is a system for performing
  automated system installation.} in a future lab session so that you can
automatically configure the automounter when you perform an unattended
installation.


\subsection{Procedure for Scripting the automounter setup}
\label{sec:scripting-procedure}

Do this \emph{only} after you are certain that your automounter is
working properly.  You should buld your shell script up piece by
piece, not try to write it all at once.
\begin{enumerate}
\item undo the setup completely:
  \begin{enumerate}
  \item delete the directory \texttt{/.auto}
  \item delete the file \texttt{/etc/auto.ftp}
  \item delete the line 
 \begin{verbatim}
/.auto    /etc/auto.ftp   --timeout 60
\end{verbatim}
from \texttt{/etc/auto.master}.
 \end{enumerate}

\item Now write the code to create the directory and the symbolic
  link.  The code should work no matter where you run the script.
  
  You may find it helpful to refer to the notes about symbolic links
  on our subject web site.

  Make sure that this works before proceding.  


\item The pseudo code for the whole system is:
\begin{verbatim}
if there is no line containing /etc/auto.ftp in /etc/auto.master
    add the appropriate line to /etc/auto.master
overwrite any file /etc/auto.ftp with the appropriate content
make the directory /.auto
if any file or directory exists with the name /ftp
    delete it.
create the symbolic link
turn on the autofs service with chkconfig in runlevels 3, 4 and 5
\end{verbatim}

\item Show your lecturer your working shell script.
\end{enumerate}

\end{document}
