\documentclass{ictlab}

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

\RCS $Revision: 1.16 $

\newcommand*{\labTitle}{Partitioning the Hard Disk}
\renewcommand*{\subject}{Operating Systems and Systems Integration}

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

A hard disk needs to be divided into one or more sections called
\emph{partitions}.  We will install a number of operating systems onto
our hard disks.  Each operating system needs at least one partition.
We will use the Linux \texttt{fdisk} program to create these
partitions today.  Later, in your subject \emph{Systems and Network
  Administration}, Albert will show you how to install Windows 2003
into some of these partitions.  Our aim for today is to create the
partitions necessary for installation of all these operating systems.

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


\subsection{Types of partition}
\label{sec:types}

On an \acro{IBM} \PC compatible, there are a few types of partition:

\noindent%
\begin{tabular}[t]{@{}ll@{}}
\toprule%
\textbf{type} & \textbf{location}\\
\midrule%
primary  & outside of any other partition \\
extended & outside of any other partition \\
logical  & inside an extended partition\\
\bottomrule
\end{tabular}

\vspace{2ex}

The total number of primary and extended partitions must be four or
less.  Also, the total number of partitions must be 15 or less.  So if
$p = \mbox{number of primary}, e = \mbox{number of extended}$ and $\ell =
\mbox{number of logical}$, then $p + e \leq 4$, and $p + e + \ell \leq 15$.

\subsection{Limitations of the original IBM PC BIOS}
\label{sec:limitations}

The computers we use are compatible with the original \acro{IBM} \PC.  The
\BIOS (Basic Input Output System) also remains compatible with the
original machine, and has the following limitations:

\noindent%
\begin{tabular}[t]{@{}lcc@{}}
\toprule%
\textbf{parameter} & \textbf{number of bits} & \textbf{maximum  value}\\
\midrule%
cylinders & 10  & 1023\\
heads & 8 & 255\\
sectors & 6 & 63\\
\bottomrule
\end{tabular}

\vspace{2ex}

To boot an operating system on a PC, the \BIOS must be able to load
the first part of the operating system.  The first part of the
operating system must be on a location on the hard disk within these
limitations.  In particular, with older machines, without an
\emph{extended} \BIOS, the boot files of the operating system must be
entirely below cylinder 1024, or the computer may not be able to
boot.  However, newer machines, such as those in our lab, have an
extended \BIOS that gets around these limitations.

\subsection{Disk and partition naming scheme in Linux}
\label{sec:naming-scheme}

The motherboards of the computers in the lab have two 40-pin \IDE
connectors: one is called the \emph{primary} \IDE bus, the other the
\emph{secondary}.  A ribbon cable connects to each of these
connectors.  There are two female sockets on each cable.  One connects
to a disk configured as the \emph{master}, the other to the
\emph{slave}.  Jumpers on the hard disk determine whether the disk is
the master or slave.

The naming scheme for \IDE disks is:

\noindent%
\begin{tabular}[t]{@{}ccc@{}}
  \toprule%
  \textbf{name} & \textbf{primary/secondary} & \textbf{master/slave}\\
  \midrule%
  hda & primary & master \\
  hdb & primary & slave \\
  hdc & secondary & master \\
  hdd & secondary & slave\\
  \bottomrule
\end{tabular}

\vspace{2ex}

Partitions are named with the first three letters being that of the
hard disk.  Added to this is a number.  A primary partition may be
numbered 1 to 4 (i.e., on our hard disks, hda1, hda2, hda3 or hda4).
Logical partitions start with the number 5, so on hda, the logical
partitions are called hda5, hda6, hda7,\ldots

\subsection{Our partitioning scheme}
\label{sec:scheme}

The partitioning scheme we use here will look like
figure~\vref{fig:partitioning-scheme}.

\begin{figure}[htb]
  \centering%
  \noindent%
  \includegraphics[scale=0.7]{partitioning-scheme-ext-2003}
  
  \caption{The partioning scheme we will use for our hard disk.}
  \label{fig:partitioning-scheme}  
