Skip to content

Linux parted command

The Linux parted command is a useful tool for managing disk partitions on a Linux system. It allows users to create, delete, resize, and modify partitions with ease. By using parted, you can effectively manage your disk space allocation and optimize the performance of your system. This command provides a flexible and powerful way to work with partitions, making it a valuable tool for system administrators and advanced users. With its versatile features and options, the Linux parted command is a handy utility for handling disk partitioning tasks efficiently.

parted Syntax:

Terminal window
parted [options] [device [command [parameters...]]]

Options:

OptionDescription
-h, —helpDisplays a help message and exits
-l, —listLists partition layout on all devices
-s, —scriptNever prompts for user intervention
-a, —alignSet alignment for new partitions
-v, —versionDisplays version information and exits

Parameters:

ParameterDescription
deviceSpecifies the device to be partitioned
commandSpecifies the action to be taken on the device
parametersAdditional parameters for the specified command

parted Usage:

Create a new partition

Terminal window
parted /dev/sdb mkpart primary ext4 0% 100%

Create a new primary partition with ext4 filesystem from the beginning to the end of the disk.

Resize a partition

Terminal window
parted /dev/sdb resizepart 1 0 50%

Resize the first partition on /dev/sdb to use only the first 50% of the disk.

Check partition alignment

Terminal window
parted /dev/sdb align-check minimal 1

Check if the first partition on /dev/sdb is aligned properly with minimal alignment.

Set partition flag

Terminal window
parted /dev/sdb set 1 boot on

Set the boot flag on the first partition on /dev/sdb.

How do I use parted in Linux?

To use the parted command in Linux, execute the following command:

Terminal window
parted /dev/sdx

How do I list partitions with parted?

To list partitions using parted, run the following command:

Terminal window
parted -l

How do I create a new partition with parted?

To create a new partition using parted, follow this example:

Terminal window
parted /dev/sdx mkpart primary 1MiB 100MiB

How can I resize a partition with parted?

To resize a partition with parted, use the following command format:

Terminal window
parted /dev/sdx resizepart <partition_number> 1MiB 200MiB

How do I format a partition using parted?

To format a partition using parted, you can use the mkfs command. Here’s an example for formatting a partition as ext4:

Terminal window
mkfs.ext4 /dev/sdx1

How can I align partitions in parted?

To align partitions in parted for optimal performance, consider using the “align-check optimal” command. Here’s how you can do it:

Terminal window
parted /dev/sdx align-check optimal <partition_number>

How do I label a partition using parted?

To label a partition with a specific name using parted, you can use the “name” command. Here’s an example:

Terminal window
parted /dev/sdx name <partition_number> 'Data'

Applications of the parted command

  • Managing disk partitions
  • Creating, resizing, moving, and deleting disk partitions
  • Setting partition labels and flags
  • Viewing partition information
  • Checking and fixing disk partition issues