17.1.2 Managing Partition Tables Using parted


If any partition on the disk to be configured using parted is currently mounted, unmount it before running parted on the disk. Similarly, if any partition is being used as swap space, use the swapoff command to disable the partition.

Before running parted on a disk that contains data, first back up the data on to another disk or medium.

You can use the parted utility to label a disk, create a partition table, view an existing partition table, add partitions, change the size of partitions, and delete partitions. parted is more advanced than fdisk as it supports more disk label types, including GPT disks, and it implements a larger set of commands.

You can use parted interactively or you can specify commands as arguments. When you run parted interactively, you specify only the name of the disk device as an argument, for example:

# parted /dev/sda
GNU Parted 2.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.

The print command displays the partition table:

(parted) print                                                            
Disk /dev/sda: 42.9GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  525MB   524MB   primary  ext4         boot
 2      525MB   42.9GB  42.4GB  primary               lvm

The mklabel command creates a new partition table:

# parted /dev/sdd
GNU Parted 2.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel
New disk label type? gpt
Warning: The existing disk label on /dev/sdd will be destroyed
and all data on this disk will be lost. Do you want to continue?
Yes/No? y

Typically, you would set the disk label type to gpt or msdos for an Oracle Linux system, depending on whether the disk device supports GPT. You are prompted to confirm that you want to overwrite the existing disk label.

The mkpart command creates a new partition:

(parted) mkpart
Partition name? []? <Enter>
File system type? [ext2]? ext4
Start? 1
End? 5GB

For disks with an msdos label, you are also prompted to enter the partition type, which can be primary, extended, or logical. The file system type is typically set to one of fat16, fat32, ext4, or linux-swap for an Oracle Linux system. If you are going to create an btrfs, ext*, ocfs2, or xfs file system on the partition, specify ext4. Unless you specify units such as GB for gigabytes, the start and end offsets of a partition are assumed to be in megabytes. To specify the end of the disk for End, enter a value of -0.

To display the new partition, use the print command:

(parted) print
Number   Start   End     Size    File system  Name  Flags
1        1049kB  5000MB  4999MB  ext4

To exit parted, enter quit.


parted commands such as mklabel and mkpart commit the changes to disk immediately. Unlike fdisk, you do not have the option of quitting without saving your changes.

For more information, see the parted(8) manual page or enter info parted to view the online user manual.