Linux Disk Management with parted command

The parted is a disk management utility. It allows us to create, manage, and delete standard partitions on Linux. There are two types of standard partition schemes: MBR and GPT.

MBR is a classical partitioning scheme. By default, it supports only four partitions. These partitions are known as primary partitions. If you need more partitions, you must convert the last primary partition into the extended partition. In the extended partition, you can create 11 logical partitions.

GPT is a modern partitioning scheme. It supports a maximum of 128 partitions. Since it supports a lot of partitions by default, it does not classify them into types.

We have three tools to create and manage standard partitions: fdisk, gdisk, and parted. The fdisk creates only MBR partitions. The gdisk creates only GPT partitions. The parted creates both.

Adding a new hard disk to the virtual machine

We can create partitions only on the disk having free unparted space. If free unparted space is not available, you can attach a new hard disk for practice.

The following tutorials explain how to create a virtual machine and add a new hard disk to the virtual machine for practice.

RHCE Practice Lab Setup in VMWare and in VirtualBox
Adding and removing hard disks in VMware Workstation

We can use the lsblk command to list all attached hard disks and their partitions.

lsblk command

On this system, we have three hard disks. The second disk contains the operating system. Since disk management involves risks of data loss, we will not use a disk containing an operating system or user data for practice. The first and third disks are blank. We can use any disk from these disks to practice the parted command. I will use the first disk.

Starting the parted utility

The parted command needs the disk path as an argument. To manage the first disk, we will specify its absolute path as an argument to the parted command. The parted command starts in a sub-shell. It takes control of the command prompt until we exit it.

starting parted

Viewing partitions information

To view the current partitions' information, we use the print command. It provides information about the disk manufacturer, model, size, label, flag, and partitions. The label describes the type of partition we can create on it.

Label Description Partition type
Unrecognized The disk is blank. It contains no partition table. We can not use it to create partitions.
GPT The disk contains the GPT partition table. We can create GPT partitions on it.
msdos The disk contains the MBR partition table. We can create the MBR partitions on it.
print command

Currently, this disk contains the GPT partition table. We can create GPT partitions on it. If we want to create MBR partitions on it, we have to change the label to the msdos.

Changing disk label

To change or set the label, we use the mklabel command. If the disk contains a different label, it displays the following warning message.

Warning: The existing disk label on the /dev/[disk] will be destroyed and all data on this disk will be lost. Do you want to continue?

If we confirm the action, it erases the existing label and creates a new label.

changing disk label

Creating MBR partitions

To create a new partition, we use the mkpart command. It needs four arguments: partition type, file system type, starting point, and ending point. By default, it creates a primary partition for the ext2 file system.

If we want to create an extended partition or a partition for a different file system type, we need to specify both values manually. To specify starting and ending points, we can use standard sizes.

Create the first primary partition of 500 MB.

create primary partition

Create another primary partition of the same size. Start the partition size from where the last partition's size ends. In our example, the last partition's size ends at 500 MB. So, we will start this partition's size from 501 MB.

create second partition

We have created the first and second partitions for the default ext2 file system. If we want to create a partition for another file system, we need to specify the new file system's name as an argument. Let us create the third primary partition for the ext3 file system.

create thrid partition

We have created three primary partitions. If we need only one more partition, we can create the fourth primary partition. But if we need more than one partition, we cannot create the fourth primary partition. In that case, we need to create an extended partition.

create extended partition

In the extended partition, we can create logical partitions. If an extended partition is available, the prompt automatically selects the partition type to the logical.

Let us create a logical partition.

create the first logical partition

While specifying the partition size if we select a partition size that overlaps the existing partition, the prompt displays a warning message and asks us to confirm the action. If we confirm the action, it creates a partition that overlaps the existing partition. It will corrupt the existing partition.

partition size overlap

Unlike the fdisk and gdisk commands, it does not keep the change in the memory. It immediately applies them to the disk. To quit the parted, we use the quit command.

quit parted

To verify new partitions, we can use the lsblk command.

verify lsblk command

Creating GPT partitions

To create GPT partitions, we need to delete the MBR partitions and change the disk label to GPT. To delete partitions, we use the rm command. Delete all MBR partitions.

delete mbr partition

Changing the label is like formatting the disk. When we change the disk label, it removes the old partition table and creates the new one. Change the disk label to GPT.

change label

Since GPT does not categorize partitions into primary, extended, and logical partitions, the mkpart command does not ask for the partition type. Instead of the partition type, it asks for the partition name. You can use any descriptive name for the partition.

create gpt partition

Let us create one more GPT partition and quit the parted utility.

create second gpt partition

Use the lsblk command to verify new partitions.

the lsblk command

File systems and mount points

The parted command only creates partitions. It does not create a file system on the partition. To use a partition, you must create a file system on it. After creating a file system, you need to mount the partition on the Linux file system. The following tutorials explain this process.

That's all for this tutorial. In this tutorial, we learned how to use the parted command to create, manage, and delete partitions on Linux.

ComputerNetworkingNotes Linux Tutorials Linux Disk Management with parted command