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.

We can create partitions only on the disk having free unparted space. We can use the lsblk command to list all attached hard disks and their partitions.

the lsblk command

This system has three hard disks. The second disk contains the operating system. Since disk management involves risks of data loss, we should 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. The disk displays the following warning message if it contains a different label.

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. We can use standard sizes to select starting and ending points.

Create the first primary partition of 500 MB.

creating 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 previous partition's size ends at 500 MB. So, we will start this partition's size from 501 MB.

creating the 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.

creating the thrid partition

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

creating extended partition

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

Let us create a logical partition.

creating the first logical partition

While specifying the partition size, if we select a partition size that overlaps the existing partition, the prompt will display a warning message and ask us to confirm the action. It will corrupt the existing partition.

partition size overlapping

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.

verifying the 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.

deleting 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.

changing 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.

creating the gpt partition

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

creating the 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 make a file system on the partition. To use a partition, you must create a file system on it. After creating a file system, you must mount the partition on the Linux file system. The following tutorials in this series explain this process.

This tutorial is part of the tutorial series Linux disk management concepts and configurations. Other parts of this series are the following.

Chapter 01  Linux disk management terminology
Chapter 02  File Management Commands in Linux
Chapter 03  Linux file system types explained
Chapter 04  Adding and removing hard disks in VMware Workstation
Chapter 05  List view and find hard disk names in Linux
Chapter 06  The fdisk command on Linux explained
Chapter 07  Manage Linux disk partition with the gdisk command
Chapter 08  The /etc/fstab file on Linux explained
Chapter 09  Linux disk management with the parted command
Chapter 10  The mkfs command on Linux
Chapter 11  The mount command on Linux temporary mounting
Chapter 12  The swap space on Linux explained
Chapter 13  How to create a swap partition in Linux
Chapter 14  How to configure LVM in Linux step-by-step
Chapter 15  How to configure RAID in Linux step-by-step

Conclusion

The parted is the lightweight and fast disk management utility on Linux. It can create, update, and delete standard partitions. In this tutorial, we learned how to use it for disk management through examples.

ComputerNetworkingNotes Linux Tutorials Linux Disk Management with parted command

We do not accept any kind of Guest Post. Except Guest post submission, for any other query (such as adverting opportunity, product advertisement, feedback, suggestion, error reporting and technical issue) or simply just say to hello mail us ComputerNetworkingNotes@gmail.com