• No results found

Many users need to view the existing partition table, change the size of the partitions, remove parti-tions, or add partitions from free space or additional hard drives. The utilitypartedallows users to perform these tasks. This chapter discusses how to usepartedto perform file system tasks.

If you want to view the system’s disk space usage or monitor the disk space usage, refer to Section 42.3 File Systems.

You must have thepartedpackage installed to use thepartedutility. To startparted, at a shell prompt as root, type the commandparted /dev/hdb, where /dev/hdb is the device name for the drive you want to configure. The(parted)prompt is displayed. Typehelpto view a list of available commands.

If you want to create, remove, or resize a partition, the device can not be in use (partitions can not be mounted, and swap space can not be enabled). The partition table should not be modified while in use because the kernel may not properly recognize the changes. Data could be overwritten by writing to the wrong partition because the partition table and partitions mounted do not match. The easiest way to achieve this it to boot your system in rescue mode. Refer to Chapter 11 Basic System Recovery for instructions on booting into rescue mode. When prompted to mount the file system, selectSkip.

Alternately, if the drive does not contain any partitions in use, you can unmount them with theumount command and turn off all the swap space on the hard drive with theswapoffcommand.

Table 5-1 contains a list of commonly usedpartedcommands. The sections that follow explain some of them in more detail.

Command Description

check minor-num Perform a simple check of the file system cp from to Copy file system from one partition to another;

fromand to are the minor numbers of the partitions

help Display list of available commands

mklabel label Create a disk label for the partition table mkfs minor-num file-system-type Create a file system of type

file-system-type mkpart part-type fs-type start-mb

end-mb

Make a partition without creating a new file system

mkpartfs part-type fs-type start-mb end-mb

Make a partition and create the specified file system

move minor-num start-mb end-mb Move the partition

name minor-num name Name the partition for Mac and PC98 disklabels only

print Display the partition table

quit Quitparted

rescuestart-mb end-mb Rescue a lost partition from start-mb to end-mb

16 Chapter 5. Managing Disk Storage

Command Description

resize minor-num start-mb end-mb Resize the partition from start-mb to end-mb

rm minor-num Remove the partition

select device Select a different device to configure

set minor-num flag state Set the flag on a partition; state is either on or off

Table 5-1.partedcommands

5.1. Viewing the Partition Table

After startingparted, type the following command to view the partition table:

print

A table similar to the following appears:

Disk geometry for /dev/hda: 0.000-9765.492 megabytes Disk label type: msdos

Minor Start End Type Filesystem Flags

1 0.031 101.975 primary ext3 boot

2 101.975 611.850 primary linux-swap 3 611.851 760.891 primary ext3

4 760.891 9758.232 extended lba

5 760.922 9758.232 logical ext3

The first line displays the size of the disk, the second line displays the disk label type, and the re-maining output shows the partition table. In the partition table, theMinor number is the partition number. For example, the partition with minor number 1 corresponds to/dev/hda1. TheStart and End values are in megabytes. The Type is one of primary, extended, or logical. The Filesystem is the file system type, which can be one of ext2, ext3, FAT, hfs, jfs, linux-swap, ntfs, reiserfs, hp-ufs, sun-ufs, or xfs. TheFlags column lists the flags set for the partition. Available flags are boot, root, swap, hidden, raid, lvm, or lba.

Tip

To select a different device without having to restartparted, use theselectcommand followed by the device name such as/dev/hdb. Then, you can view its partition table or configure it.

5.2. Creating a Partition

Warning

Do not attempt to create a partition on a device that is in use.

Before creating a partition, boot into rescue mode (or unmount any partitions on the device and turn off any swap space on the device).

Chapter 5. Managing Disk Storage 17

Startparted, where /dev/hda is the device on which to create the partition:

parted /dev/hda

View the current partition table to determine if there is enough free space:

print

If there is not enough free space, you can resize an existing partition. Refer to Section 5.4 Resizing a Partition for details.

5.2.1. Making the Partition

