LinuxCommandLibrary

parted.interactive

Manage disk partitions interactively

TLDR

Start interactive mode with the specified disk selected

$ sudo parted [/dev/sdX]
copy

Show partition information in interactive mode
$ print
copy

Select a disk in interactive mode
$ select [/dev/sdX]
copy

Create a 16 GB partition with the specified filesystem in interactive mode (GPT partition table)
$ mkpart [partition_name] [btrfs|ext2|ext3|ext4|fat16|fat32|hfs|hfs+|linux-swap|ntfs|reiserfs|udf|xfs] [0%] [16G]
copy

Create a 16 GB partition with the specified filesystem in interactive mode (MBR partition table)
$ mkpart [primary|logical|extended] [btrfs|ext2|ext3|ext4|fat16|fat32|hfs|hfs+|linux-swap|ntfs|reiserfs|udf|xfs] [0%] [16G]
copy

Resize a partition in interactive mode
$ resizepart [/dev/sdXN] [end_position_of_partition]
copy

Remove a partition in interactive mode
$ rm [/dev/sdXN]
copy

Display help
$ ?
copy

SYNOPSIS

parted [options] [device]
To enter interactive mode, simply run:
sudo parted /dev/sda

PARAMETERS

device
    The disk device to operate on (e.g., /dev/sda, /dev/nvme0n1). Specifying a device will select it for interactive operations.

-h, --help
    Displays help information for parted and exits without entering interactive mode.

-s, --script
    Executes commands non-interactively from a script or pipeline. (Note: This option prevents interactive mode.)

-v, --version
    Displays the parted version information and exits.

-a, --align type
    Set alignment type for partitions (e.g., optimal, cylinder, none). Affects how partitions are created or resized for performance or compatibility.

-l, --list
    Lists all available disk devices and their partition tables without entering interactive mode.

-m, --machine
    Displays information in a machine-readable format, suitable for scripting.

-e, --error-symbolic
    Report errors symbolically rather than numerically.

DESCRIPTION

parted.interactive conceptually refers to the GNU Parted utility when it is run in its interactive mode, which is its default behavior if no specific commands are provided on the command line. parted is a powerful and versatile command-line tool used for creating, deleting, resizing, moving, copying, and checking disk partitions. It supports various partition table formats, including MS-DOS, GPT, Mac, and others.

In interactive mode, users are presented with a prompt where they can type commands such as mklabel, mkpart, rm, resize, print, and select, to manage disk partitions step-by-step. This interactive approach provides immediate feedback and allows for cautious, guided manipulation of disk layouts, significantly reducing the risk of accidental data loss compared to non-interactive, script-driven operations. Due to its direct interaction with disk structures, parted requires superuser (root) privileges.

CAVEATS

Data Loss Risk: Incorrect use of parted can lead to permanent data loss. Always back up critical data before making changes to partition tables.
Root Privileges: parted requires superuser privileges (root) to operate on disk devices.
Device Selection: Always ensure you are operating on the correct disk device to avoid accidentally modifying the wrong drive.
In-Use Partitions: It is generally unsafe to modify partitions that are currently in use or mounted. Unmount filesystems before modifying their partitions.
File System Awareness: parted itself does not directly manipulate file systems (like ext4 or NTFS) within partitions; it only manages the partitions themselves. Tools like mkfs and fsck are needed for file system operations.

INTERACTIVE COMMANDS

Once in interactive mode, parted offers a range of commands to manage partitions:
help: Display help for commands.
mklabel label-type: Create a new disk label (e.g., gpt, msdos).
mkpart part-type name fs-type start end: Make a partition.
rm number: Delete partition number.
resize number start end: Resize partition number.
print: Display the partition table.
select device: Select a different device to work on.
unit unit-type: Set the default unit for sizes (e.g., GiB, s for sectors).
quit: Exit parted.

UNITS AND SIZES

parted often defaults to MiB or GiB for displaying sizes but allows users to specify units (e.g., 500MB, 10GB, 100s for sectors) when creating or resizing partitions. The unit command within the interactive session can change the default display unit.

HISTORY

GNU Parted was developed by Andrew Clausen and released in 1998 as part of the GNU project. It was designed to be a more modern and flexible alternative to existing tools like fdisk, supporting a wider range of partition table types (including GPT) and providing functionality for resizing and moving partitions, which fdisk typically lacks. Its interactive mode has been a core feature since its inception, providing a guided way to manage disk layouts. Over the years, it has become a standard utility in most Linux distributions.

SEE ALSO

fdisk(8), gdisk(8), cfdisk(8), sfdisk(8), mkfs(8), resize2fs(8)

Copied to clipboard