parted

systemLinux/Unix
The parted command is one of the most frequently used commands in Linux/Unix-like operating systems. parted A disk partition manipulation program

Quick Reference

Command Name:

parted

Category:

system

Platform:

Linux/Unix

Basic Usage:

parted [options] [arguments]

Common Use Cases

    Syntax

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

    Options

    Option Description
    -a, --align=[none|cyl|min|opt] Set alignment for new partitions
    -h, --help Display help information
    -l, --list List partition layout on all block devices
    -m, --machine Display machine parseable output
    -s, --script Never prompt for user intervention
    -v, --version Display the version

    Common Commands:

    Command Description
    mklabel type Create a new disklabel (partition table) of type 'type' (e.g., 'gpt', 'msdos')
    mkpart [part-type name fs-type] start end Create a new partition, part-type is optional (primary/logical/extended), name is optional, fs-type is only for guidance
    print [number] Display the partition table or information about partition 'number'
    rm number Delete partition 'number'
    resizepart number end Resize partition 'number' to end at 'end'
    name number name Name partition 'number' as 'name'
    set number flag state Set 'flag' on partition 'number' to 'state' (on/off)
    unit unit Set the default unit to 'unit' (e.g., 's', 'B', 'MiB', 'GB')
    align-check type number Check if partition 'number' is aligned for 'type' (min/opt)
    rescue start end Rescue a lost partition between 'start' and 'end'
    help [command] Print general help, or help on 'command'
    quit Exit the program

    Examples

    How to Use These Examples

    The examples below show common ways to use the parted command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    # Basic Examples Basic
    sudo parted -l
    List all disk partitions.
    sudo parted /dev/sda print
    Display the partition table of /dev/sda.
    # Advanced Examples Advanced
    sudo parted /dev/sda mklabel gpt Create a new GPT partition table on /dev/sda. sudo parted /dev/sda mkpart primary ext4 0% 100% Create a primary partition using the entire disk. sudo parted /dev/sda mkpart primary ext4 1MiB 100MiB Create a primary partition between 1MiB and 100MiB. sudo parted /dev/sda resizepart 1 200MiB Resize partition 1 to 200MiB. sudo parted /dev/sda rm 2 Remove partition 2. sudo parted /dev/sda name 1 boot Name partition 1 as 'boot'. sudo parted /dev/sda set 1 boot on Set the boot flag on partition 1. sudo parted /dev/sda unit GB print Display the partition table with sizes in gigabytes.

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    GNU Parted is a powerful disk partition manipulation program that enables users to create, destroy, resize, move, and copy partitions on hard drives. As a command-line utility, it provides a more flexible and scriptable alternative to graphical partition managers, making it especially valuable for system administrators and advanced users who need precise control over disk organization. Unlike some other partitioning tools, Parted supports multiple partition table formats, including the traditional MBR (Master Boot Record) and the newer GPT (GUID Partition Table) which is required for disks larger than 2TB and for UEFI boot systems. This versatility makes Parted an essential tool in modern disk management scenarios. Key features of the parted command: 1. Multiple Partition Table Support: Parted can handle various partition table types, including msdos (MBR), gpt, aix, amiga, bsd, dvh, loop, mac, pc98, and sun. 2. Live Partition Manipulation: One of Parted's most significant advantages is its ability to resize partitions without data loss (though backups are always recommended), even while they're mounted in some cases. 3. Scriptable Operation: With its non-interactive mode, Parted can be easily incorporated into scripts for automated disk setup or maintenance tasks. 4. File System Awareness: While Parted doesn't handle file system creation or manipulation directly, it is aware of file system boundaries and can resize partitions with consideration for the file systems they contain. 5. Comprehensive Partition Management: Beyond basic creation and deletion, Parted offers advanced features like partition alignment optimization, flag management, and partition type specification. 6. Rescue Mode: Parted includes functionality to help recover lost or deleted partitions, which can be invaluable in data recovery scenarios. Common use cases for Parted include: - Setting up new hard drives with appropriate partition schemes - Converting between partition table types (e.g., from MBR to GPT) - Resizing partitions to allocate space efficiently - Creating complex partitioning layouts for specialized server configurations - Preparing disks for multi-boot systems - Troubleshooting partition-related issues - Automating disk configuration in deployment scripts While Parted is a powerful tool, it should be used with caution, especially when modifying existing partitions. Incorrect operations can lead to data loss, so it's crucial to understand the commands being executed and to maintain regular backups. Additionally, some operations like partition resizing might require additional steps to resize the file systems within those partitions, typically using file system-specific tools like resize2fs for ext filesystems. For users who prefer a graphical interface but want to leverage Parted's capabilities, GParted (GNOME Partition Editor) provides a GUI frontend to the Parted library, combining ease of use with powerful functionality.

    Related Commands

    These commands are frequently used alongside parted or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the parted command works in different scenarios.

    $ parted
    View All Commands