Creating an ext3 File System

If you are adding a new disk drive to a Red Hat Linux system and want to utilize the ext3 file system, you must first partition the hard disk with a program such as fdisk and then format the file system.

Partitioning with fdisk

To use fdisk, open a shell prompt and log in as the root user. The fdisk command requires you to specify the device you are partitioning as an argument to the command. In the following examples, the device will be /dev/hdb, which corresponds to the second device on the primary IDE channel. To begin, type:

/sbin/fdisk /dev/hdb

The following table provides the most common fdisk commands.

Table 5-1. fdisk commands

CommandWhat it Does
mdisplays help
pdisplays the current partition table
ddeletes a partition
ncreates a new partition
wwrites the partition table to disk
tsets the anticipated file system type for the partition
ldisplays the list of file system types for partitions
qquits fdisk without altering the disk

TipTip
 

If you need to exit the program at any time without altering your disk, type q.

Now that you are in the fdisk program, type n to create a new partition. The program will ask you to choose a partition type, choose e for an extended and p for a primary partition.

Before choosing the partition type, be aware that Red Hat Linux only allows up to four primary partitions per disk. If you wish to create more than that, one (and only one) of the four primary poartitions may be an extended partition, which acts as a container for one or more logical partitions. Since it acts as a container, the extended partition must be at least as large as the total size of all the logical partitions it is to contain. For more information on disk partitions, see the Appendix called An Introduction to Disk Partitions in the Official Red Hat Linux Installation Guide.

After choosing the partition type and the number for that partition, choose which cylinder head you would like the partition to start on. You can type [Enter] to except the default value.

Next, specify the size. The easiest way to do this is to type +sizeM, where size is the size of the partition in megabytes. If you press [Enter] without entering a value, fdisk will use the remainder of the disk.

Repeat this process until you have created your desired partitioning scheme.

TipTip
 

It is a good idea to write down which partitions (for example, /dev/hdb2) are meant for which file systems (for example, /home/username) as you create each partition.

Next, you will need to specify what type of file system you intend to put on the disk because fdisk creates partitions of type unknown by default.

To do this, type t followed by a partition number. Next enter the hex value for the file system type you intend to install on the partition. For Linux swap partitions. the hex value is 82. For Linux ext2 or ext3 partitions, the hex value is 83. For other partition types, use the l command to see a list of file system types and their hex values. Repeat this for each partition you created.

When you are finished making partitions, type w to save your changes and quit.

WarningWarning
 

By typing w, you are permanently destroying any data that currently exists on the device. If you need wish to preserve any data, type q to exit the program without altering the disk and back up your data.

Formating ext3 File Systems with mkfs

Once you have created partitions on the disk drive using a partitioning program such as fdisk, you should use mkfs to create an ext3 file system on each partition.

To do this, log in as root and type:

/sbin/mkfs -t ext3 /dev/hdbX

In the above command, replace hdb with the drive letter and X with the partition number.

WarningWarning
 

Using mkfs to format a disk partition will permanently destroy any data that currently exists on the partition.

Assigning a Label with e2label

Once you have created and formated a partition, you should assign it a label using the e2label command. This allows you to add the partition to /etc/fstab using a label instead of using a device path, thereby making the system more robust. [1] To add a label to a partition, type the following command as root:

/sbin/e2label /dev/hdbX /mount/point

Where hdb is the drive letter, X is the partition number, and /mount/point is the mount point you intend to use for the partition.

Once you have assigned each partition a label, add the partitions to /etc/fstab. To do this, log in as root and type:

pico -w /etc/fstab

Then add a line to /etc/fstab for each labeled partition similar to this:

LABEL=/mount/point   /mount/point   ext3   defaults   1 2

In the above entry in /etc/fstab, replace each occurrence of /mount/point with the mount point you intend to use for the partition.

If you need more information on the various options available to you in /etc/fstab, type man fstab.

If there are partitions whose label you are unsure of, type the following command:

/sbin/tune2fs -l /dev/hdbX |grep volume

In the above command, replace hdb with the drive letter and X with the partition number.

This will return something similar to the output below:

Filesystem volume name: /mount/point

In this output, /mount/point is the volume label.

After completing the above steps, you will have successfully added a new ext3 disk to the system. The next section demonstrates how to convert an ext2 disk partition to an ext3 partition.

Notes

[1]

Adding a partition to /etc/fstab allows the partition to be mounted at boot time and simplifies use of the mount command.