Linux parted command

Updated: 11/06/2021 by Computer Hope
parted command

On Unix-like operating systems, the parted command creates, views, deletes, and modifies disk partitions.

Description

GNU parted is a disk partitioning and partition resizing program. It lets you create, destroy, resize, move and copy ext2, linux-swap, FAT (File Allocation Table), FAT32, and reiserfs partitions. It can create, resize, and move Macintosh HFS partitions, and detect jfs, ntfs, ufs, and xfs partitions. It is useful for creating space for new operating systems, reorganising disk usage, and copying data to new hard disks.

Syntax

parted [options] [device [command [options...]...]]

Options

-h, --help Display a help message, and exit.
-l, --list Lists partition layout on all block devices.
-m, --machine Displays machine-parseable output
-s, --script Never prompts for user input.
-v, --version Displays version information, and exits.
-a alignment-type,
--align alignment-type
Set alignment for newly created partitions, valid alignment types are:

none Use the minimum alignment allowed by the disk type.
cylinder Align partitions to cylinders.
minimal Use minimum alignment as given by the disk topology information. This and the optimal value uses layout information provided by the disk to align the logical partition table addresses to actual physical blocks on the disks. The minimal value is the minimum alignment needed to align the partition properly to physical blocks, which avoids performance degradation.
optimal Use optimum alignment as given by the disk topology information. This aligns to a multiple of the physical block size in a way that guarantees optimal performance.

Commands

[device] The block device to be used. When none is given, parted uses the first block device it finds.
[command [options]] Specifies the command to be executed. If no command is given, parted presents a command prompt. Possible commands are:

check partition Do a simple check on partition.
cp [source-device] source destination Copy the source partition's filesystem on source-device (or the current device if no other device was specified) to the destination partition on the current device.
help [command] Print general help, or help on command if specified.
mkfs partition fs-type Make a filesystem fs-type on partition. fs-type can be one of "fat16", "fat32", "ext2", "linux-swap", or "reiserfs".
mklabel label-type Create a new disklabel (partition table) of label-type. label-type should be one of "bsd", "dvh", "gpt", "loop", "mac", "msdos", "pc98", or "sun".
mkpart part-type [fs-type] start end Make a part-type partition with filesystem fs-type (if specified), beginning at start and ending at end (by default in megabytes). fs-type can be one of "fat16", "fat32", "ext2", "HFS", "linux-swap", "NTFS", "reiserfs", or "ufs". part-type should be one of "primary", "logical", or "extended".
mkpartfs part-type fs-type start end Make a part-type partition with filesystem fs-type beginning at start and ending at end (by default in megabytes). Using this command is discouraged. Instead, use mkpart to create an empty partition, and then use external tools, like mke2fs, to create the filesystem.
move partition start end Move partition so it begins at start and ends at end. Note: move never changes the minor number.
name partition name Set the name of partition to name. This option works only on Mac, PC98, and GPT disklabels. The name can be placed in quotes, if necessary.
print Display the partition table.
quit Exit from parted.
rescue start end Rescue a lost partition that was located somewhere between start and end. If a partition is found, parted asks to create an entry for it in the partition table.
resize partition start end Resize the filesystem on partition so it begins at start and ends at end (by default in megabytes).
rm partition Delete partition.
select device Choose device as the current device to edit. The device usually is a Linux hard disk device, but it can also be a partition, software raid device, or an LVM logical volume, if necessary.
set partition flag state Change the state of the flag on partition to state. Supported flags are: "boot", "root", "swap", "hidden", "raid", "lvm", "lba", "legacy_boot", and "palo". The state should be "on" or "off".
unit unit Set unit as the unit to use when displaying locations and sizes, and for interpreting those given by the user when not suffixed with an explicit unit. The unit can be one of "s" (sectors), "B" (bytes), "kB", "MB", "GB", "TB", "%" (percentage of device size), "cyl" (cylinders), "chs" (cylinders, heads, sectors), or "compact" (megabytes for input, and a human-friendly form for output).
version Display version information and a Copyright message.

Known issues

ext3 filesystem functionality does not currently work. To manage ext3 type filesystems, use tools like resize2fs or mke2fs. Note that the currently supported ext2 filesystem is deprecated once ext3 support is finalized. Further note that ext3 support has limited functionality that is yet to be defined. Use tools like resize2fs and mke2fs to manage these types of filesystems.

To manually resize an ext3 filesystem or a partition, use resize2fs, fdisk, or similar tools. For LVM situations, use the LVM commands to resize the LVM elements.

Examples

parted

Brings you to the parted command prompt, where you can enter any of the commands listed above. Note that parted should run as the superuser to gain the full hardware access it requires; for example, you may need to run parted with the sudo command instead:

sudo parted

Once inside, you are placed at a "(parted)" prompt, where you can enter any of the commands above to partition your hard disk, or the quit command to exit.

fdisk — A disk partitioning utility.
mkfs — Build a Linux file system, usually a hard disk partition.