\end{figure}

% \vspace{2ex}

We will create all these partitions today.

We will use the Linux installation boot disk as a \emph{rescue disk}.
This will boot a basic Linux system independent of the local hard
disks, suitable for doing emergency repairs to an installed operating
system.

We will use this to run \texttt{fdisk} and partition the removable
hard disk.

We begin by making two floppy disks: a boot disk and a network driver
disk.

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


\subsection{Making the Two Boot Floppies}
\label{sec:boot-floppies}

\begin{enumerate}
\item Either make the two floppy disks yourself or take them from the
  technician or from the lecturer.
  \begin{explanation}
    How to make a the two floppy disks?  Boot the lab machine into Linux,
    change to the network drive on \texttt{/home/nfs/redhat-9/images},
    and put a \emph{good} floppy disk into the drive.  You should format
    each disk first to verify that it has no bad sectors:
\begin{alltt}
$ \textbf{fdformat /dev/fd0}
\end{alltt}%$
If you get any errors, throw that floppy disk away and get another
one.  Do the same with the second disk.

Then use the \texttt{dd} command to create the boot disk from the disk
image on our network drive:
\begin{alltt}
$ \textbf{cd /home/nfs/redhat-9/images}
$ \textbf{dd if=bootdisk.img of=/dev/fd0 bs=1440k}
\end{alltt}
    When the floppy light is off, you have created your boot floppy.

    Then put in the second floppy and make the network driver disk:
\begin{alltt}
$ \textbf{dd if=drvnet.img of=/dev/fd0 bs=1440k}
\end{alltt}%$
  You can read more about the \texttt{dd} command if you type:
\begin{alltt}
$ \textbf{man dd}    
\end{alltt}%$
  \end{explanation}
\end{enumerate}


\subsection{Removable Hard Disks}
\label{sec:removable-hard-disks}

\textbf{Hard disks are very delicate.}  Treat them as if they were
very fragile and very expensive (they are!).  \textbf{Never} plug or
unplug a removable hard disk in while the power is on.  \eemph{Wait at least
fifteen seconds before putting the hard disk in or removing it from
the computer after turning off the power.}

\begin{enumerate}
\item Turn off the computer, and wait at least 15 seconds.
  
\item Install the removable hard disk.  Push it in \emph{firmly} with
  both thumbs until you are sure it is pushed in all the way.  This
  will be the master device on the primary IDE bus.

  Most people do not push the hard disk all the way in the first time!
\end{enumerate}


\subsection{Rescue Mode}
\label{sec:rescue-mode}

\begin{enumerate}
\item Put the floppy disk into the drive and reboot the machine.
\item At the \texttt{boot:} prompt, enter linux rescue:
\begin{alltt}
boot: \textbf{linux rescue}
\end{alltt}

\item Accept defaults for language and keyboard.


\item When asked ``What type of media contains the rescue image?''
  select ``\texttt{NFS image}''.

\item At the message ``No Driver found'', select ``\texttt{Use a
    driver disk}''
  
\item For ``Driver Disk Source'', select \texttt{fd0} (the floppy
  disk), rather than \texttt{hdb}.  What is \texttt{hdb}?
  \answerbox{The \CDROM.}

\item Insert the network driver disk when requested.

\item For ``Network Device'', choose \texttt{eth0}.
  \begin{explanation}
    Note that the computers in this lab have two network cards.
  \end{explanation}
\item If you are asked to choose the network driver, select the Intel
  EtherExpress Pro 100 (e100).


%   \begin{figure}[htb]
%     \centering%
%     \includegraphics[width=0.9\linewidth]{http}
%     \caption{The screen where you select using HTTP for the network
%       installation method.}
%     \label{fig:ftp}
%   \end{figure}

%% \item For the host name of the \NFS server, put:
%% \begin{verbatim}
%% nicku.org
%% \end{verbatim}
%% For the installation directory, put:
%% \begin{verbatim}
%% /var/ftp/pub/rh-9-updated
%% \end{verbatim}

