\section{The Grand Unified Boot Loader (GRUB)}

\begin{frame}
   {The Grand Unified Boot Loader (GRUB)}

   \begin{itemize}
      \item Allows boot selection
      \begin{itemize}
         \item Can choose alternate operating systems
         \item Can choose alternate \textbf{Linux} kernels
         \item Can choose alternate \textbf{initramfs} images
      \end{itemize}
      \item Allows argument passing
      \begin{itemize}
         \item Can change an existing stanza in menu
         editing mode
         \item Can issue boot commands interactively on
         \textbf{GRUB} command line
      \end{itemize}
      \item Version 2 has replaced Version 1 on all major
      \textbf{Linux} distributions except for \textbf{RHEL 6}-based
      ones
   \end{itemize}

\end{frame}

\cprotect\note{

   Virtually all \textbf{x86}-based \textbf{Linux} systems
   (outside the embedded sphere) today use \textbf{GRUB}
   (\textbf{GR}and \textbf{U}nified \textbf{B}ootloader)
   to handle the early phases of system startup. Other
   platforms may have other equivalents, such as
   \textbf{ELILO} used on \textbf{EFI} systems such as
   \textbf{IA64} (\textbf{Itanium}), and \textbf{Das
      U-BOOT} used on many embedded configurations.

   Some important features of \textbf{GRUB} are:

   \begin{itemize}
      \item

      Alternative operating systems can be chosen at boot
      time.

      \item

      Alternative kernels and/or initial ramdisks can be
      chosen at boot time for a given operating system.

      \item

      Boot parameters can be easily changed at boot time
      without having to edit configuration files, etc. in
      advance.

   \end{itemize}
}

\begin{frame}
   {GRUB Versions}

   \begin{itemize}
      \item \textbf{GRUB 2}
      \begin{itemize}
         \item Used on all modern \textbf{Linux} distributions
         \item Configuration Files:
         \begin{kcode}
/boot/grub/grub.cfg
      or  /boot/grub2/grub.cfg
      or  /boot/efi/EFI/redhat/grub.cfg
/boot/grub2/grubenv      
/etc/default/grub
/etc/grub.d
         \end{kcode}
      \end{itemize}
      \item \textbf{GRUB 1}
      \begin{itemize}
         \item Only major distribution still using is
         \textbf{RHEL 6}
         \item Configuration Files:
         \begin{kcode}
/boot/grub/grub.conf
         \end{kcode}
         \item Philosophy the same, details quite different
      \end{itemize}
      \item
      We will concentrate on \textbf{GRUB 2}; version 1 is
      now legacy
   \end{itemize}

\end{frame}

\cprotect\note{

   While details are different between \textbf{GRUB 2}
   and the legacy Version 1, the basic philosophy is the same.

   At boot a basic configuration file is read:

   \filelink{/boot/grub/grub.cfg}

   or

   \filelink{/boot/grub2/grub.cfg}

   or

   \filelink{/boot/efi/EFI/redhat/grub.cfg}

   This file is auto-generated by \textbf{update-grub}
   (or \textbf{grub2-mkconfig}) based
   on configuration files in the \filelink{/etc/grub.d}
   directory and on \filelink{/etc/default/grub} and
   should not be edited by hand.  Usually these
   utilities are run from other distribution-supplied
   scripts used for updating or compiling \textbf{Linux}
   kernels.

   Once again the file is better off not being edited by
   hand. However, if you do make changes, most of the
   time they will be preserved.

}

\section{Interactive Selections with GRUB at Boot}
\begin{frame}
   {Interactive Selections with GRUB at Boot}
   \begin{itemize}
      \item Upon boot enters interactive shell
      \item Doing nothing picks default operating system and kernel
      \item Use up and down arrows for alternate selection
      \item Type \texttt{e} to enter interactive editor to change
      boot choices and parameters
      \item Changes will not be preserved in configuration files.
   \end{itemize}

\end{frame}

