\section{Working with Logical Volumes}

\begin{frame}
   {Logical Volume Utilities}

   \begin{figure}[H]
      \includegraphics[width=0.975\textwidth]{IMAGES/sbinlvm}
      \caption{Logical Volume Utilities}
   \end{figure}


\end{frame}

\cprotect\note {

   There are a number of utilities that manipulate logical
   volumes.  Unsurprisingly, they all begin with
   \textbf{lv}.  We will discuss the most commonly used
   ones, but a short list can be obtained by:
   \begin{cmd}
$ ls -lF /sbin/lv*
   \end{cmd}

   These utilities are in \filelink{/sbin} not
   \filelink{/usr/sbin} as they may be needed either for
   boot or repair and recovery.

   Most of them are symbolically linked to \textbf{lvm}, a
   Swiss army knife program that does all the work but
   figures out what it is being asked to do based on the
   name it is invoked with.  This is also true for most of
   the \textbf{pv*} and \textbf{vg*} utilities as you can
   verify easily enough.

   \begin{figure}[H]
      \includegraphics[width=0.975\textwidth]{IMAGES/sbinpv}
      \caption{Physical Volume Utilities}
   \end{figure}

}


\begin{frame}
   {Creating Logical Volumes}

   \begin{enumerate}
      \item Create partitions on disk drives (type
      \texttt{8e} in \textbf{fdisk}) .
      \item Create physical volumes from the partitions.
      \item Create the volume group.
      \item Allocate logical volumes from the volume group.
      \item Format the logical volumes.
      \item Mount the logical volumes (also update
      \filelink{/etc/fstab} as needed).
   \end{enumerate}

\end{frame}

\cprotect\note{

   \textbf{lvcreate} allocates logical volumes from within
   volume groups.  The size can be specified either in
   bytes or number of extents (remember they are 4 MB by
   default).  Names can be anything desired.

   \textbf{lvdisplay} reports on available logical volumes

   Filesystems are placed in logical volumes and are
   formatted with \textbf{mkfs} as usual.

   For example, assuming one has already created
   partitions \filelink{/dev/sdb1} and
   \filelink{/dev/sdc1} and given them type \texttt{8e},
   the steps involved in setting up and using a new
   logical volume are:

   \begin{cmd}
$ sudo pvcreate /dev/sdb1
$ sudo pvcreate /dev/sdc1
$ sudo vgcreate -s 16M vg /dev/sdb1
$ sudo vgextend vg /dev/sdc1
$ sudo lvcreate -L 50G -n mylvm vg
$ sudo mkfs -t ext4 /dev/vg/mylvm
$ mkdir /mylvm
$ sudo mount /dev/vg/mylvm /mylvm
   \end{cmd}

   Be sure to add the line
   \begin{kcode}
/dev/vg/mylvm /mylvm ext4 defaults 1 2
   \end{kcode}
   to \filelink{/etc/fstab} to make this a persistent
   mount.

}

\begin{frame}
   {Displaying Logical Volumes}

   \begin{itemize}
      \item \textbf{pvdisplay} - show physical volumes
      \begin{cmd}
$ pvdisplay
$ pvdisplay /dev/sda5
      \end{cmd}
      \item \textbf{vgdisplay} - show volume groups
      \begin{cmd}
$ vgdisplay
$ vgdisplay /dev/vg0
      \end{cmd}
      \item \textbf{lvdisplay} - show logical volumes
      \begin{cmd}
$ lvdisplay
$ lvdisplay /dev/vg0/lvm1
      \end{cmd}
   \end{itemize}

\end{frame}

\cprotect\note{

   \textbf{pvdisplay} is for showing one or
   more physical volumes.  If you leave off physical
   volume name, it lists all physical volumes.

   \textbf{vgdisplay} is for showing one or
   more volume groups.  If you leave off the volume group
   name, it lists all volume groups.

   \textbf{lvdisplay} is for showing one or
   more logical volumes.  If you leave off the logical
   volume name, it lists all logical volumes.

   \begin{figure}[H]
      \includegraphics[width=0.9\textwidth]{IMAGES/sbinvg}
      \caption{Volume Group Utilities}
   \end{figure}

}



