\section{Filesystem Quotas **}

\begin{frame}
   {Filesystem Quotas **}

   \begin{itemize}
      \item \textbf{Linux} can use and enforce quotas on
      many filesystem types.
      \item These utilities help manage quotas:
      \begin{itemize}
         \item \textbf{quotacheck}: generates and
         updates quota accounting files
         \item \textbf{quotaon}: enables quota
         accounting
         \item \textbf{quotaoff}: disables quota
         accounting
         \item \textbf{edquota}: edits user or group quotas
         \item \textbf{quota}: reports on usage and
         limits
      \end{itemize}
      \item Quota operations require the existence of the
      files \filelink{aquota.user} and \filelink{aquota.group}
      in the root directory of the filesystem using
      quotas.
   \end{itemize}

   %%\begin{OLDlfbox}
   \begin{iconbox}[unbreakable]{Please Note}{\importantcolor}{\importanticon}
      The use of disk quotas is no longer popular in enterprise data
      centers, which is why this section is marked as optional!
   \end{iconbox}
   %%   \end{OLDlfbox}

\end{frame}

\cprotect\note{

   Disk quotas allow administrators to control the maximum
   space particular users (or groups) are allowed.
   Considerable flexibility is allowed and quotas can be
   assigned on a per-filesystem basis.  Protection is
   provided against a subset of users exhausting
   collective resources.

   Quotas may be enabled or disabled on a per-filesystem
   basis.  In addition \textbf{Linux} supports the use of
   quotas based on user and group ids.

   Different filesystem types may have additional
   quota-related utilities, such as \textbf{xfs\_quota}.

}

\begin{frame}
   {Setting up quotas}

   \begin{itemize}
      \item Mount the filesystem with user and/or group
      quota options:
      \begin{itemize}
         \item Add the \texttt{usrquota} and/or
         \texttt{grpquota} options to the filesystems
         entry in \filelink{/etc/fstab}
         \item Mount or remount the filesystem
      \end{itemize}
      \item Run \textbf{quotacheck} on the filesystem to set
      up quotas
      \item Enable quotas on the filesystem
      \item Set quotas with \textbf{edquota}
   \end{itemize}

\end{frame}

\cprotect\note{

   To create a filesystem quota you must first make sure
   you have mounted the filesystem with the user and/or
   group quota mount options.  Without these nothing else
   will work.

   Fore example, to enable use quotas, first you need to
   put the right options in \filelink{/etc/fstab} as in:
   \begin{cmd}
/dev/sda5 /home ext4 defaults,usrquota 1 2
   \end{cmd}
   where we have assumed \filelink{/home} is on a
   dedicated partition.

   Then test with the following commands:

   \begin{cmd}
$ sudo mount -o remount /home
$ sudo quotacheck -vu /home
$ sudo quotaon -vu /home
$ sudo edquota someusername
   \end{cmd}

   You may also want to set up \textbf{grace periods} with
   \textbf{edquota}.
}

\begin{frame}
   {quotacheck}

   \begin{itemize}
      \item
      \textbf{quotacheck} creates and updates the
      filesystem's quota accounting files (\verb?aquota.user?
      and \verb?aquota.group?)

      \item To update user files for all filesystems in
      \filelink{/etc/fstab} with user quota options:
      \begin{cmd}
$ sudo quotacheck -ua
      \end{cmd}
      \item
      To update group files for all filesystems in
      \filelink{/etc/fstab} with group quota options:
      \begin{cmd}
$ sudo quotacheck -ga
      \end{cmd}
      \item
      To update the user file for a particular filesystem:
      \begin{cmd}
$ sudo quotacheck -u [somefilesystem]
      \end{cmd}
      \item
      To update the group file for a particular filesystem:
      \begin{cmd}
$ sudo quotacheck -g [somefilesystem]
      \end{cmd}
      Use the \verb?-v? option to get more verbose output.
   \end{itemize}

\end{frame}

\cprotect\note{

   \textbf{quotacheck} is generally only run when quotas
   are initially turned on (or need to be updated).  The
   program may also be run when \textbf{fsck} reports
   errors in the filesystem when the system is starting
   up.
}


\begin{frame}
   {Turning Quotas On and Off}

   \begin{itemize}
      \item \textbf{quotaon} and \textbf{quotaoff} are used
      to turn filesystem quotas on and off
      \begin{cmd}
$ sudo qoutaon --help
  \end{cmd}
      \begin{response}
