The utility
parted
allows users to:
View the existing partition table
Change the size of existing partitions
Add partitions from free space or additional hard drives
By default, the parted
package is included when installing Red Hat Enterprise Linux. To start parted
, log in as root and type the command parted /dev/sda
at a shell prompt (where /dev/sda
is the device name for the drive you want to configure).
If you want to remove or resize a partition, the device on which that partition resides must not be in use. Creating a new partition on a device which is in use—while possible—is not recommended.
For a device to not be in use, none of the partitions on the device can be mounted, and any swap space on the device must not be enabled.
As well, the partition table should not be modified while it is in use because the kernel may not properly recognize the changes. If the partition table does not match the actual state of the mounted partitions, information could be written to the wrong partition, resulting in lost and overwritten data.
The easiest way to achieve this it to boot your system in 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 4.1, “parted
commands” contains a list of commonly used
parted
commands. The sections that follow explain some of these commands and arguments in more detail.
Table 4.1. parted
commands
Command
|
Description
|
---|
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
|
print
|
Display the partition table
|
quit
|
Quit parted
|
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
|
toggle [NUMBER [FLAG ]
|
Toggle the state of FLAG on partition NUMBER
|
unit UNIT
|
Set the default unit to UNIT
|
4.1. Viewing the Partition Table
After starting parted
, use the command print
to view the partition table. A table similar to the following appears:
Model: ATA ST3160812AS (scsi)
Disk /dev/sda: 160GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
1 32.3kB 107MB 107MB primary ext3 boot
2 107MB 105GB 105GB primary ext3
3 105GB 107GB 2147MB primary linux-swap
4 107GB 160GB 52.9GB extended root
5 107GB 133GB 26.2GB logical ext3
6 133GB 133GB 107MB logical ext3
7 133GB 160GB 26.6GB logical lvm
The first line contains the disk type, manufacturer, model number and interface, and the second line displays the disk label type. The remaining output below the fourth line 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/sda1
. The Start
and End
values are in megabytes. Valid Type
are metadata, free, primary, extended, or logical. The Filesystem
is the file system type, which can be any of the following:
ext2
ext3
fat16
fat32
hfs
jfs
linux-swap
ntfs
reiserfs
hp-ufs
sun-ufs
xfs
If a Filesystem
of a device shows no value, this means that its file system type is unknown.
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 (for example, /dev/sda
). Doing so allows you to view or configure the partition table of a device.