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.
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.
parted CommandIn 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.
Creating the File System on the Partitioned Disk
After you partition the disk for a specific file system, you can create the file system on it. In the DOS world, this two-part process is described by DOS as low-level formatting (creating the partitions and partition table) and formatting (creating the file system). In the Unix world, the latter is known as creating a file system. In this section, you learn how to create a file system in Linux.
An unformatted disk storage device (a floppy disk, hard disk drive, or removable media) typically arrives to you with a low-level format, which has been done with a tool such as fdisk or superformat. Although the disk might have a boot block and partition information, it typically lacks the file structure needed for a file system.
If you are preparing to create a file system on any device other than a floppy disk, examine it with fdisk or another utility of your choice and modify the partition table accordingly (following the instructions you saw in the preceding sections of this chapter).
To create the file system structure, you need to do what is sometimes referred to as a high-level format. For FAT file systems, this is accomplished by the format command. In Linux, you use the mke2fs -j command to create an ext3 file system.
If you are creating a Reiser file system, use the mkreiserfs command. To create a DOS file system, use the mkdosfs command. Other commands for other file systems include:
► mkfs.ext2 — The ext2 file system
► mkfs.msdos — The MS-DOS file system
► mkfs.vfat — The FAT32 file system
mke2fs to Create the File SystemThe mke2fs command is used to create both the ext2 and the ext3 file systems. At its simplest, the command is used as:
# mke2fs partition
such as:
# mke2fs /dev/hdc4
Here are some of the most useful options for mke2fs:
► -c — This option checks for bad blocks during file system creation.
► -N — This option overrides the default number of inodes created. (The default number is usually a good choice, but you might need to use this option to allow additional useable disk space.)
► -m — This option frees up some space on the disk, but you do so at your peril. By default, the system allocates 5% of the blocks to the super-user — to be used in file recovery during fsck. You can lower that allocation, but you might not leave enough blocks for fsck to recover enough files.