%   See
%   figure~\vref{fig:ftp}.

  \begin{figure}[htb]
    \centering%
    \includegraphics[width=0.9\linewidth]{dhcp-choose}
    \caption{The screen where you select using DHCP for TCP/IP parameters.}
    \label{fig:dhcp-config}
  \end{figure}
  
\item When asked for the IP address of the computer, accept the
  default of \texttt{DHCP}.  See
  figure~\vref{fig:dhcp-config}.  If this does not immediately
  succeed, click on ``\texttt{Back}'' and choose \texttt{eth1}.  If
  that does not work, check the connection of the network cable to the
  Ethernet socket on the motherboard.

\item For ``\NFS server name'', put \texttt{nicku.org}

\item For ``Red Hat directory'', put
  \texttt{/var/ftp/pub/rh-9-updated}

  
\item When asked if you want to mount the Linux system that is
  installed on the local hard disk, select ``\texttt{Skip}''.
  \begin{explanation}
    In many other cases, for example, when using the rescue disk to
    fix some problem on a system that is already installed, it is
    often helpful to allow the rescue disk to mount that installation.
  \end{explanation}
\end{enumerate}

%   See figure~\ref{fig:select-csalinux}.
%   \begin{figure}[htb]
%     \centering%
%     \includegraphics[width=0.9\linewidth]{select-csalinux}
%     \caption{The screen where you select the server to do the network
%       installation from.}
%     \label{fig:select-csalinux}
%   \end{figure}

%% \item Select \textsf{Manually partition with fdisk [experts only]}.
%%   Yes, we are experts!

%% \item Get a shell prompt by pressing the key combination
%%   \key{Ctrl-Alt-F2}
%%   \begin{explanation}
%%     You can switch back to the graphical screen any time by pressing
%%     \key{Ctrl-Alt-F7}
%%   \end{explanation}

%% \item When asked what disk you want to install on, select
%%   \textsf{/dev/hda}.  This is \textbf{very important}; do not
%%   partition \textsf{/dev/hdc}, or Henry the technician will need to
%%   stay back and re-install the operating system for the other classes;
%%   he will be very upset!!!  \emph{Be very careful}.
%%   \begin{explanation}
%%     If you do not see \texttt{hda} as an option, then there are a few
%%     possibilities:
%%     \begin{itemize}
%%     \item Your hard disk is not pushed all the way in.  Turn off the
%%       computer, wait 15 seconds, then push it in, and start again;
%%       \emph{or}
%%     \item Your hard disk jumpers are not set as \emph{master}.  Verify
%%     that this is the case.  Do not use the \emph{cable select} or
%%     \emph{slave} jumper settings.
%%     \end{itemize}
%%   \end{explanation}

  

\subsection{Running \texttt{fdisk}}
\label{sec:fdisk}

\begin{enumerate}
\item \emph{Carefully} start the \texttt{fdisk} program running on
  your removable hard disk:
\begin{alltt}
# \textbf{fdisk /dev/hda}    
\end{alltt}
Make sure you type \texttt{/dev/hda}.  This is \textbf{very
  important}; do not partition \texttt{/dev/hdc}, or Henry the system
administrator will need to stay back and re-install the operating
system for the other classes; he will be very upset!!!  \emph{Be very
  careful}.
  \begin{explanation}
    If you get an error message:
\begin{verbatim}
Unable to open /dev/hda
\end{verbatim}
    then there are a few possibilities:
    \begin{itemize}
    \item Your hard disk is not pushed all the way in.  Turn off the
      computer, wait 15 seconds, then push it in, and start again;
      \emph{or}
    \item Your hard disk jumpers are not set as \emph{master}.  Verify
    that this is the case.  Do not use the \emph{cable select} or
    \emph{slave} jumper settings.
    \end{itemize}
  \end{explanation}

