Книга: Fedora™ Unleashed, 2008 edition

Creating the Partition Table

Creating the Partition Table

Fedora provides several tools to create, examine, and modify the partition table. Because not all the tools we review are likely to be installed on your system (or other system you might be working on for now), this chapter describes making a partition table, using some command-line and graphical tools that Fedora provides.

The partition table has enough room for only four partitions. When the format was first created, it must have been assumed that four would be plenty. Complex, modern systems with very large hard drives make multiple partitions desirable for any number of unique reasons. To get around this problem, one of the four partitions — typically, partition number four — can be used as an extended partition. In other words, in the partition table, it looks like a big partition taking up the rest of the disk. Actually, it is a link to a table that contains the offsets to as many as 63 partitions for IDE disks and 15 for SCSI disks. One extended partition is chained to the next one in this manner.

The fdisk Command

The Linux fdisk command edits the partition table. You must be the super-user (root) before you can run fdisk (also said in Linux shorthand as "run fdisk as root"). Only hard drives (IDE and SCSI) can be accessed with fdisk, and you must use the device name as an argument. USB hard drives are accessed under SCSI emulation and are treated just as if they were SCSI devices. For example, to open fdisk and use it on the first IDE hard drive on the system, you would type this:

# fdisk /dev/hda

and you would see something like this:

# fdisk /dev/hda
The number of cylinders for this disk is set to 4982. There is nothing wrong with that, but this is larger than 1024, and in certain setups could cause problems with software that runs at boot time:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSes (e.g., DOS FDISK or the OS/2 FDISK)

Pressing the m key displays the help screen as follows:

Command (m for help): m
Command action
 a toggle a bootable flag
 b edit bsd disklabel
 c toggle the dos compatibility flag
 d delete a partition
 l list known partition types
 m print this menu
 n add a new partition
 o create a new empty DOS partition table
 p print the partition table
 q quit without saving changes
 s create a new empty Sun disklabel
 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)

Pressing the p key will display the volume's partition information as follows (note that your drive information will be different):

Command (m for help): p
Disk /dev/hda: 255 heads, 63 sectors, 4982 cylinders
Units = cylinders of 16065 * 512 bytes
Device    Boot Start  End   Blocks  Id System
/dev/hda1 *        1  383  3076416   b Win95 FAT32
/dev/hda2        384  387    32130  83 Linux
/dev/hda3        388 1025  5124735  83 Linux
/dev/hda4       1026 4982 31784602+  5 Extended
/dev/hda5       1026 1042   136521 82 Linux swap
/dev/hda6       1043 1552  4096543+ 83 Linux
/dev/hda7       1553 4102 20482843+ 83 Linux
/dev/hda8       4103 4500  3196903+ 83 Linux
/dev/hda9       4501 4982  3871633+ 83 Linux

Older versions of fdisk would default to /dev/hda. The author of fdisk decided that wasn't a good thing, so now you must always type the device name.

TIP

The fdisk command is dangerous to explore only if you write the changes to the partition table. Because you are specifically asked whether you want to do this, poke around to satisfy your curiosity and avoid pressing the w key when you're done; just use q to quit. Armed with this knowledge, do not feel too shy if you're curious about the partition table. But if you really do not want to take a chance on breaking anything, play it safe and use the -l (that's the letter L, not the numeral 1) as in:

# fdisk -l /dev/had
fdisk
happily prints the contents of the partition table to the screen (often referred to as stdout, or standard output) and exits without placing you in the edit mode.

It is always a good idea to keep a hard copy of your edited partition table. You can redirect the output of fdisk -l to a file:

# fdisk -l device > mypartitiontable.txt

or send it to the printer with:

# fdisk -l device | kprinter

In the first example, a redirector symbol (>) is used to redirect the listing from stdout to a file. In the second example, we used a pipe (|) to send the output directly to the printer (assuming that you have one connected).

Now that you are running fdisk as root, you can create a partition table. We will assume that you have installed a brand-new drive as /dev/hdb (the Primary Slave IDE device) and want to partition the entire drive as a single partition. Launch fdisk with:

# fdisk /dev/hdb

Use the n key to create a new partition, and fdisk prompts you for the beginning cylinder:

First Cylinder (1-9729, default 1) :

Press the Enter key to accept the default of 1. Now, fdisk prompts:

Using the default value of 1
Last Cylinder or +size or +sixeM or +sizeK (2-9729, default 9729) :

Here, you can give the size in cylinders, the size in kilobytes, the size in megabytes, or accept the default value (which is the last cylinder on the disk). Press the Enter key to accept the default.

Using default value of 9729

And we are back at the fdisk prompt:

Command (m for help) :

Enter the w command to write the new partition table to the disk, and fdisk exits, returning you to the command prompt.

The parted Command

In the past, Red Hat used a partition editor during its installation process named Disk Druid; the underlying code for Disk Druid has been replaced by GNUparted (also known simply as parted, the name of the command itself). GNUparted is the GNU partition editor and a very powerful utility. You use parted to create, delete, move, resize, and copy ext2, ext3, and FAT32 partitions. Although GNUparted displays a GUI interface during the installation process, it really is a console utility. GNUparted can be used from the command line.

Оглавление книги


Генерация: 1.365. Запросов К БД/Cache: 3 / 0
поделиться
Вверх Вниз