2.2.3. Linux Partition Requirements
Before we explain how to
repartition your drives, you need an idea of how much space
you will be allocating for Linux.
We will be discussing how to create
these partitions later, in the section "Section 3.1.3, "Creating Linux Partitions"" in
Chapter 3, "Installation
and Initial
Configuration".
On Unix systems, files are stored on a
filesystem, which is
essentially a
section of the hard drive (or other medium, such as
CD-ROM or floppy) formatted to hold files. Each
filesystem is associated with a specific part of the directory tree;
for example, on many systems, there is a filesystem for all the
files in the directory /usr, another
for /tmp, and so on. The root
filesystem is the primary filesystem, which corresponds to
the topmost directory, /.
Under Linux, each filesystem lives
on a separate partition on the hard drive. For instance, if you have a
filesystem for / and another for
/usr, you will need two partitions to hold the
two filesystems.
Before you install Linux, you will need to prepare filesystems for
storing the Linux software. You must have at least one filesystem (the
root filesystem), and therefore one partition, allocated to Linux.
Many Linux users opt to store all their files on the root
filesystem, which, in most cases, is easier to manage than several
filesystems and partitions.
However, you may create multiple filesystems for Linux if you
wish--for example, you may want to use separate filesystems for
/usr and /home. Those
readers with Unix system administration experience
will know how to use multiple filesystems creatively. In
the section "Section 6.1.4, "Creating Filesystems"" in
Chapter 6, "Managing
Filesystems, Swap,
and Devices", we discuss the use of multiple
partitions and filesystems.
Why use more than one filesystem? The most
commonly stated reason is safety; if, for some reason, one of your
filesystems is damaged, the others will (usually) be unharmed. On the
other hand, if you store all your files on the root filesystem, and
for some reason the filesystem is damaged, you may lose all
your files in one fell swoop.
This is, however, rather uncommon; if
you back up the system regularly, you should be quite safe.[14]
[14]Matt uses a single 200-MB
filesystem for all his Linux files and hasn't had any problems (so
far).
On the other hand, using several filesystems has the advantage that
you can easily upgrade your system without endangering your own
precious data. You might have a partition for the users' home
directories, and when upgrading the system, you leave this partition
alone, wipe out the others, and reinstall Linux from scratch. Of
course, nowadays distributions all have quite elaborate update
procedures, but from time to time, you might want a
"fresh start."
Another reason to use multiple filesystems is to divvy up storage
among multiple hard drives. If you have, say, 100 MB free on one hard
drive, and 2 GB free on another, you might want to create a
100-MB root filesystem on the first drive and a 2-GB
/usr filesystem on the other. Currently it is not
possible for a single filesystem to span multiple drives; if your free
hard drive storage is fragmented between drives, you need to use
multiple filesystems to use all the storage.
In summary, Linux requires at least one partition, for the root filesystem.
If you wish to create multiple filesystems, you need a separate
partition for each additional filesystem. Some distributions of Linux
automatically create partitions and filesystems for you, so you may not need
to worry about these issues at all.
Another issue to consider when planning your partitions is swap space.
You have two
options. The first is to use a swap file that
exists on one of your Linux filesystems. You will create the swap file
for use as virtual RAM after you install the
software. The second option is to create a swap
partition, an individual partition to be used only as swap
space. Most people use a swap partition instead of a swap file.
A single swap file or partition may be up to 128 MB (more with the
latest kernels).[15]
If you
wish to use more than 128 MB of swap (hardly ever necessary), you can
create multiple swap partitions or files--up to 16 in all. For
example, if you need 256 MB of swap, you can create two 128-MB swap
partitions.
[15]This value applies to machines with Intel
processors. On other architectures like the Alpha, it can
be higher.
Setting up a swap partition is covered in the section
"Section 3.1.4, "Creating Swap Space"" in
Chapter 3, "Installation
and Initial
Configuration", and setting up a swap file in
the section "Section 6.2, "Managing Swap Space"" in
Chapter 6, "Managing
Filesystems, Swap,
and Devices".
Therefore, in general, you will create at least two partitions for
Linux: one for use as the root filesystem, and the other for use as
swap space. There are, of course, many variations on partitioning, but
this is the minimal setup. You are not required to use swap space with
Linux, but if you have less than 32 MB of physical
RAM, it is strongly suggested that you do.
Of course, you need to know how
much space these partitions will require. The
size of your Linux filesystems (containing the software itself)
depends greatly on how much software you're installing and what
distribution of Linux you are using. Hopefully, the documentation that
came with your distribution will give you an approximation of the
space requirements. A small Linux system can use 40 MB or less; a
larger system anywhere from 100 to 300 MB, or more. Keep in mind that
in addition to the space required by the software itself, you need to
allocate extra space for user directories, room for future expansion,
and so forth.
If you use several partitions, you can use a rather small partition
for the root directory. 32 MB should suffice--use at least 30-50 MB
more if you keep /var on the same partition, as most people do. On
the other hand, you will probably want to have a largish
/usr partition.
The size of your swap partition (should you elect to use one) depends
on how much virtual RAM you require. A rule of
thumb is to use a swap partition that is twice the space of your
physical RAM; for example, if you have 4 MB of
physical RAM, an 8-MB swap partition should
suffice. Of course, this is mere speculation; the actual amount
of swap space you require depends on the software you will be
running. If you have a great deal of physical RAM
(say, 64 MB or more), you may not wish to use swap space at all.
Because of
BIOS limitations, it is usually not possible to
boot from partitions using cylinders numbered over 1023. Therefore,
when setting aside space for Linux, keep in mind you may not want
to use a partition in the over-1023 cylinder range for your Linux root
filesystem. Linux can still use partitions with
cylinders numbered over 1023, but you may not be able to
boot Linux from such a partition. This advice may
seem premature, but it is important to know when planning your drive
layout, and today, many people have large disks with more than 1023
cylinders.
If you absolutely must use a partition with cylinders numbered over
1023 for your Linux root filesystem, you can always boot Linux from floppy.
This is not so bad, actually; it takes only a few seconds longer to boot
than from the hard drive. At any rate, it's always an option.
2.2.4. Repartitioning Your Drives
In this section,
we'll describe how to resize your current partitions (if any) to make
space for Linux. If you are installing Linux on a "clean"
hard drive, skip this section and proceed to
Chapter 3, "Installation
and Initial
Configuration".
The usual way to resize an existing partition is to delete it (thus
destroying all data on that partition) and recreate it. Before
repartitioning your drives, back up your
system. After resizing the partitions, you can reinstall
your original software from the backup. However, there are several
programs available for MS-DOS that
resize partitions nondestructively. One of these is known as
FIPS and can be found on many Linux
FTP sites.
Also, keep in mind that because you'll be shrinking your original
partitions, you may not have space to reinstall everything. In this case,
you need to delete enough unwanted software to allow the rest to fit on
the smaller partitions.
The program used to repartition is known as
fdisk. Each operating system has its own analogue
of this program; for example, under MS-DOS, it is
invoked with the FDISK command. You should consult
your documentation for whatever operating systems you are currently
running for information on repartitioning. Here, we'll discuss how to
resize partitions for MS-DOS using
fdisk, but this information should be easily
extrapolated to other operating systems.
The fdisk program (on any operating system) is
responsible for reading the partition table on a given drive and
manipulating it to add or delete partitions. However, some versions of
fdisk do more than this, such as adding information
to the beginning of a new partition to make it usable by a certain
operating system. For this reason, you should usually only create
partitions for an operating system with the version of
fdisk that comes with it. You can't create
MS-DOS partitions with Linux
fdisk; partitions created in this way can't
be used correctly by MS-DOS (actually, if you
really know what you are doing, you might be lucky in creating
MS-DOS partitions from Linux, but we would not
advise doing so). Similarly,
MS-DOS fdisk may not be able to
recognize Linux partitions. As long as you have a version of
fdisk for each operating system you use, you should
be fine. (Note that not all systems name this program
fdisk; some refer to it as a "disk
manager" or "volume manager.")
Later, in the section "Section 3.1.3, "Creating Linux Partitions"" in
Chapter 3, "Installation
and Initial
Configuration",
we describe how to create new Linux partitions, but for now we are
concerned with resizing your current ones.
Please consult the documentation for your
current operating systems before repartitioning your drive. This
section is meant to be a general overview of the process; there are
many subtleties we do not cover here. You can lose all the
software on your system if you do not repartition the drive correctly.
Let's say that you have a single hard drive on your system, currently
devoted entirely to MS-DOS. Hence, your drive
consists of a single MS-DOS partition, commonly
known as C:. Because this repartitioning method
will destroy the data on that partition, you need to create a bootable
MS-DOS "system disk," which contains
everything necessary to run FDISK and restore the
software from backup after the repartitioning is complete.
In many cases, you can use the MS-DOS installation
disks for this purpose. However, if you need to create your own
system disk, format a floppy with the
command:
FORMAT /s A:
Copy onto this floppy all necessary
MS-DOS
utilities (usually most of the software in the directory
\DOS on your drive), as well as the programs
FORMAT.COM and
FDISK.EXE. You should now be able to boot this
floppy and run the command:
FDISK C:
to start up
FDISK.
Use of FDISK should be self-explanatory, but
consult the MS-DOS documentation for details. When
you start FDISK, use the menu option to display the
partition table, and write down the information displayed there. It is
important to keep a record of your original setup in case you want to
back out of the Linux installation.
To delete an existing partition, choose the FDISK
menu option "Delete an MS-DOS Partition or Logical DOS
Drive." Specify the type of partition you wish to
delete (primary, extended, or logical) and the number of the
partition. Verify all of the warnings. Poof!
To create a new (smaller) partition for MS-DOS,
choose the FDISK option "Create an
MS-DOS Partition or Logical DOS Drive." Specify the
type of partition (primary, extended, or logical) and the size of the
partition to create (specified in megabytes). FDISK
should create the partition, and you're ready to roll.
After you're done using FDISK, exit the program and
reformat any new partitions. For example, if you resized the first
DOS partition on your drive
(C:), you should run the command:
FORMAT /s C:
You may now reinstall your original software from backup.