\item The lecturer will demonstrate the partitioning procedure.  Make
  sure that you \textbf{ask questions} if you are unsure.  If you make a
  mistake and partition the wrong hard disk, you will upset many
  people.

  The common \texttt{fdisk} commands that you will use are:

  \noindent%
  \begin{tabularx}{\linewidth}[t]{@{}clY@{}}
    \toprule%
    \textbf{command} & \textbf{name} & \textbf{action}\\
    \midrule%
    \texttt{m} & \textbf{m}enu & show a list of all the commands\\
    \texttt{p} & \textbf{p}rint & display the partition table\\
    \texttt{n} & \textbf{n}ew partition & create a new partition\\
    \texttt{d} & \textbf{d}elete & delete a partition (useful if you
    make a mistake!)\\
    \texttt{a} & \textbf{a}ctive & make a partition active\\
    \texttt{q} & \textbf{q}uit & exit \emph{without saving} the
    table.  Great if you really mess it up!\\
    \texttt{t} & \textbf{t}ype & set the \textbf{t}ype of partition\\
    \texttt{w} & \textbf{w}rite & Write changes to the disk.  After
    that, it's very hard to undo your changes, so
    think three times before pressing \texttt{w}.\\
    \bottomrule
  \end{tabularx}
  
\item Use the \textbf{p}rint command to display the partition table
  first.
  
\item Delete any partitions that are \emph{obviously} the wrong size.
  \eemph{Be \emph{very careful} NOT to delete the partition that
  contains your installation of Windows\@.}  \emph{Think} before you
  partition.  Do \emph{not} blindly follow this procedure if you do not
  understand what you are doing.
  
  Here is the sequence of commands I typed to destroy all the
  previously exising partitions. (Note that since I do not have Windows
  installed on my hard disk, I deleted all the partitions first):
\begin{alltt}\small
Command (m for help): \textbf{d}
Partition number (1-9): \textbf{9}

Command (m for help): \textbf{d}
Partition number (1-8): \textbf{8}

Command (m for help): \textbf{d}
Partition number (1-7): \textbf{7}

Command (m for help): \textbf{d}
Partition number (1-6): \textbf{6}

Command (m for help): \textbf{d}
Partition number (1-5): \textbf{5}

Command (m for help): \textbf{d}
Partition number (1-5): \textbf{2}

Command (m for help): \textbf{d}
Selected partition \textbf{1}
\end{alltt}

\item Here are the \texttt{fdisk} commands I used to create the
  partition table:
\begin{alltt}\small
Command (m for help): \textbf{p}

Disk /dev/hda: 41.1 GB, 41174138880 bytes
240 heads, 63 sectors/track, 5318 cylinders
Units = cylinders of 15120 * 512 = 7741440 bytes

   Device Boot    Start       End    Blocks   Id  System

Command (m for help): \textbf{n}
Command action
   e   extended
   p   primary partition (1-4)
\textbf{p}
Partition number (1-4): \textbf{1}
First cylinder (1-5318, default 1): 
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-5318, default 5318): \textbf{+1g}

Command (m for help): \textbf{p}

Disk /dev/hda: 41.1 GB, 41174138880 bytes
240 heads, 63 sectors/track, 5318 cylinders
Units = cylinders of 15120 * 512 = 7741440 bytes

   Device Boot    Start       End    Blocks   Id  System
/dev/hda1             1       130    982768+  83  Linux

