parted – Disk partitioning and partition resizing tool

The parted command is a disk partitioning and partition resizing tool that allows users to create, resize, move, and copy partitions on a hard disk. It is a powerful command-line utility that is used to manage disk partitions on Linux systems.

Overview

The parted command is used to create, resize, move, and copy partitions on a hard disk. It can be used to create partitions for various file systems, such as ext2, ext3, ext4, NTFS, and FAT. The parted command can also be used to resize existing partitions, move partitions to different locations on the disk, and copy partitions to other disks or locations.

Creating a partition

To create a partition using the parted command, you need to specify the disk and the partition size. For example, to create a new partition on /dev/sda with a size of 10GB, use the following command:

parted /dev/sda mkpart primary 0GB 10GB

This command creates a new primary partition on /dev/sda with a size of 10GB.

Resizing a partition

To resize a partition, you need to use the resizepart command followed by the partition number and the new size. For example, to resize the first partition on /dev/sda to 20GB, use the following command:

parted /dev/sda resizepart 1 20GB

This command resizes the first partition on /dev/sda to 20GB.

Moving a partition

To move a partition, you need to use the move command followed by the partition number and the new location. For example, to move the first partition on /dev/sda to the end of the disk, use the following command:

parted /dev/sda move 1 -1

This command moves the first partition on /dev/sda to the end of the disk.

Copying a partition

To copy a partition, you need to use the copy command followed by the source partition number and the destination disk or partition. For example, to copy the first partition on /dev/sda to /dev/sdb, use the following command:

parted /dev/sda copy 1 /dev/sdb

This command copies the first partition on /dev/sda to /dev/sdb.

Options

The following table lists the available options for the parted command:

Option Description
-a Specify alignment for new partitions
-s Disable interactive mode
-l Display partition table for specified device
-m Output machine-readable format
-p Display partition information in a human-readable format
-v Display version information

Troubleshooting tips

  • Always make a backup of your data before making any changes to your disk partitions.
  • Double-check the device name before running any parted command to avoid accidentally modifying the wrong disk.
  • If you encounter errors or warnings, refer to the parted documentation or seek assistance from a Linux expert.

Notes

  • The parted command requires root or sudo privileges to run.
  • The parted command is not recommended for use on disks with data that cannot be replaced or restored, such as production servers or critical systems.
  • The parted command is a powerful tool that can cause data loss if used improperly. Always use caution when using this command.