Managing Partitions

When you partition a hard drive, you organize it into sections, which can then be formatted. Every hard drive requires at least one partition. In fact, you can divide a standard hard drive into 15 or 16 different partitions, depending on whether it is an IDE (Integrated Drive Electronics) or SCSI (Small Computer Systems Interface) drive.

You can configure three different types of partitions on a hard drive:

Primary partition You can create up to four different primary partitions on an IDE or a SCSI hard drive. One primary partition must be active; it should include a bootloader such as GRUB, the Linux Loader (LILO), or the Windows NT/2000/XP bootloader.

Extended partition If you need more partitions, you can convert one primary partition into an extended partition. The extended partition then can be further subdivided into logical partitions.

Logical partition An extended partition can be subdivided into the logical partitions that you need. You can have up to 11 logical partitions on a SCSI hard drive or up to 12 logical partitions on an IDE hard drive.

In Chapter 03 , you used Disk Druid to create different partitions during the Red Hat Linux installation process. However, Disk Druid is not available once Linux is installed; your only option is to use the fdisk utility.

Adding Partitions with fdisk

The fdisk utility is the traditional tool for managing partitions. While functionally similar to the MS-DOS tool of the same name , the Linux fdisk utility looks different and is much more versatile. It can help you manage the empty space on an existing drive. It lets you configure up to four primary partitions on a hard drive. You can use fdisk to change the type of partition to one of over 100 different types, including FAT32, Novell NetWare, Linux Logical Volume Manager, Linux Swap, and, of course, a standard Linux partition.

Adding a New Hard Drive

As a Linux administrator, you need to know how to add new hard drives to your servers. Once you ve physically connected your hardware, make sure your PC recognizes it through your BIOS or other means. If your PC doesn t recognize it, there may be a problem with the new hard disk or the connections.

Once you ve added a new hard drive, you need to set it up and configure it. The basic hard drive configuration utility is fdisk . Take a look at Figure 7.1, which illustrates a configuration with two different physical hard drives.

click to expand
Figure 7.1: fdisk shows two hard drives

As you can see, the fdisk -l command lists partition tables on the local computer. In this case, there are two different physical SCSI hard disks, designated /dev/sda and /dev/sdb . The /dev/sda hard drive includes a number of different partitions.

Note the number of cylinders in /dev/sda . Because that is the same number as the last cylinder of the last /dev/sda partition, you know that no room is available for additional partitions on the first SCSI hard drive.

As shown in Figure 7.1, no partitions are associated with /dev/sdb . As noted by the output from fdisk -l , the second SCSI hard drive does not contain a valid partition table. It s time to do something about that. Use fdisk to open up the second SCSI hard drive with the following command:

 # fdisk /dev/sdb 
Note  

Depending on the value of your PATH variable, you may need to specify the full path to a command such as fdisk . If the fdisk command does not work by itself, try /sbin/fdisk . For more information on PATH, see Chapter 08 .

If this is a completely new hard drive, you ll see a message telling you the hard drive does not contain a valid partition table. If you don t see this message, it probably means that someone has used the hard drive before. In either case, the next thing you ll see is the fdisk utility prompt:

 Command (m for help): 

Now press the m command to see the options available within the fdisk utility. The more important commands are described in Table 7.2.

Table 7.2: fdisk Commands

Command

Result

a

Sets or unsets the bootable flag. You need to make at least one primary partition on one of your first two hard drives bootable.

d

Deletes a partition. Before a partition is actually deleted, you need to select the partition number.

l

Lists known partition types. Over 100 different partition types are available.

m

Shows available fdisk commands.

n

Configures a new partition.

p

Lists the current partition table.

q

Exits fdisk without saving changes.

t

Allows you to change the partition system ID. You ll also need the partition number and the ID of the partition type you want, based on the known partition types (which you can find with the l command).

v

Verifies the current partition table.

w

Writes your changes and exits from fdisk . No changes are written to the partition table until you execute this command.

Now let s return to the task at hand: configuring a new hard drive. You re in the fdisk utility, and the first thing to do is to create a new partition. Issue the n command. The fdisk utility lets you choose whether you re creating a primary or an extended partition. If you already have an extended partition, fdisk allows you to create a logical partition.

 Command (m for help):  n  Command action       e   extended       p   primary partition (1-4) 

Start by creating a primary partition with the p command. Make it the first primary partition, and start it with the first available cylinder. You can specify the size of the partition in cylinders, KBs, or MBs. The sequence is shown in Figure 7.2. The first partition is configured as 100MB, starting with cylinder number one. As you can see, 100MB in this case corresponds to 49 cylinders.

You can continue this process until you ve configured the space you need or you ve allocated all of the space on the new hard drive. Once you ve finished configuring partitions, save your changes with the w command. If you want to start again, exit without saving by using the q command.

Before you can use your new partition, you need to format it to a system such as ext2, ext3, or VFAT. Details on this process are available later in this chapter.

click to expand
Figure 7.2: Creating a new partition

Managing an Existing Hard Drive

If you installed Red Hat Linux on a very large hard drive, you may have some extra space available. Remember, you can configure up to 15 or 16 different partitions on your hard drive, depending on whether it is an IDE or a SCSI drive. In this section, we ll toggle a bootable partition, add a new extended partition, and then add and delete a logical partition.

It s easy to make a partition bootable. Once in the fdisk utility, run the a command. Select the appropriate primary partition, and fdisk adds the bootable label. Figure 7.3 illustrates this process.

click to expand
Figure 7.3: Making a partition bootable

You can install a bootloader such as GRUB or LILO on a bootable partition on one of the first two hard drives on your computer.

Based on the configuration shown back in Figure 7.2, there are 463 free cylinders still available on the new hard drive. The space under the Boot column is empty. And this is specifically labeled as a Linux partition.

Now that you re more familiar with fdisk , creating extended and logical partitions is fairly easy. However, you can also select different cylinders. Figure 7.4 shows one set of commands that you could use to create an extended and a logical partition.

click to expand
Figure 7.4: Adding extended and logical partitions

Note how the cylinders of the first logical partition, /dev/sdb5 , are contained within the cylinders of the extended partition. All logical partitions must fit within the space available to an extended partition.

Revising Partition Labels

You can use fdisk to configure partitions for swap space for LVM, or even for other operating systems.

When you use the Linux fdisk utility to create a new partition, it sets up the new partition with a Linux label by default. You can configure such partitions to the basic Linux formats: ext2, ext3, xfs, reiserfs, and so forth. However, there are a number of other ways to label a partition.

Use fdisk to open the hard drive with the partition you want to change. The following is based on Figure 7.4.

Now use the t command within fdisk to change the partition label. You ll need to select the partition number and then enter the hex code associated with the desired system. For example, the following commands changes the /dev/sdb5 logical partition to the Linux swap system:

 Command (m for help):  t  Partition number (1-5):  5  Hex code (type L to list codes):  82  Changed system type of partition 5 to 82 (Linux swap) 

As you can see in Figure 7.5, you can set a partition to be usable by a wide variety of operating systems.

click to expand
Figure 7.5: Available fdisk partition systems

Later in this chapter, you ll take the final steps to get new partitions ready for data. But first, partitions have labels that help Linux use /etc/fstab to mount the partitions that you need. Let s take a look.

 


Mastering Red Hat Linux 9
Building Tablet PC Applications (Pro-Developer)
ISBN: 078214179X
EAN: 2147483647
Year: 2005
Pages: 220

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net