\cprotect\note{

   Upon system boot, after the initial POST and BIOS stages
   \textbf{GRUB} will be entered and display a menu
   containing a list of bootable images either from
   one or more \textbf{Linux} distributions or operating
   systems.  There may also be submenus with even more
   choices.

   Using up and down arrows and the \texttt{Enter} key the
   user can select the right boot option, or can wait for a
   configurable time period before the default choice is
   entered.

   However, you can do much more.  After selecting an
   entry, you can type \texttt{e} for edit and then enter
   into an interactive shell.  In this shell you can alter
   the \textbf{stanza} in the configuration file that
   describes that particular boot option.  Usually you do
   this to alter the \textbf{kernel command line}; for
   example adding the word \texttt{single} at the end of
   the command line will cause the system to boot in
   \textbf{single use mode} in order to take corrective
   actions.  Once the desired change is made you can hit
   the right key to make the system boot.

   At the bottom of the screen you will see displayed
   information on the exact key strokes, so there is no
   need to memorize.

   Note that any changes you make to the configuration are
   \textbf{not persistent} and will be lost on the next
   boot.  So for permanent changes, you need to change the
   actual files on the machine using the right utilities.

   It is also possible to enter a pure shell, rather than
   edit a particular stanza.  One can run a number of
   different commands and even try to re-install or repair
   \textbf{GRUB}.  If there are serious problems, like not
   being able to find a configuration file, \textbf{GRUB}
   reverts back to this command line mode and you may be
   able to rescue the system without resorting to rescue
   media.
}

\section{Installing GRUB}

\begin{frame}
   {Installing GRUB}

   \begin{itemize}
      \item The \textbf{GRUB} boot loader should be installed at
      system installation
      \item Can be reinstalled later at any time, with
      \textbf{grub2-install} or \textbf{grub-install}
      depending on distribution
      \item Install can also mean:
      \begin{itemize}
         \item Setting up the configuration files grub needs to operate
         \item Installing the needed utilities
      \end{itemize}
      \begin{cmd}
$ sudo grub2-install /dev/sda
      \end{cmd}
      \item
      Note on EFI multi-boot systems, you may have to
      run \textbf{efibootmgr} as well; things can be more complex.
      See the \textbf{man} page.
   \end{itemize}

\end{frame}

\cprotect\note{

   The word \textbf{installing} can have several different
   meanings with respect to \textbf{GRUB}:
   \begin{enumerate}
      \item
      Installing the \textbf{grub} program and associated
      utilities in their proper locations.  In \textbf{GRUB
         1} there was actually a program just called
      \textbf{grub}, but in \textbf{GRUB 2} there are a
      bunch of utilities with names like \textbf{grub2-*} or
      \textbf{grub-*}.
      \item
      Installing the files \textbf{GRUB} needs to operate at
      boot time, under either \filelink{/boot/grub} or
      \filelink{/boot/grub2}.  This is separate than the files
      the \textbf{Linux} kernel needs
      (\texttt{vmlinuz-*, initramfs-*})  which will need to be in
      the \filelink{/boot} directory as well.
      \item
      Installing \textbf{GRUB} as the \textbf{boot loader} in
      the system; usually this is done at the front of the
      entire hard disk, but can also be done in a partition.
   \end{enumerate}

   To reinstall, the exact procedure for doing so depends
   on \textbf{GRUB} version.
   It can be as easy as:
   \begin{cmd}
$ sudo grub2-install /dev/sda
   \end{cmd}
   Please read the \textbf{man page} carefully before running
   such a command; there are many options, and messing up
   \textbf{GRUB} can make your system un-bootable.

}


\begin{frame}
   {GRUB Device Nomenclature}

   \begin{itemize}
      \item
      Needed to access files at boot time since file systems
      not mounted
      \item
      The first hard drive is denoted as \verb?hd0?, the
      second as \verb?hd1?, etc,
      \item
      However, partitions start counting from 1:
      \begin{itemize}
         \item \filelink{sda1} is \verb?(hd0,1)?
         \item \filelink{sdc4} is \verb?(hd2,4)?
      \end{itemize}
   \end{itemize}

\end{frame}

\cprotect\note{

   Within the configuration file, each stanza has to
   specify what the \textbf{root} partition is; this is
   not the same as what we mean when we took about the
   root directory of the system.  In this context it means
   the partition that contains the kernel itself (in the
   \filelink{/boot} directory.)  For example it is very
   common to have \filelink{/boot} in its own partition,
   let us say \filelink{/dev/sda1}.

   It is also fine to do \verb?kernel (hd0,0)/vmlinuz? ....
   instead, and leave out the \verb?root? line.

   A quick look at \filelink{grub.cfg} should make it clear.

}