Command (m for help): \textbf{t}
Selected partition 1
Hex code (type L to list codes): \textbf{l}

 0  Empty           1c  Hidden Win95 FA 70  DiskSecure Mult bb  Boot Wizard hid
 1  FAT12           1e  Hidden Win95 FA 75  PC/IX           be  Solaris boot   
 2  XENIX root      24  NEC DOS         80  Old Minix       c1  DRDOS/sec (FAT-
 3  XENIX usr       39  Plan 9          81  Minix / old Lin c4  DRDOS/sec (FAT-
 4  FAT16 <32M      3c  PartitionMagic  82  Linux swap      c6  DRDOS/sec (FAT-
 5  Extended        40  Venix 80286     83  Linux           c7  Syrinx         
 6  FAT16           41  PPC PReP Boot   84  OS/2 hidden C:  da  Non-FS data    
 7  HPFS/NTFS       42  SFS             85  Linux extended  db  CP/M / CTOS / .
 8  AIX             4d  QNX4.x          86  NTFS volume set de  Dell Utility   
 9  AIX bootable    4e  QNX4.x 2nd part 87  NTFS volume set df  BootIt         
 a  OS/2 Boot Manag 4f  QNX4.x 3rd part 8e  Linux LVM       e1  DOS access     
 b  Win95 FAT32     50  OnTrack DM      93  Amoeba          e3  DOS R/O        
 c  Win95 FAT32 (LB 51  OnTrack DM6 Aux 94  Amoeba BBT      e4  SpeedStor      
 e  Win95 FAT16 (LB 52  CP/M            9f  BSD/OS          eb  BeOS fs        
 f  Win95 Ext'd (LB 53  OnTrack DM6 Aux a0  IBM Thinkpad hi ee  EFI GPT        
10  OPUS            54  OnTrackDM6      a5  FreeBSD         ef  EFI (FAT-12/16/
11  Hidden FAT12    55  EZ-Drive        a6  OpenBSD         f0  Linux/PA-RISC b
12  Compaq diagnost 56  Golden Bow      a7  NeXTSTEP        f1  SpeedStor      
14  Hidden FAT16 <3 5c  Priam Edisk     a8  Darwin UFS      f4  SpeedStor      
16  Hidden FAT16    61  SpeedStor       a9  NetBSD          f2  DOS secondary  
17  Hidden HPFS/NTF 63  GNU HURD or Sys ab  Darwin boot     fd  Linux raid auto
18  AST SmartSleep  64  Novell Netware  b7  BSDI fs         fe  LANstep        
1b  Hidden Win95 FA 65  Novell Netware  b8  BSDI swap       ff  BBT            
Hex code (type L to list codes): \textbf{c}
Changed system type of partition 1 to c (Win95 FAT32 (LBA))

Command (m for help): \textbf{p}

Disk /dev/hda: 41.1 GB, 41174138880 bytes
240 heads, 63 sectors/track, 5318 cylinders
Units = cylinders of 15120 * 512 = 7741440 bytes

   Device Boot    Start       End    Blocks   Id  System
/dev/hda1             1       130    982768+   c  Win95 FAT32 (LBA)

Command (m for help): \textbf{n}
Command action
   e   extended
   p   primary partition (1-4)
\textbf{e}
Partition number (1-4): \textbf{2}
First cylinder (131-5318, default 131): 
Using default value 131
Last cylinder or +size or +sizeM or +sizeK (131-5318, default 5318): 
Using default value 5318

Command (m for help): \textbf{p}

Disk /dev/hda: 41.1 GB, 41174138880 bytes
240 heads, 63 sectors/track, 5318 cylinders
Units = cylinders of 15120 * 512 = 7741440 bytes

   Device Boot    Start       End    Blocks   Id  System
/dev/hda1             1       130    982768+   c  Win95 FAT32 (LBA)
/dev/hda2           131      5318  39221280    5  Extended

Command (m for help): \textbf{t}
Partition number (1-5): \textbf{2}
Hex code (type L to list codes): \textbf{f}
Changed system type of partition 2 to f (Win95 Ext'd (LBA))

Command (m for help): \textbf{p}

Disk /dev/hda: 41.1 GB, 41174138880 bytes
240 heads, 63 sectors/track, 5318 cylinders
Units = cylinders of 15120 * 512 = 7741440 bytes

   Device Boot    Start       End    Blocks   Id  System
/dev/hda1             1       130    982768+   c  Win95 FAT32 (LBA)
/dev/hda2           131      5318  39221280    f  Win95 Ext'd (LBA)

Command (m for help): \textbf{n}
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
\textbf{l}
First cylinder (131-5318, default 131): 
Using default value 131
Last cylinder or +size or +sizeM or +sizeK (131-5318, default 5318): \textbf{+3g}

Command (m for help): \textbf{p}

Disk /dev/hda: 41.1 GB, 41174138880 bytes
240 heads, 63 sectors/track, 5318 cylinders
Units = cylinders of 15120 * 512 = 7741440 bytes

   Device Boot    Start       End    Blocks   Id  System
/dev/hda1             1       130    982768+   c  Win95 FAT32 (LBA)
/dev/hda2           131      5318  39221280    f  Win95 Ext'd (LBA)
/dev/hda5           131       519   2940808+  83  Linux

Command (m for help): \textbf{t}
Partition number (1-6): \textbf{5}
Hex code (type L to list codes): \textbf{7}
Changed system type of partition 5 to 7 (HPFS/NTFS)

Command (m for help): \textbf{p}

Disk /dev/hda: 41.1 GB, 41174138880 bytes
240 heads, 63 sectors/track, 5318 cylinders
Units = cylinders of 15120 * 512 = 7741440 bytes

   Device Boot    Start       End    Blocks   Id  System
/dev/hda1             1       130    982768+   c  Win95 FAT32 (LBA)
/dev/hda2           131      5318  39221280    f  Win95 Ext'd (LBA)
/dev/hda5           131       519   2940808+   7  HPFS/NTFS

Command (m for help):
\end{alltt}

\item The finished partition table should look something like this:
\begin{alltt}
Command (m for help): \textbf{p}

Disk /dev/hda: 41.1 GB, 41174138880 bytes
240 heads, 63 sectors/track, 5318 cylinders
Units = cylinders of 15120 * 512 = 7741440 bytes

   Device Boot    Start       End    Blocks   Id  System
/dev/hda1   *         1       130    982768+   c  Win95 FAT32 (LBA)
/dev/hda2           131      5318  39221280    f  Win95 Ext'd (LBA)
/dev/hda5           131       519   2940808+   7  HPFS/NTFS
/dev/hda6           520       908   2940808+   7  HPFS/NTFS
/dev/hda7           909      1297   2940808+   7  HPFS/NTFS
/dev/hda8          1298      1363    498928+  82  Linux swap
/dev/hda9          1364      2656   9775048+  83  Linux
\end{alltt}
\begin{explanation}
  Note that the type of the swap partition is ``83 Linux swap''.
\end{explanation}

\item When the partitioning procedure is finished and you have pressed
  \key{w} to \textbf{w}rite your new partition table, then:
  \begin{enumerate}
  \item type the \texttt{sync} (short for \emph{synchronise}) command
    a few times to ensure that the memory buffers are written to the
    hard disk before you shut down the computer.
  \item type \texttt{exit}, and turn off the power on the computer
    when requested.
  \item Wait 15 seconds before removing the hard disk and returning it
    to the cabinet at the end of the class.
  \item Answer the questions in section~\vref{sec:review-questions}.
  \end{enumerate}
\end{enumerate}

\clearpage
\section{Review Questions}
\label{sec:review-questions}

A system administrator is given a disk partitioned as shown in
figure~\vref{fig:partitioning-scheme-silly}.
\begin{figure}[htb]
  \centering%
  \noindent%
  \includegraphics[scale=0.7]{partitioning-scheme-silly}
  
  \caption{A partioning scheme.  We want to add two more partitions.}
  \label{fig:partitioning-scheme-silly}  
\end{figure}
\begin{enumerate}
\item Can you add two partitions, if the \NTFS and \FAT{}32 partitions
  all contain data?
\begin{biganswerbox}[1cm]%
  \begin{solution}%
  \end{solution}%
\end{biganswerbox}
\item What would you do if you were the system administrator?
\begin{biganswerbox}[4cm]%
  \begin{solution}%
  \end{solution}%
\end{biganswerbox}
\item If you were creating the partitions originally, how would you
  have done it?
\begin{biganswerbox}[5cm]%
  \begin{solution}%
  \end{solution}%
\end{biganswerbox}
\end{enumerate}
\end{document}
