12.1. Standard Partitions using parted

12.1. Standard Partitions using parted

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 39.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/sda, where /dev/sda 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 cannot be in use (partitions cannot be mounted, and swap space cannot 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 5, 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 (system processes that use or lock the file system from being unmounted), you can unmount them with the umount command and turn off all the swap space on the hard drive with the swapoff command.

Table 12.1, “parted commands” contains a list of commonly used parted commands. 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 fromto 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-numfile-system-type Create a file system of type file-system-type
mkpart part-typefs-typestart-mbend-mb Make a partition without creating a new file system
mkpartfs part-typefs-typestart-mbend-mb Make a partition and create the specified file system
move minor-numstart-mbend-mb Move the partition
name minor-numname Name the partition for Mac and PC98 disklabels only
print Display the partition table
quit Quit parted
rescuestart-mbend-mb Rescue a lost partition from start-mb to end-mb
resize minor-numstart-mbend-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-numflagstate Set the flag on a partition; state is either on or off

Table 12.1. parted commands



Note: This documentation is provided {and copyrighted} by Red Hat®, Inc. and is released via the Open Publication License. The copyright holder has added the further requirement that Distribution of substantively modified versions of this document is prohibited without the explicit permission of the copyright holder. The CentOS project redistributes these original works (in their unmodified form) as a reference for CentOS-4 because CentOS-4 is built from publicly available, open source SRPMS. The documentation is unmodified to be compliant with upstream distribution policy. Neither CentOS-4 nor the CentOS Project are in any way affiliated with or sponsored by Red Hat®, Inc.