\section{Sizing up partitions}

\begin{frame}
   {Sizing up Partitions}

   \begin{itemize}
      \item Most \textbf{Linux} systems should use a minimum of two
      partitions:

      \textbf{root} (\filelink{/})
      \begin{itemize}
         \item Used for the filesystem
         \item Most \textbf{Linux} installations will have more
         than one filesystem
         \item It is somewhat inconvenient to re-size (can use
         \textbf{LVM} when possible)
      \end{itemize}

      \textbf{Swap}
      \begin{itemize}
         \item Used as an extension of physical memory
         \item A common choice is equal to \textbf{RAM} size
         \item May have multiple swap partitions as well as swap files

      \end{itemize}
      \item Some distributions, such as \textbf{Ubuntu}, default to
      a swap file rather than a partition, but:
      \begin{itemize}
         \item More flexible
         \item More dangerous if error or bug
      \end{itemize}

   \end{itemize}

\end{frame}

\cprotect\note{

   Most installations will have more than one filesystem on
   more than one partition, which are joined together at
   \textbf{mount points}.

   It is difficult with most filesystem types to resize the
   root partition; using \textbf{LVM} (discussed later)
   can make this easier.

   While it is certainly possible to run \textbf{Linux}
   with just the root partition, most systems use more
   partitions to allow for easier backups, more efficient
   use of disk drives, and better security.

   The usual recommendation is swap size should be equal to
   physical memory in size; sometimes twice that is
   recommended.  However, the correct choice depends on the
   related issues of system use scenarios as well as
   hardware capabilities.

   Adding more and more swap will not necessarily
   help because at a certain point it becomes useless.
   One will need to either add more memory or
   re-evaluate the system setup.

}
\section{Backing Up and Restoring Partition Tables}
\begin{frame}
   {Backing Up and Restoring Partition Tables}

   \begin{itemize}
      \item
      \textbf{MBR}
      \begin{itemize}
         \item Use the \textbf{dd} program:
         \item The following command will backup the \textbf{MBR} (along
         with the partition table)
         \begin{cmd}
$ dd if=/dev/sda of=mbrbackup  bs=512 count=1
         \end{cmd}
         \item The \textbf{MBR} can be restored using the following
         \begin{cmd}
$ sudo dd if=mbrbackup of=/dev/sda bs=512 count=1
         \end{cmd}
      \end{itemize}
      \item \textbf{GPT}
      \begin{itemize}
         \item Use \textbf{sgdisk} which can also be used on
         \textbf{MBR} systems
         \begin{cmd}
$ sudo sgdisk --backup-file=gptbackup /dev/sda
$ sudo sgdisk --load-backup-file=gptbackup /dev/sda
         \end{cmd}
      \end{itemize}
   \end{itemize}
\end{frame}

\cprotect\note{
   \small{

      Always assume changing
      the disk partition table might eliminate all data in
      all filesystems (It should not, but be
      cautious!).

      Thus, it is always prudent to make a
      backup of all data (that is not already backed up)
      before doing any of this type of work.
      For \textbf{MBR} systems, \textbf{dd} can be
      used for converting and copying files.  Be
      careful in using \textbf{dd}: A simple typing error or
      misused option could destroy your entire disk.
      The above \textbf{dd} commands only copy the primary partition
      table; they do not deal with any partition tables
      stored in the other partitions (for extended
      partitions, etc.)

      For \textbf{GPT} systems it is best to use the \textbf{sgdisk}
      tool as in:

      \begin{cmd}
x8:/tmp>sudo sgdisk -p /dev/sda
   \end{cmd}
      \begin{responsevar}{\tiny}
Disk /dev/sda: 1000215216 sectors, 476.9 GiB
Model: SAMSUNG MZNLN512
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): DBDBE747-8392-4B62-97AA-6214490073DC
Partition table holds up to 128 entries
....
Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048          534527   260.0 MiB   EF00  EFI System Partition
   2          534528          567295   16.0 MiB    0C01  Microsoft reserved ...
....
   \end{responsevar}
      Note if run on a pure \textbf{MBR} system:
      \begin{cmd}
c8:/tmp>sudo sgdisk -p /dev/sda
 \end{cmd}
      \begin{responsevar}{\tiny}
***************************************************************
Found invalid GPT and valid MBR; converting MBR to GPT format
in memory. 
***************************************************************
Disk /dev/sda: 500118192 sectors, 238.5 GiB
Model: Crucial_CT256MX1
Sector size (logical/physical): 512/4096 bytes
....
   \end{responsevar}
   }
}



