% Linux Installation and Getting Started    -*- TeX -*-
% fdisk.tex
% Copyright (c) 1992-1994 by Matt Welsh <mdw@sunsite.unc.edu>
%
% This file is freely redistributable, but you must preserve this copyright 
% notice on all copies, and it must be distributed only as part of "Linux 
% Installation and Getting Started". This file's use is covered by the 
% copyright for the entire document, in the file "copyright.tex".

\subsection{Creating Linux partitions}
\namedlabel{sec-install-linux-fdisk}{Creating Linux partitions}

\index{fdisk@{\tt fdisk}|(}
\index{partitions!fdisk@{\tt fdisk}|(}

Now you are ready to create Linux partitions with the {\tt fdisk} command.
As described in Section~\ref{sec-install-linux-reqs}, in general you
will need to create at least one partition for the Linux software itself, and
another partition for swap space.

After booting the installation media, run {\tt fdisk} by typing
\begin{tscreen}
fdisk \cparam{drive}
\end{tscreen}
where \cparam{drive} is the Linux device name 
of the drive you plan to add
partitions to (see Table~\ref{table-part-names}). 
For instance, if you want to run {\tt fdisk} 
on the first SCSI disk in your system, use the command {\tt fdisk /dev/sda}. 
{\tt /dev/hda} (the first IDE drive) is the default if you don't specify one.

If you are creating Linux partitions on more than one drive, run {\tt fdisk}
once for each drive.

\begin{tscreen}
\# {\em fdisk /dev/hda} 

Command (m for help): 
\end{tscreen}
Here {\tt fdisk} is waiting for a command; you can type {\tt m} to get a 
list of options.
\begin{tscreen}
Command (m for help):  {\em m} \\
Command action \\
   a   toggle a bootable flag \\
   d   delete a partition \\
   l   list known partition types \\
   m   print this menu \\
   n   add a new partition \\
   p   print the partition table \\
   q   quit without saving changes \\
   t   change a partition's system id \\
   u   change display/entry units \\
   v   verify the partition table \\
   w   write table to disk and exit \\
   x   extra functionality (experts only) 

Command (m for help): 
\end{tscreen}
The {\tt n} command is used to create a new partition.
Most of the other options you won't need to worry about. To quit
{\tt fdisk} without saving any changes, use the {\tt q} command. To quit
{\tt fdisk} and write the changes to the partition table to disk, use the
{\tt w} command.

The first thing you should do is display your current partition table
and write the information down, for later reference. Use the {\tt p} command.
\begin{tscreen}
Command (m for help):  {\em p} \\
Disk /dev/hda: 16 heads, 38 sectors, 683 cylinders \\
Units = cylinders of 608 * 512 bytes 
\begin{verbatim}
   Device Boot  Begin   Start     End  Blocks   Id  System 
/dev/hda1   *       1       1     203   61693    6  DOS 16-bit >=32M 

\end{verbatim}
Command (m for help): 
\end{tscreen}
In this example, we have a single MS-DOS partition on {\tt /dev/hda1}, which
is 61693 blocks (about 60 megs).\footnote{A block, under Linux,
is 1024 bytes.} This partition starts at cylinder number
1, and ends on cylinder 203. We have a total of 683 cylinders in this 
disk; so there are 480 cylinders left to create Linux partitions on.

To create a new partition, use the {\tt n} command. In this example, we'll
create two primary partitions ({\tt /dev/hda2} and {\tt /dev/hda3}) 
for Linux. 

\begin{tscreen}
Command (m for help): {\em n} \\
Command action \\
\ \ e   extended \\
\ \ p   primary partition (1-4)  \\
\ \ {\em p} 
\end{tscreen}
Here, {\tt fdisk} is asking the type of the partition to create: extended
or primary. In our example, we're creating only primary partitions, so we
choose {\tt p}.
\begin{tscreen}
Partition number (1-4): 
\end{tscreen}
{\tt fdisk} will then ask for the number of the partition to create; 
since partition 1
is already used, our first Linux partition will be number 2.
\begin{tscreen}
Partition number (1-4): {\em 2}\\
First cylinder (204-683): 
\end{tscreen}
Now enter the starting cylinder number of the partition. Since cylinders
204 through 683 are unused, we'll use the first available one (numbered 204).
There's no reason to leave empty space between partitions.
\begin{tscreen}
First cylinder (204-683): {\em 204} \\
Last cylinder or +size or +sizeM or +sizeK (204-683): 
\end{tscreen}
{\tt fdisk} is asking for the size of the partition to create. We can
either specify an ending cylinder number, or a size in bytes, kilobytes,
or megabytes. 
Since we want our partition to be 80 megs in size, we 
specify {\tt +80M}. When specifying a partition size in this way,
{\tt fdisk} will round the actual partition size to the nearest number
of cylinders. 
\begin{tscreen}
Last cylinder or +size or +sizeM or +sizeK (204-683): {\em +80M} 

Warning: Linux cannot currently use 33090 sectors of this partition
\end{tscreen}
If you see a warning message such as this, it can be ignored. 
{\tt fdisk} prints the warning because it's an 
older program, and dates before the time that Linux partitions were allowed to 
be larger than 64 megabytes.

Now we're ready to create our second Linux partition. For sake of 
demonstration, we'll create it with a size of 10 megabytes.
\begin{tscreen}
Command (m for help): {\em n} \\
Command action \\
   e   extended \\
   p   primary partition (1-4) \\
{\em p} \\
Partition number (1-4): {\em 3} \\
First cylinder (474-683): {\em 474} \\
Last cylinder or +size or +sizeM or +sizeK (474-683): {\em +10M} 
\end{tscreen}

At last, we'll display the partition table. Again, write down all of 
this information---especially the block sizes of your new partitions. You'll
need to know the sizes of the partitions when creating filesystems, later.
Also, verify that none of your partitions overlap.
\begin{tscreen}
Command (m for help): {\em p}
 
Disk /dev/hda: 16 heads, 38 sectors, 683 cylinders \\
Units = cylinders of 608 * 512 bytes 
\begin{verbatim}
   Device Boot  Begin   Start     End  Blocks   Id  System 
/dev/hda1   *       1       1     203   61693    6  DOS 16-bit >=32M 
/dev/hda2         204     204     473   82080   81  Linux/MINIX 
/dev/hda3         474     474     507   10336   81  Linux/MINIX 
\end{verbatim}
\end{tscreen}
As you can see, {\tt /dev/hda2} is now a partition of size 82080 blocks
(which corresponds to about 80 megabytes), and {\tt /dev/hda3} is 
10336 blocks (about 10 megs). 

Note that many distributions (such as Slackware) require you to use 
the {\tt t} command in {\tt fdisk} to change the type of the swap 
partition to ``Linux swap'', which is usually numbered 82. You can
use the {\tt L} command to print a list of known partition type codes,
and then use {\tt t} to set the type of the swap partition to that
which corresponds to ``Linux swap''. 

In this way, the installation software will be able to automatically find 
your swap partitions based on type. If the installation software doesn't 
seem to recognize your swap partition, you might want to re-run 
{\tt fdisk} and use the {\tt t} command on the partition in question.

In the example above, the remaining cylinders on the disk (numbered 508 to 
683) are unused. You may wish to leave unused space on the disk, in case
you wish to create additional partitions later. 

Finally, we use the {\tt w} command to write the changes to disk and
exit {\tt fdisk}.
\begin{tscreen}
Command (m for help): w

\#
\end{tscreen}
 
Keep in mind that none of the changes you make while running {\tt fdisk}
will take effect until you give the {\tt w} command, so you can toy with
different configurations and save them when you're done. Also, if you 
want to quit {\tt fdisk} at any time without saving the changes, use the
{\tt q} command. Remember that you shouldn't modify partitions for
operating systems other than Linux with the Linux {\tt fdisk} program.

Remember that you may not be able to boot Linux from a partition 
using cylinders numbered over 1023. Therefore, you should try to create
your Linux root partition within the sub-1024 cylinder range. Again,
if this is impossible, you can simply boot Linux from floppy.

Some Linux distributions require you to reboot the system after running
{\tt fdisk}. This is to allow the changes to the partition table to
take effect before installing the software. Newer versions of {\tt fdisk}
automatically update the partition information in the kernel, so rebooting
isn't necessary. To be on the safe side, after running {\tt fdisk} you
should reboot the installation media, as before, before proceeding.


\index{fdisk@{\tt fdisk}|)}
\index{partitions!fdisk@{\tt fdisk}|)}

