parted
Manage disk partitions
TLDR
List partitions on all block devices
Create a new partition table of the specified label-type
Create a new gpt partition table with a 500MiB boot partition and give the rest for the system partition (--script skips user intervention prompts)
Set a partition to have its boot flag turned on
Start interactive mode with the specified disk selected
Display help
SYNOPSIS
parted [options] [device [command [options...]]]
PARAMETERS
-h
, --help
Displays a help message with command usage and options.-v
, --version
Shows the version information of parted.-s
, --script
Never prompts for user input. This makes parted suitable for scripting and automated tasks, but requires precise command construction.-m
, --machine
Displays output in a machine-readable format, useful for parsing by other programs.-a
alignment-type, --align
alignment-type
Specifies the alignment type for new or resized partitions. Common types include none, cylinder, minimal, and optimal.-l
, --list
Lists the partition layout on all detected block devices. This option bypasses the need to specify a device argument.
DESCRIPTION
parted is a powerful command-line utility for managing disk partitions. It allows users to create, delete, resize, move, copy, and check partitions on various storage devices.
Unlike older tools like fdisk, parted supports modern partition table formats such as GUID Partition Table (GPT) in addition to traditional MS-DOS (MBR), enabling it to work with disks larger than 2TB and offering more flexible partitioning schemes.
It can operate in an interactive mode, guiding the user through commands, or in a non-interactive (script) mode for automation. parted is frequently used for setting partition flags (e.g., bootable, LVM) and ensuring optimal partition alignment for performance.
Caution: Partitioning tools can lead to permanent data loss if used incorrectly. Always back up important data before making any changes to disk partitions.
CAVEATS
Data Loss Risk: Incorrect usage of parted can lead to irreversible data loss. Always back up critical data before performing disk operations.
Filesystem Resizing: While parted can resize partitions, it typically does not resize the filesystem contained within that partition. A separate utility (e.g., resize2fs for extN filesystems, xfs_growfs for XFS) is usually required to adjust the filesystem size after partition changes.
Device Naming: Ensure the correct device is specified (e.g., /dev/sda, /dev/nvme0n1). Targeting the wrong device can lead to severe data corruption.
INTERACTIVE VS. NON-INTERACTIVE MODE
When invoked with only a device (e.g., parted /dev/sda
), parted enters an interactive prompt where users can issue commands like print
, mklabel
, mkpart
, etc. For automation, the -s
or --script
option allows commands to be passed directly on the command line, enabling non-interactive operation.
COMMON INTERNAL COMMANDS
While parted's main options control its overall behavior, specific partition operations are performed using internal commands when in interactive mode or passed as arguments in non-interactive mode. Some common ones include:mklabel
type: Creates a new partition table (e.g., gpt, msdos).mkpart
part-type [fs-type] start end: Creates a new partition.rm
number: Removes a partition.resizepart
number end: Resizes a partition.print
: Displays the current partition table.set
number flag state: Changes a partition flag (e.g., set 1 boot on).
HISTORY
parted was originally developed by Andrew Clausen and Lennert Buytenhek, with its first release in 1998. It was conceived as a more advanced partitioning tool to overcome the limitations of utilities like fdisk, particularly concerning disk sizes larger than 2TB and the ability to resize partitions. As a GNU project, it has evolved to support modern standards like GPT (GUID Partition Table), making it an indispensable tool for contemporary disk management.