\begin{exe} {Mounting Options}

   \begin{lfbox}[Fresh Partition or Loopback File]
      In this exercise you will need to either create a
      fresh partition, or use a loopback file.  The solution
      will differ slightly and we will provide details of
      both methods.
   \end{lfbox}
   \begin{enumerate}
      \item
      Use \textbf{fdisk} to create a new 250 MB
      partition on your system, probably on
      \filelink{/dev/sda}.  Or create a file full
      of zeros to use as a loopback file to simulate
      a new partition.

      \item
      Use \textbf{mkfs} to format a new filesystem on
      the partition or loopback file just created.  Do
      this three times, changing the block size each time.
      Note the locations of the superblocks, the
      number of block groups and any other pertinent
      information, for each case.

      \item
      Create a new subdirectory (say \filelink{/mnt/tempdir}) and
      mount the new filesystem at this location. Verify it
      has been mounted.

      \item
      Unmount the new filesystem, and then remount it
      as read-only.

      \item
      Try to create a file in the mounted directory.
      You should get an error here, why?

      \item
      Unmount the filesystem again.

      \item

      Add a line to your \filelink{/etc/fstab} file so
      that the filesystem will be mounted at boot
      time.

      \item
      Mount the filesystem.

      \item
      Modify the configuration for the new filesystem
      so that binary files may not be executed from
      the filesystem (change defaults to \verb?noexec? in
      the \filelink{/mnt/tempdir} entry).  Then remount
      the filesystem and copy an executable file
      (such as \filelink{/bin/ls})
      to \texttt{/mnt/tempdir} and try to run it.
      You should get an error: why?
   \end{enumerate}
   When you are done you will probably want to clean up
   by removing the entry from \filelink{/etc/fstab}.

   \begin{sol}

      \begin{info}[]
         \textbf{Physical Partition Solution}
      \end{info}
      \begin{enumerate}
         \item
         We won't show the detailed steps in \textbf{fdisk}, as
         it is all ground covered earlier.  We will assume the
         partition created is \filelink{/dev/sda11}, just to
         have something to show.
         \begin{cmd}
$ sudo fdisk /dev/sda
         \end{cmd}
         \begin{response}
.....
w
$ partprobe -s
         \end{response}
         Sometimes the \textbf{partprobe} won't work, and to
         be sure the system knows about the new partition
         you have to reboot.
         \item
         \begin{cmd}
$ sudo mkfs -t ext4         -v /dev/sda11
$ sudo mkfs -t ext4 -b 2048 -v /dev/sda11
$ sudo mkfs -t ext4 -b 4096 -v /dev/sda11
         \end{cmd}
         Note the \verb?-v? flag (verbose) will give the
         requested information; you will see that for a
         small partition like this the default is 1024
         byte blocks.
         \item
         \begin{cmd}
$ sudo mkdir /mnt/tempdir
$ sudo mount /dev/sda11 /mnt/tempdir
$ mount | grep tempdir
         \end{cmd}
         \item
         \begin{cmd}
$ sudo umount /mnt/tempdir
$ sudo mount -o ro /dev/sda11 /mnt/tempdir
         \end{cmd}
         If you get an error while unmounting, make
         sure you are not currently in the directory.
         \item
         \begin{cmd}
$ sudo touch /mnt/tempdir/afile
         \end{cmd}
         \item
         \begin{cmd}
$ sudo umount /mnt/tempdir
         \end{cmd}
         \item
         Put this line in \filelink{/etc/fstab}:
         \begin{cmd}
/dev/sda11 /mnt/tempdir ext4 defaults 1 2
         \end{cmd}
         \item
         \begin{cmd}
$ sudo mount /mnt/tempdir
$ sudo mount | grep tempdir
         \end{cmd}
         \item
         Change the line in \filelink{/etc/fstab} to:
         \begin{cmd}
/dev/sda11 /mnt/tempdir ext4 noexec 1 2
         \end{cmd}
         Then do:
         \begin{cmd}
$ sudo mount -o remount /mnt/tempdir
$ sudo cp /bin/ls /mnt/tempdir
$ /mnt/tempdir/ls
         \end{cmd}
         You should get an error here, why?
      \end{enumerate}

      \begin{info}[]
         \textbf{Loopback File Solution}
      \end{info}
      \begin{enumerate}
         \item
         \begin{cmd}
$ sudo dd if=/dev/zero of=/imagefile bs=1M count=250
         \end{cmd}
         \item
         \begin{cmd}
$ sudo mkfs -t ext4         -v
$ sudo mkfs -t ext4 -b 2048 -v /imagefile
$ sudo mkfs -t ext4 -b 4096 -v /imagefile
         \end{cmd}
         You will get warned that this is a file and
         not a partition, just proceed.

         Note the \verb?-v? flag (verbose) will give the
         requested information; you will see that for a
         small partition like this the default is 1024
         byte blocks.
         \item
         \begin{cmd}
$ sudo mkdir /mnt/tempdir
$ sudo mount -o loop /imagefile /mnt/tempdir
$ mount | grep tempdir
         \end{cmd}
         \item
         \begin{cmd}
$ sudo umount /mnt/tempdir
$ sudo mount -o ro,loop /imagefile /mnt/tempdir
         \end{cmd}
         If you get an error while unmounting, make
         sure you are not currently in the directory.
         \item
         \begin{cmd}
$ sudo touch /mnt/tempdir/afile
         \end{cmd}
         \item
         \begin{cmd}
$ sudo umount /mnt/tempdir
         \end{cmd}
         \item
         Put this line in \filelink{/etc/fstab}:
         \begin{configlst}[in \texttt{/etc/fstab}]
/imagefile /mnt/tempdir ext4 loop 1 2
         \end{configlst}
         \item
         \begin{cmd}
$ sudo mount /mnt/tempdir
$ sudo mount | grep tempdir
         \end{cmd}
         \item
         Change the line in \filelink{/etc/fstab} to:
         \begin{configlst}[in \texttt{/etc/fstab}]
/imagefile /mnt/tempdir ext4 loop,noexec 1 2
         \end{configlst}
         Then do:
         \begin{cmd}
$ sudo mount -o remount /mnt/tempdir
$ sudo cp /bin/ls /mnt/tempdir
$ /mnt/tempdir/ls
         \end{cmd}
         You should get an error here, why?
      \end{enumerate}
   \end{sol}
\end{exe}

