Many users need to view the existing partition table, change the size of the partitions, remove partitions, or add partitions from free space or additional hard drives. The utility parted allows users to perform these tasks. This chapter discusses how to use parted to 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 the parted package installed to use the parted utility. To start parted, at a shell prompt as root, type the command parted /dev/hdb, where /dev/hdb is the device name for the drive you want to configure. The (parted) prompt is displayed. Type help to 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, select Skip.
Alternately, if the drive does not contain any partitions in use, you can unmount them with the umount command and turn off all the swap space on the hard drive with the swapoff command.
Table 5-1 contains a list of commonly used parted commands. The sections that follow explain some of them in more detail.
|check minor-num||Perform a simple check of the file system|
|cp from to||Copy file system from one partition to another; from and 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|
|Display the partition table|
|rescue start-mb end-mb||Rescue a lost partition from start-mb to end-mb|
|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. parted commands
After starting parted, type the following command to view the partition table:
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 remaining output shows the partition table. In the partition table, the Minor number is the partition number. For example, the partition with minor number 1 corresponds to /dev/hda1. The Start 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. The Flags column lists the flags set for the partition. Available flags are boot, root, swap, hidden, raid, lvm, or lba.
To select a different device without having to restart parted, use the select command followed by the device name such as /dev/hdb. Then, you can view its partition table or configure it.