From the partition table, determine the start and end points of the new partition and what partition type it should be. You can only have four primary partitions (with no extended partition) on a device.

If you need more than four partitions, you can have three primary partitions, one extended partition, and multiple logical partitions within the extended. For an overview of disk partitions, refer to the appendix An Introduction to Disk Partitions in the Red Hat Enterprise Linux Installation Guide.

For example, to create a primary partition with an ext3 file system from 1024 megabytes until 2048 megabytes on a hard drive type the following command:

mkpart primary ext3 1024 2048

Tip

If you use themkpartfscommand instead, the file system is created after the partition is created.

However,parteddoes not support creating an ext3 file system. Thus, if you wish to create an ext3 file system, usemkpartand create the file system with themkfscommand as described later.mkpartfs works for file system type linux-swap.

The changes start taking place as soon as you press [Enter], so review the command before executing to it.

After creating the partition, use theprintcommand to confirm that it is in the partition table with the correct partition type, file system type, and size. Also remember the minor number of the new partition so that you can label it. You should also view the output of

cat /proc/partitions

to make sure the kernel recognizes the new partition.

5.2.2. Formating the Partition

The partition still does not have a file system. Create the file system:

/sbin/mkfs -t ext3 /dev/hdb3

18 Chapter 5. Managing Disk Storage

Warning

Formatting the partition permanently destroys any data that currently exists on the partition.

5.2.3. Labeling the Partition

Next, give the partition a label. For example, if the new partition is/dev/hda3and you want to label it/work:

e2label /dev/hda3 /work

By default, the installation program uses the mount point of the partition as the label to make sure the label is unique. You can use any label you want.

5.2.4. Creating the Mount Point As root, create the mount point:

mkdir /work

5.2.5. Add to/etc/fstab

As root, edit the/etc/fstabfile to include the new partition. The new line should look similar to the following:

LABEL=/work /work ext3 defaults 1 2

The first column should containLABEL=followed by the label you gave the partition. The second column should contain the mount point for the new partition, and the next column should be the file system type (for example, ext3 or swap). If you need more information about the format, read the man page with the commandman fstab.

If the fourth column is the worddefaults, the partition is mounted at boot time. To mount the partition without rebooting, as root, type the command:

mount /work

5.3. Removing a Partition

Warning

Do not attempt to remove a partition on a device that is in use.

Before removing a partition, boot into rescue mode (or unmount any partitions on the device and turn off any swap space on the device).

Startparted, where /dev/hda is the device on which to remove the partition:

Chapter 5. Managing Disk Storage 19

parted /dev/hda

View the current partition table to determine the minor number of the partition to remove:

print

Remove the partition with the commandrm. For example, to remove the partition with minor number 3:

rm 3

The changes start taking place as soon as you press [Enter], so review the command before committing to it.

After removing the partition, use theprintcommand to confirm that it is removed from the partition table. You should also view the output of

cat /proc/partitions

to make sure the kernel knows the partition is removed.

The last step is to remove it from the/etc/fstabfile. Find the line that declares the removed partition, and remove it from the file.

5.4. Resizing a Partition

Warning

Do not attempt to resize a partition on a device that is in use.

Before resizing a partition, boot into rescue mode (or unmount any partitions on the device and turn off any swap space on the device).

Startparted, where /dev/hda is the device on which to resize the partition:

parted /dev/hda

View the current partition table to determine the minor number of the partition to resize as well as the start and end points for the partition:

print

Warning

The used space of the partition to resize must not be larger than the new size.

To resize the partition, use theresizecommand followed by the minor number for the partition, the starting place in megabytes, and the end place in megabytes. For example:

resize 3 1024 2048

20 Chapter 5. Managing Disk Storage

After resizing the partition, use theprintcommand to confirm that the partition has been resized correctly, is the correct partition type, and is the correct file system type.

After rebooting the system into normal mode, use the commanddfto make sure the partition was mounted and is recognized with the new size.

Chapter 6.