\section{Mounting filesystems}

\begin{frame}
   {Mounting Filesystems}

   \begin{itemize}
      \item Each filesystem is mounted under a specific
      directory:
      \begin{cmd}
$ mount -t ext4 /dev/sdb4 /home
      \end{cmd}

      \begin{itemize}
         \item Mounts an \textbf{ext4} filesystem
         \item Usually not necessary to specify the type with \verb?-t? option
         \item The filesystem is located on a specific
         partition of a hard drive
         (\filelink{/dev/sdb4})
         \item The filesystem is mounted at the
         position \filelink{/home} in the current
         directory tree
         \item Any files residing in the original
         \filelink{/home} directory are hidden until
         the partition is unmounted
      \end{itemize}
   \end{itemize}

\end{frame}

\cprotect\note{


   All accessible files in \textbf{Linux} are organized into
   one large hierarchical tree structure with the head of the
   tree being the root directory (\filelink{/}). However, it is
   common to have more than one partition (each of which can
   have its own filesystem type) joined together in the same
   filesystem tree.  These partitions can also be on different
   physical devices, even on a network.

   The \textbf{mount} program allows attaching at any point in
   the tree structure; \textbf{umount} allows detaching them.

   The \textbf{mount point} is the directory where the
   filesystem is attached. It must exist before \textbf{mount}
   can use it; \textbf{mkdir} can be used to create an empty
   directory.  If a pre-existing directory is used and it
   contains files prior to being used as a mount point, they
   will be hidden after mounting.  These files are not deleted
   and will again be visible when the filesystem is unmounted.

   Only the superuser can mount and unmount filesystems.

}

\begin{frame}
   {mount}

   \begin{multicols}{2}
      \begin{itemize}
         \item General form for \textbf{mount}
         \begin{cmd}
mount [options] <source> <directory>
      \end{cmd}
         \item Can mount using: \textbf{Device Node}, \textbf{Label}
         or \textbf{UUID}
         \item Each filesystem has its own set of options.
         A common example would be:
         \begin{cmd}
$ sudo mount -o remount,ro /myfs
      \end{cmd}
         which remounts a filesystem with a read-only attribute.
         \begin{figure}[H]
            \includegraphics[width=2.8in]{IMAGES/mounthelp}
            \caption{mount}
         \end{figure}
      \end{itemize}
   \end{multicols}

\end{frame}

\cprotect\note{

   The following ways of mounting are all equivalent:

   \begin{cmd}
$ sudo mount /dev/sda2   /home
$ sudo mount LABEL=home  /home
$ sudo mount    -L home  /home
$ sudo mount UUID=26d58ee2-9d20-4dc7-b6ab-aa87c3cfb69a /home
$ sudo mount   -U 26d58ee2-9d20-4dc7-b6ab-aa87c3cfb69a /home
   \end{cmd}

   Labels are assigned by filesystem type specific
   utilities, such as \textbf{e2label}, and \textbf{UUID}s
   are assigned when partitions are created as containers
   for the filesystem, and formatted with \textbf{mkfs}.

   While any of these three methods for specifying the
   device can be used, modern systems deprecate using the
   device node form because the names can change according
   to how the system is booted, which hard drives are
   found first, etc.

   Labels are an improvement, but on rare occasions one
   could have two partitions that wind up with the same
   label.  \textbf{UUID}s, however, should always be unique
   and are created when the partitions are created.

}

\begin{frame}
   {Currently Mounted Filesystems}

   \begin{figure}[H]
      \includegraphics[width=0.72\textwidth]{IMAGES/mountout}
      \caption{Currently Mounted Filesystems}
   \end{figure}
\end{frame}

\cprotect\note{

}

\begin{frame}
   {umount}

   \begin{itemize}
      \item Used to unmount filesystems
      \item General form of \textbf{umount}:
      \begin{cmd}
umount [device-file | mount-point]
      \end{cmd}
      \item
      Examples:
      \begin{itemize}
         \item Unmount the \filelink{/home} filesystem:
         \begin{cmd}
$ umount /home
         \end{cmd}
         \item Unmount \filelink{/dev/sda3} device:
         \begin{cmd}
$ umount /dev/sda3
         \end{cmd}
      \end{itemize}
   \end{itemize}

\end{frame}

