\documentclass{lpiclab}

\RCS $Revision: 1.0 $

\usepackage{alltt,key}
%\usepackage{floatfig}
\usepackage{wrapfig}
%\usepackage[hang,bf,nooneline]{caption2}
\usepackage[flushleft]{caption2}

\ifx\pdftexversion\undefined \else
  \usepackage[pdfpagemode=None,pdfauthor={Nick Urbanik}]{hyperref}
\fi

\newcommand*{\screenwidth}{0.4\textwidth}
\newcommand*{\labTitle}{Compiling a kernel}
%\renewcommand*{\subject}{Operating Systems and Systems Integration}

\providecommand*{\DHCP}{\acro{DHCP}\xspace}

% \newenvironment{cmd}[1]{\begin{alltt}\$ \textbf{#1} \(\hookleftarrow\)}%
% {\end{alltt}}
% \newenvironment{rootcmd}[1]{\begin{alltt}\# \textbf{#1} \(\hookleftarrow\)}%
% {\end{alltt}}
% \newcommand{\ucmd}[1]{%
%   \texttt{\$ \textbf{#1} \(\hookleftarrow\)}%
% }
 
\newcommand*{\rootcmd}[1]{%
  \texttt{\# \textbf{#1} \(\hookleftarrow\)}%
}
 
\newcommand*{\cmd}[1]{%
  \texttt{\$ \textbf{#1} \(\hookleftarrow\)}%
}

\newcommand*{\cmdbox}[1]{%
  \mbox{\texttt{\$ \textbf{#1} \(\hookleftarrow\)}}%
}

\newcommand{\opt}[1]{%
  \textbf{\texttt{#1}}%
}
 

\begin{document}

\section{Aim}
\label{sec:aim}

We aim to be able to compile a Linux kernel.

\section{Background}
\label{sec:background}

In this laboratory the old DEC network cards use a driver that is
included in the kernel source code, but it is not built in the default
setup that we use in this laboratory.  We need this built as a
\emph{module} that can be loaded into the kernel so that we can use
the network card.

There are a number of steps in the process:

\begin{itemize}
\item We verify that the kernel source code is installed.
\item I prefer to build the kernel not as root, but as a normal user.
  We will change the ownership of the kernel source code to our own
  account.
\item We edit the Makefile and change the \texttt{EXTRAVERSION} name
  near the top so that the kernel will have a different name from the
  kernel provided by the distribution.
\item We copy a suitable configuration file from those provided by the
  distribution, or we can go through and choose the details of
  configuration ourselves, though this is quite time consuming, as
  there are many configuration options to choose.  The name of the
  configuration file is \texttt{.config}
\item We start a configuration program that provides a graphical user
  interface that edits the configuration file with \texttt{make xconfig}
\item We calculate the dependencies (which things need to be compiled)
  with \texttt{make dep}.
\item We build the kernel with \texttt{make bzImage}
\item We build the modules with \texttt{make modules}
\item We install the modules with \texttt{sudo make modules\_install}
\item We copy the kernel to the \texttt{/boot} directory
\item We also copy the \texttt{System.map} file and the
  \texttt{.config} files to the \texttt{/boot} directory.
\item Generate a \RAM disk file with mkinitrd.
\item We edit the GRUB configuration so we can boot our new kernel.
\item We boot into our new kernel and watch with a happy smile as
  everything works.
\end{itemize}


\section{Procedure}
\label{sec:procedure}

\subsection{Change the Ownership of the Source Code}
\label{sec:chown}

\begin{enumerate}
\item Notice the dot `.' at the end of the \texttt{chown} command.
  Use your own username instead of \texttt{jimmy}.
\begin{alltt}
\cmd{cd /usr/src}
\cmd{ls}
debug  linux-2.4  linux-2.4.21-15.EL  redhat
\cmd{cd linux-2.4.21-15.EL}
\cmd{chown -R jimmy.jimmy .}
\end{alltt}
We will call the current location the \emph{top level} of the source directory.
\item Let us clean up any other residue from previous compiles with
\par
\cmd{make clean}
\end{enumerate}


\subsection{Change the Name of the Kernel: Edit the \texttt{Makefile}}
\label{sec:edit-makefile}

\begin{enumerate}
\item With the editor of your choice (\texttt{emacs}, \texttt{gedit},
  \texttt{vi}, \texttt{nano}\ldots\,, edit the file \texttt{Makefile}
  in the top level directory, and
\item change the line

\begin{alltt}
EXTRAVERSION = -15.EL
\end{alltt}
to
\begin{alltt}
EXTRAVERSION = -15.ELde4x5
\end{alltt}
\end{enumerate}

\subsection{Get a Configuration File}
\label{sec:config-file}

\begin{enumerate}
\item Red Hat provide some configuration files in the \texttt{config}
  directory.  Get an appropriate configuration for the computer
  and\ldots
\begin{alltt}
\cmd{cd configs}
\cmd{ls}
kernel-2.4.21-athlon.config        kernel-2.4.21-ia32e.config
kernel-2.4.21-athlon-smp.config    kernel-2.4.21-ia64.config
kernel-2.4.21-i386-BOOT.config     kernel-2.4.21-ppc64.config
kernel-2.4.21-i386.config          kernel-2.4.21-ppc64iseries.config
kernel-2.4.21-i586.config          kernel-2.4.21-ppc64pseries.config
kernel-2.4.21-i586-smp.config      kernel-2.4.21-s390.config
kernel-2.4.21-i686.config          kernel-2.4.21-s390x.config
kernel-2.4.21-i686-hugemem.config  kernel-2.4.21-x86_64.config
kernel-2.4.21-i686-smp.config      kernel-2.4.21-x86_64-smp.config
\cmd{cp kernel-2.4.21-i686.config ../.config}
\end{alltt}
\ldots copy it to the name \texttt{.config} in the top level.
\item Have a look at the configuration file with \texttt{less} or your
  editor.
\end{enumerate}

\subsection{Edit the Configuration with \texttt{make xconfig}}
\label{sec:make-xconfig}

\begin{enumerate}
\item In the top level directory, type:

\cmd{make xconfig}

This will start a Tk program that allows you to select configuration
options.

\item Choose the menu item Network Interfaces
\item Find the item that corresponds the the \texttt{de4x5} module,
  and select \textbf{\texttt{m}} for \emph{module}
  You can click on the help buttons to find what each configuration
  option is for.
\item Save the configuration and exit the program.
\end{enumerate}

\subsection{Make the Dependencies}
\label{sec:make-dep}

\cmd{make dep}

\subsection{Build the Kernel}
\label{sec:make-bzImage}

\cmd{make bzImage}

\subsection{Build the Modules}
\label{sec:make-modules}

\cmd{make modules}

\subsection{Install the Modules}
\label{sec:make-modules-install}

\cmd{sudo make modules\_install}


\subsection{Copy the kernel to /boot}
\label{sec:copy-to-boot}

\begin{alltt}
\cmd{sudo cp -a arch/i386/boot/bzImage /boot/vmlinuz-2.4.21-15.ELde4x5}
\cmd{sudo cp -a System.Map /boot/System.map-2.4.21-15.ELde4x5}
\cmd{sudo cp -a .config /boot/config-2.4.21-15.ELde4x5}
\end{alltt}


\subsection{Make an RAM disk file with mkinitrd}
\label{sec:mkinitrd}

\begin{alltt}
\cmd{cd /boot}
\cmd{/sbin/mkinitrd -v initrd-2.4.21-15.ELde4x5.img 2.4.21-15.ELde4x5}
\end{alltt}

\subsection{Edit GRUB Configuration to Boot the New Kernel}
\begin{enumerate}
\item Edit \texttt{/boot/grub/grub.conf} (or
  \texttt{/boot/grub/menu.lst}) and copy the section for booting the
  old kernel
\item Edit it, changing the name of the kernel and initrd file to
  match what you have made
\item Boot the computer into your new kernel and rejoice!
\end{enumerate}

\end{document}
