Наши друзья и партнеры


Книги по Linux (с отзывами читателей)

Библиотека сайта rus-linux.net

Linux System Administrator's Survival Guide lsg08.htm

Previous Page TOC Next Page

Chapter 8

Hard Disks

Adding an additional hard disk to your Linux system is not difficult. Linux is extremely cooperative with this task, allowing great flexibility in the type, speed, capacity, and partitioning of new drives. This short chapter shows you how to add a new hard disk and get it running properly with Linux. If you are adding a hard disk to your Linux system, you will also want to read Chapter 18, "Filesystems and Disks," which explains in more detail how to access the Linux areas of your new drives. Note that some versions of Linux only allow partitions from one drive (the primary boot drive) to be used.

Buying a New Drive

When you bought your PC, you had a hard drive installed in it. Depending on when you bought it, the drive could have a capacity of as little as 40M or as much as 550M of disk space. Prices of hard drives have dropped dramatically over the past couple of years and show no signs of slowing, offering higher capacities for less money every year. Current trends towards newer electronics and manufacturing efficiencies have pushed the disk drive market to the point where drives under 500M are expected to be unavailable in the very near future.

Adding a new high-capacity or an older lower capacity drive is a simple solution to the perennial problem of disk space shortages. One important (and often overlooked) criterion to consider when buying a hard drive is to purchase a drive that is compatible with your existing hard disk controller card (unless you plan to replace your existing drive and controller type). PC users have to worry about several different interfaces. Most commercial systems bought for home and small office use IDE (Integrated Drive Electronics) interfaces and drives. IDE controllers can only support two peripherals, such as two IDE drives or one IDE drive and one IDE CD-ROM drive. If you are using IDE, make sure you can add a new device. IDE has recently been upgraded to EIDE (Enhanced IDE), which allows up to four devices to be attached, two devices each on up to two controllers.

An older interface is ESDI (Enhanced Small Device Interface), which also could handle only two drives. ESDI drives are no longer manufactured, and ESDI controller users should seriously consider scrapping their controller card and using a newer EIDE or SCSI controller. SCSI controllers are the most powerful and flexible system you can add to a PC, although they tend to cost considerably more than IDE, for example. SCSI interface busses are faster than IDE, and you can add up to seven devices to a SCSI chain. Chapter 7, "SCSI Devices," covered SCSI in much more detail.

None of these interface types are interchangeable. If you are not sure which interface you have, either check your documentation or ask your dealer. You can always change interfaces but this change requires a new controller card and replacement of any existing devices.

Before you buy a new drive, check whether your machine has space for it; not all machines have available expansion slots. Small-footprint desktop PCs usually only have a single drive bay, for example. With these types of machines, your only option is to replace the existing drive with a new one of higher capacity, discarding (or selling) the old drive.

Assuming you have room for a new drive, installing it is not difficult, but it can be unnerving the first time. Many dealers will install new drives for you, often free of charge. Most hard drives come with good instruction sheets and all the parts you need, so if you feel adventurous, go ahead and try installing the drive yourself. Usually, the process involves fastening the new drive into an available drive bay with a few small screws, attaching a power connector, and then finally attaching a cable from the interface card that also routes through your other drives (and sometimes the CD-ROM or tape drive, as well). Depending on the type of system you currently have, you might use the existing drive cable if there is a spare connector, or you may need to buy a new cable.

Once the drive is installed, you need to make the PC aware of its existence. SCSI drives are an exception, as the SCSI controller handles all the device information. In the BIOS, you set all the hard drives to None if you are using SCSI, and leave the SCSI controller to inform the BIOS of all peripherals attached to it. For any other drive type, you need to add the drive information to the BIOS table. You can usually access this table by pressing Del or Ctrl+Alt+Esc during the boot sequence (an on-screen message usually tells you the key sequence to use). When you enter the disk drive setup screen, you need to specify the number of cylinders, heads, and sectors per track of the new drive. For most drives, the other information requested in the BIOS drive configuration screen can be ignored. If you have any problems with the BIOS installation, check the documentation that came with the drive, or call your dealer.

Formatting and Partitioning the New Drive

To set up your new hard drive's partitions, you use fdisk just as you did when you set up the first hard drive(covered in the Chapter 3 of this book). If you are going to create a DOS partition on the new drive, most system administrators prefer to boot from a DOS floppy disk or a DOS partition of the first hard drive, and then use the DOS version of fdisk to set up the new drive. (The DOS fdisk program is easier to use than Linux's.)

When in fdisk, switch to the second drive. If you don't see an option on the fdisk menu to change drives, the new drive has not been recognized by the BIOS or SCSI controller card, in which case you should check the configuration again. Once on the second drive, you can partition any DOS areas that you want before you set up the Linux partitions. After setting up DOS partitions, you can format them using DOS' FORMAT command.

<NOTE>With some newer high-capacity drives, the DOS FDISK program can't access all the area on the disk. Many manufacturers now supply a utility disk with a replacement for FDISK that enables you to access the whole drive, format it, and update the partition tables. Use this utility over the standard FDISK if you have a choice. Most new high-capacity IDE disks also include a device driver used by some versions of DOS to access the whole disk area. Recent versions of Linux shouldn't have a problem with these drives.<NOTE>

When you are ready to set up the Linux partitions, boot your machine into Linux and enter the fdisk program. You should be able to access the second hard disk from the menu now. If you have created a DOS partition, it should show up in the partition table. Add any Linux partitions you want following the same process you used with the first drive. You can add more swap partitions to complement those on your first hard disk, or set up the drive with one or more Linux filesystems. Remember to specify the filesystem types within fdisk.

To format any new swap space partitions, use the command

mkswap -c partition size

where partition is the name of the partition and size is the size of the partition in blocks (displayed in the partition table). The -c option tells mkswap to check for bad blocks in the partition. For example, to format a /dev/hdb2 partition for Linux, issue the command

mkswap -c /dev/hdb2 15404

where 15404 is the disk size in blocks, taken from the partition table shown in Linux's fdisk.

After you format the swap partition, you can enable the Linux swap space partition with the swapon command followed by the partition name, such as:

swapon /dev/hdb2

Once the swapon command is executed, Linux will use the new swap space.

To set up the Linux filesystem partitions, create the filesystems with the mkfs (make filesystem) command. The format of the mkfs command depends on the type of filesystem you are setting up, but most users will want to use the Second Extended (ext2) filesystem. To create a Second Extended filesystem, issue the command

mke2fs -c <partition> <size>

where partition is the partition name and size is the size of the partition in blocks (taken from the partition display in fdisk).

<NOTE>Some versions of Linux don't require you to specify the partition size because the mke2fs utility determines the number automatically. In general, any release later than 0.5 can do this calculation for you.<NOTE>

The mke2fs command checks the partition for bad blocks (started by the -c option), and then sets a filesystem up in that partition. You can use other filesystems supported by Linux, although most are slower than the Second Extended filesystem. After you create the partitions, you can mount them for use. See Chapter 18, "Filesystems" for information about the process of adding the new filesystems to your existing Linux configuration.


Adding a second (or third, or fourth) hard drive is a handy and fast way to expand the amount of disk space available to Linux, as well as increasing your swap space if you are having memory problems. The process is simple and Linux is tolerant of errors. If you run into major problems, simply start the process again. There is no real limit to the number of partitions and drives you can mount on Linux, as your hard disk controller card's limits are usually reached first.

Previous Page Page Top TOC Next Page