\cprotect\note{

   Note the command to unmount a filesystem is \textbf{umount}
   (not \textbf{unmount}!).

   Like \textbf{mount}, \textbf{umount} has many options, many
   of which are specific to filesystem type.  Once again, the
   \textbf{man} pages are the best source for specific option
   information.

   The most common error encountered when unmounting a
   filesystem is trying to do this on a filesystem currently in
   use; i.e., there are current applications using files or
   other entries in the filesystem.

   This can be as simple as having a terminal window open in a
   directory on the mounted filesystem.  Just using \textbf{cd}
   in that window, or killing it, will get rid of the
   \texttt{device is busy} error and allow unmounting.

   However, if there are other processes inducing this error,
   you must kill them before unmounting the filesystem.  You
   can use \textbf{fuser} to find out which users are using the
   filesystem and kill them (be careful with this, you may also
   want to warn users first). You can also use \textbf{lsof}
   (``list open files'') to try and see which files are being
   used and blocking unmounting.
}
\section{NFS}
\begin{frame}
   {Network Shares (NFS) }

   \begin{itemize}
      \item
      Most common network share is \textbf{NFS}
      \item
      Others include \textbf{AFS} and \textbf{SMB}
      (\textbf{CIFS})
      \item
      \textbf{mount} as in:
      \begin{cmd}
$ sudo mount -t nfs myserver.com:/shdir /mnt/shdir
      \end{cmd}
      \item
      Put this line in \filelink{/etc/fstab} to mount on boot
      or with \verb?mount -a?:

      \begin{kcode}
myserver.com:/shdir /mnt/shdir nfs rsize=8192,wsize=8192,timeo=14,intr 0 0
      \end{kcode}
      \item System may try to mount \textbf{NFS} filesystem
      before the network is up. Can use \verb?netdev?  and
      \verb?noauto? options (\verb?man nfs?, examine
      \textbf{mount} options)
      \item
      Can be solved also using \textbf{autofs} or
      \textbf{automount}
      \item
      \textbf{mount} has a million options, some specific to
      \textbf{nfs}.  See the \textbf{man} pages for both
      \textbf{nfs} and \textbf{mount} for more detail.
   \end{itemize}

\end{frame}

\cprotect\note{

   It is common to mount remote filesystems through network
   shares, so they appear as if they were on the local
   machine.

   Probably the most common method used historically has been
   \textbf{NFS} (\textbf{N}etwork \textbf{File}
   \textbf{S}ystem).

   \textbf{NFS} was originally developed by \textbf{Sun
      Microsystems} in 1989, and has been continuously
   updated.  Modern systems use \textbf{NFSv4}, which has
   been continuously updated since 2000.

   Other network filesystems include \textbf{AFS}
   (\textbf{A}ndrew \textbf{F}ile \textbf{S}ystem) and
   \textbf{SMB} (\textbf{S}erver \textbf{M}essage
   \textbf{B}lock), also termed \textbf{CIFS}.

   Because a network file system may either be unavailable at
   any time, either because it is not present on the network
   share, or the network is unavailable, systems have to be
   prepared for this possibility.

   Thus, in such circumstances, a system should be instructed
   not to get hung, or blocked, while waiting longer than a
   specified period.  These can be specified in the mount
   command or in \filelink{/etc/fstab}.

}
\section{Mounting at Boot and /etc/fstab}
\begin{frame}
   {Mounting at Boot}

   \begin{itemize}
      \item During system initialization the command:
      \begin{cmd}
$ mount -a
      \end{cmd}
      is executed in order to mount all filesystems listed in
      \filelink{/etc/fstab}
      \item Can specify local and remote network-mounted
      filesystems to be mounted at bootup
   \end{itemize}

\end{frame}

\cprotect\note{

   \filelink{/etc/fstab} is used to define
   mountable file systems and devices on startup. Look
   there to see what file systems can be mounted, where
   they may be found locally, who may mount them and with
   what permissions. If a file or directory is specified
   in \filelink{/etc/fstab}, it may be mounted at startup.

   This may include both local and remote network-mounted
   filesystems, such as NFS and samba filesystems.  }

\begin{frame}
   {/etc/fstab}

   \begin{itemize}
      \item Contains information about filesystems, their
      standard mount points and what options should be
      used when mounting them.
      \item Each record in the file contains white space
      separated fields of information about a filesystem
      to be mounted
      \begin{itemize}
         \item Device-file, label, or UUID
         \item Mount point
         \item Filesystem type
         \item A comma-separated options list
         \item Dump frequency (or a zero)
         \item \textbf{fsck} pass number (or a zero)
      \end{itemize}
      \item The \textbf{mount} and \textbf{umount} commands
      can use information in \filelink{/etc/fstab}
   \end{itemize}

\end{frame}

\cprotect\note{

   Each record in the file contains information about a
   filesystem to be mounted at boot time.  The first item
   in the record may either be a device-file name (such
   as \filelink{/dev/sda1}), a label, or a UUID .  This is
   followed by the mount point for the filesystem (where
   in the tree structure is it to be inserted).  Then
   comes the filesystem type followed by a
   comma-separated list of options, followed by the dump
   frequency (used by the \texttt{dump -w} command) or a
   zero (ignored by \textbf{dump}), followed by the
   \textbf{fsck} pass number or a zero (meaning do not
   \textbf{fsck} this partition).

   \begin{figure}[H]
      \includegraphics[width=6.0in]{IMAGES/fstab}
      \caption{/etc/fstab Example}
   \end{figure}
   \vspace{-20pt}
}