quotaon: Usage:
        quotaon [-guvp] [-F quotaformat] [-x state] -a
        quotaon [-guvp] [-F quotaformat] [-x state] filesys ...
-a, --all                turn quotas on for all filesystems
-f, --off                turn quotas off
-u, --user               operate on user quotas
-g, --group              operate on group quotas
-p, --print-state        print whether quotas are on or off
-x, --xfs-command=cmd    perform XFS quota command
-F, --format=formatname  operate on specific quota format
-v, --verbose            print more messages
-h, --help               display this help text and exit
-V, --version            display version information and exit
  \end{response}
      \item
      Note that these two programs are really one and the
      same and operate accordingly to which name they are
      called with.
   \end{itemize}

\end{frame}

\cprotect\note{

   For example:

   \begin{cmd}
$ sudo quotaon -av
   \end{cmd}
   \begin{response}
/dev/sda6 [/]: group quotas turned on
/dev/sda5 [/home]: user quotas turned on
   \end{response}
   \begin{cmd}
$ sudo quotaoff -av
   \end{cmd}
   \begin{response}
/dev/sda6 [/]: group quotas turned off
/dev/sda5 [/home]: user quotas turned off
   \end{response}
   \begin{cmd}
$ sudo quotaon -avu
   \end{cmd}
   \begin{response}
dev/sda5 [/home]: user quotas turned on
   \end{response}
   \begin{cmd}
$ sudo quotaoff -avg
   \end{cmd}
   \begin{response}
 /dev/sda6 [/]: group quotas turned off
   \end{response}

   Note also that quota operations will fail if the files
   \texttt{aquota.user} or \texttt{aquota.group} do not
   exist.
}



\begin{frame}
   {Examining Quotas}

   \begin{itemize}
      \item
      The \textbf{quota} utility is used to generate reports
      on quotas:
      \begin{itemize}
         \item \texttt{quota} (or \texttt{quota -u}) returns your
         current user quota.
         \item \texttt{quota -g} returns your current group quota
         \item The superuser may look at quotas for any user or
         group by specifying a user or group name.
      \end{itemize}
   \end{itemize}

\end{frame}

\cprotect\note{

   \begin{cmd}
$ sudo quota george
   \end{cmd}
   \begin{response}
 Disk quotas for user george (uid 1000):
  Filesystem blocks quota limit grace files quota limit grace
  /dev/sda5  837572   500  1000        5804   0       0
   \end{response}
   \begin{cmd}
 $ sudo quota gracie
   \end{cmd}
   \begin{response}
 Disk quotas for user gracie (uid 1001):
  Filesystem blocks quota limit grace files quota limit grace
   /dev/sda5  83757  5000 10000        5804     0     0
   \end{response}
}


\begin{frame}
   {Setting Quotas}

   \begin{itemize}

      \item
      Edit limits for \verb?username? :
      \begin{cmd}
$ sudo edquota -u [username]
        \end{cmd}

      \item
      Edit limits for \verb?groupname? :
      \begin{cmd}
$ sudo edquota -g [groupname]
        \end{cmd}

      \item
      Copy \verb?userproto?'s user quota values to
      \verb?username? :
      \begin{cmd}
$ sudo edquota -u -p [userproto] [username] 
        \end{cmd}

      \item
      Copy \verb?groupproto?'s group quota values to
      \verb?groupname? :
      \begin{cmd}
$ sudo edquota -g -p [groupproto] [groupname] 
        \end{cmd}

      \begin{itemize}
         \item
         The last two commands are useful for including in
         scripts which might be used to create new
         accounts and set quotas for them.
      \end{itemize}
      \item
      Set grace periods :
      \begin{cmd}
$ sudo edquota -t 
        \end{cmd}
   \end{itemize}

\end{frame}

\cprotect\note{


   Typing \textbf{edquota} brings up the quota editor. For
   the user or group specified a temporary file is created
   with a text representation of the current disk quotas
   for that user or group.

   Then an editor is invoked for that file and quotas may
   then be modified.  Once you leave the editor, the
   temporary file is read and the binary quota files adopt
   the changes.

   The only fields which can be edited in the quota are
   the soft and hard limits.  The other fields are
   informational only.

   Quotas for users and groups may be set for disk blocks
   and/or inodes.  In addition, soft and hard limits may
   be set as well as grace periods: Soft limits may be
   exceeded for a grace period.  Hard limits may never be
   exceeded.

   The grace period is set on a per-filesystem basis.
   \begin{cmd}
$ sudo edquota gracie
$ sudo edquota -t
   \end{cmd}

}


