4.3. Partitioning Hard Drive(s)

Why partition, anyway? Well, although it is possible to get a perfectly functioning Linux system running on a single-partition system, and, in fact, is a bit easier to configure this way, there are a number of benefits from partitioning one or more of your storage devices into multiple partitions.

While it is true that Linux will operate just fine on a disk with only one large partition defined, there are several advantages to partitioning your disk for at least the four main file systems (root, usr, home, and swap). These include:

First, it may reduce the time required to perform file system checks (both upon bootup and when doing a manual fsck), because these checks can be done in parallel. (By the way, NEVER run an fsck on a mounted file system!!! You will almost certainly regret what happens to it. The exception to this is if the file system is mounted read-only, in which case it is safe to do so.) Also, file system checks are a lot easier to do on a system with multiple partitions. For example, if I knew my /home partition had problems, I could simply unmount it, perform a file system check, and then remount the repaired file system (as opposed to booting my system with a rescue diskette into single-user mode and doing the repairs).

Second, with multiple partitions, you can, if you wish, mount one or more of your partitions as read-only. For example, if you decide that everything in /usr will not be touched even by root, you can mount the /usr partition as read-only.

Finally, the most important benefit that partitioning provides is protection of your file systems. If something should happen to a file system (either through user error or system failure), on a partitioned system you would probably only lose files on a single file system. On a non-partitioned system, you would probably lose them on all file systems.

This little fact can be a big plus. For example, if your root partition is so corrupted you can't boot, you can basically boot from the rescue diskette set, mount your root partition, and copy what you can (or restore from backup; see Chapter 8 for details on how files can be backed up and restored), to another partition such as home, and then reboot once again using the emergency boot disk, typing "mount root=/dev/hda3" (assuming the partition containing your temporary root file system is on the third partition of hda) and boot your fully functional Linux box. Then you can run an fsck on your unmounted corrupt root partition.

I have had personal experience in file system catastrophies, and I was very grateful for having had the damage limited due to the use of multiple partitions.

Finally, since Linux allows you to set up other operating system(s) (such as Windows 95/98/NT, BeOS, or what-have-you), and then dual- (or triple-, ...) boot your system, you might wish to set up additional partitions to take advantage of this. Typically, you would want to set up at least one separate partition for each operating system. Linux includes a decent boot loader (called LILO on Intel-based systems, although much the same thing is available as MILO on Alpha, and SILO on Sparc) which allows you to specify which operating system you want to boot at power on, with a time-out default boot of your favorite operating system (probably Linux, right?)

You should partition a disk (or disks) according to your needs. In my experience on Intel, Alpha, and Sparc platforms, for a fairly loaded system (feature-wise), doing a fair amount of tasks (as a desktop system at home, or as an Internet server at work), I have found the following approximation of space works pretty effectively for determining a partition size.

Given:

A given disk of X Mb/Gb          (eg. 2 Gb)
(Or, more than one disk with a combined total of X Mb/Gb)

Calculate:

(swap) about double main RAM     (eg. 64 Mb system gets 128 Mb swap)
/ (root)  about 10% of available (eg. 200 Mb)
/home about 20% of available     (eg. 400 Mb)
/usr any remaining space         (eg. 1272 Mb)

/var (optional -- see below)
/boot (optional -- see below)
/archive (optional -- see below)

Of course, the above amounts are approximate guidelines only. Obviously you are going to want to juggle those percentages around a bit depending on what you are going to use your Linux system for. If you are going to be doing stuff like adding lots of bulky applications such as WordPerfect or Netscape, or perhaps adding Japanese character support, you would probably benefit from a bit more /usr space.

I always seem to have a lot of space available on /home, so if your users aren't doing much (or you have imposed strict quota sizes), or you aren't offering shell accounts and personal web pages, etc., you probably could lower /home space and raise /usr.

Here is a description of the various mount points and file system information, which may give you a better idea of how to best define your partition sizes for your own needs:

As extra drive(s) are added, further partitions can be added to the new drives, mounted at various mount-points as required -- this means a Linux system never needs to worry about running out of space. As an example, if in the future it is clear that sda6 is starting to get filled up, we could add another drive, set a nicely sized partition with a mount-point at /usr/local -- and then transfer all the information from /usr/local over to the new drive. But no system or application component would "break" because Linux would see /usr/local no matter where it was located.

To give you an example of how one might set up partitions, I have used the following partitioning scheme on an Intel system (dual boot, Windows 95 and Linux):

   Device Boot   Begin    Start      End   Blocks   Id  System
/dev/hda1  *         1        1      254  1024096+   6  DOS 16-bit >=32M
/dev/hda2          255      255      782  2128896    5  Extended
/dev/hda5          255      255      331   310432+  83  Linux native
/dev/hda6          332      332      636  1229728+  83  Linux native
/dev/hda7          637      637      749   455584+  83  Linux native
/dev/hda8          750      750      782   133024+  82  Linux swap

The first partition, /dev/hda1, is a DOS-formatted file system used to store the alternative operating system (Windows 95). This gives me 1 Gb of space for that operating system.

The second partition, /dev/hda2, is a physical partition (called "extended") that encompasses the remaining space on the drive. It is used only to encapsulate the remaining logical partitions (there can only be 4 physical partitions on a disk; in my case I required more than 4 partitions, therefore I had to use a logical partitioning scheme for the others).

The third through fifth partitions, /dev/hda5, /dev/hda6, and /dev/hda7, are all e2fs-formatted file systems used for the / (root), /usr, and the /home partitions, respectively.

Finally, the sixth partition, /dev/hda8, is used for the swap partition.

For yet another example, this time an Alpha box with two hard drives (sole boot, Linux only), I have chosen the following partitioning scheme:

   Device Boot   Begin    Start      End   Blocks   Id  System
/dev/sda1            1        1        1     2046    4  DOS 16-bit <32M
/dev/sda2            2        2      168   346859   83  Linux native
/dev/sda3          169      169      231   130851   82  Linux swap
/dev/sda4          232      232     1009  1615906    5  Extended
/dev/sda5          232      232      398   346828   83  Linux native
/dev/sda6          399      399     1009  1269016   83  Linux native
/dev/sdb1            1        1      509  2114355   83  Linux native
/dev/sdb2          510      510     1019  2118540   83  Linux native

The first partition, /dev/sda1, is a DOS-formatted file system used to store the MILO boot loader. The Alpha platform has a slightly different method of booting than an Intel system does, therefore Linux stores its boot information in a FAT partition. This partition only needs to be as large as the smallest possible partition allowed -- in this case, 2Mb.

The second partition, /dev/sda2, is an e2fs-formatted file system used for the / (root) partition.

The third partition, /dev/sda3, is used for the swap partition.

The fourth partition, /dev/sda4, is an "extended" partition (see previous example for details).

The fifth and sixth partitions, /dev/sda5, and /dev/sda6, are e2fs-formatted file systems used for the /home and /usr partitions, respectively.

The seventh partition, /dev/sdb1, is an e2fs-formatted file system used for the /archive partition.

The eighth and final partition, /dev/sdb2, is an e2fs-formatted file system used for the /archive2 partition.

After you finish setting up your partition information, you'll need to write the new partition to disk. After this, the Red Hat installation program reloads the partition table into memory, so you can continue on to the next step of the installation process.