\begin{exe} {Filesystem Quotas}

   \begin{info}
      The subsection describing this material was marked as
      optional, so you may not have covered the material
      necessary to do this exercise.
   \end{info}

   \begin{enumerate}
      \item
      Change the entry in \filelink{/etc/fstab} for your new
      filesystem to use user quotas (change \verb?noexec? to
      \verb?usrquota? in the entry for
      \filelink{/mnt/tempdir}). Then remount the filesystem.
      \item
      Initialize quotas on the new filesystem, and then
      turn the quota checking system on.
      \item
      Now set some quota limits for the normal user
      account: a soft limit of 500 blocks and a hard limit
      of 1000 blocks.

      \item
      As the normal user, attempt to use \textbf{dd} to create some
      files to exceed the quota limits. Create
      \filelink{bigfile1} (200 blocks) and \filelink{bigfile2}
      (400 blocks).

      You should get a warning. Why?
      \item

      Create \filelink{bigfile3} (600 blocks).

      You should get an error message. Why?
      Look closely at the file sizes.
      \item
      Eliminate the persistent mount line you inserted in
      \filelink{/etc/fstab}.
   \end{enumerate}

   \begin{sol}

      \begin{enumerate}
         \item
         Change \filelink{/etc/fstab} to have one of the
         following two lines according to whether you
         are using a real partition or a loopback file:
         \begin{configlst}[in \texttt{/etc/fstab}]
/dev/sda11     /mnt/tempdir ext4 usrquota      1 2
/imagefile     /mnt/tempdir ext4 loop,usrquota 1 2
         \end{configlst}
         Then remount:
         \begin{cmd}
$ sudo mount -o remount /mnt/tempdir
         \end{cmd}
         \item
         \begin{cmd}
$ sudo quotacheck -u /mnt/tempdir
$ sudo quotaon -u /mnt/tempdir
$ sudo chown student.student /mnt/tempdir
         \end{cmd}
         (You won't normally do the line above, but we
         are doing it to make the next part easier).
         \item
         Substitute your user name for the
         \verb?student? user account.
         \item
         \begin{cmd}
$ sudo edquota -u student
         \end{cmd}
         \item
         \begin{cmd}
$ cd /mnt/tempdir
$ dd if=/dev/zero of=bigfile1 bs=1024 count=200
         \end{cmd}
         \begin{response}
200+0 records in
200+0 records out
204800 bytes (205 kB) copied, 0.000349604 s, 586 MB/s
         \end{response}
         \begin{cmd}
$ quota
         \end{cmd}
         \begin{response}
Disk quotas for user student (uid 500):
Filesystem blocks quota lim grace files qu lim gr
/dev/sda11    200   500  1000   1   0   0
         \end{response}
         \begin{cmd}
$ dd if=/dev/zero of=bigfile2 bs=1024 count=400
         \end{cmd}
         \begin{response}
sda11: warning, user block quota exceeded.
400+0 records in
400+0 records out
4096600 bytes (410 kB) copied, 0.000654847 s, 625 MB/s
         \end{response}
         \item

         Create \filelink{bigfile3} (600 blocks).

         \begin{cmd}
$ quota
         \end{cmd}
         \begin{response}
Disk quotas for user student (uid 500):
Filesystem blocks quota limit grace files qu lim gr
/dev/sda11    600*   500  1000 6days   2  0  0
         \end{response}
         \begin{cmd}
$ dd if=/dev/zero of=bigfile3 bs=1024 count=600
         \end{cmd}
         \begin{response}
sda11: write failed, user block limit reached.
dd: writing `bigfile3': Disk quota exceeded
401+0 records in
400+0 records out
409600 bytes (410 kB) copied, 0.00177744 s, 230 MB/s
         \end{response}
         \begin{cmd}
$ quota
         \end{cmd}
         \begin{response}
Disk quotas for user student (uid 500):
Filesystem blocks  quota limit grace files quota limit grace
/dev/sda11   1000*   500  1000 6days     3     0     0
         \end{response}
         \begin{cmd}
$ ls -l
         \end{cmd}
         \begin{response}
total 1068
-rw------- 1 root    root      7168 Dec 10 18:56 aquota.user
-rw-rw-r-- 1 student student 204800 Dec 10 18:58 bigfile1
-rw-rw-r-- 1 student student 409600 Dec 10 18:58 bigfile2
-rw-rw-r-- 1 student student 409600 Dec 10 19:01 bigfile3
drwx------ 2 root    root     16384 Dec 10 18:47 lost+found
-rwxr-xr-x 1 root    root     41216 Dec 10 18:52 more
         \end{response}
         Look closely at the file sizes.
         \item
         Get rid of the line in \filelink{/etc/fstab}.
      \end{enumerate}
   \end{sol}
\end{exe}

