🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

parted Command

Advanced Disk & Storage man(8)

GPT and MBR partition management tool

📅 Updated: Mar 16, 2026
SYNTAX
parted [OPTIONS] [DEVICE] [COMMAND]

What Does parted Do?

The parted command is a disk partitioning tool that supports both GPT (GUID Partition Table) and MBR (Master Boot Record) partition schemes. Unlike fdisk which historically only supported MBR, parted handles GPT partitions natively, making it essential for modern systems with drives larger than 2TB.

parted supports creating, resizing, moving, and deleting partitions on hard drives, SSDs, and other block devices. It can work in both interactive and scripted (non-interactive) modes, making it suitable for both manual administration and automated provisioning.

One of parted's unique features is the ability to resize partitions — growing or shrinking them without data loss (when combined with filesystem resize tools). This makes it invaluable for server administration where storage requirements change over time.

For enterprise environments using LVM, RAID, or complex storage configurations, parted is typically the first step in preparing physical volumes before creating LVM physical volumes (pvcreate), volume groups, and logical volumes.

Options & Flags

OptionDescriptionExample
print Display partition table of a device sudo parted /dev/sda print
mklabel gpt Create a new GPT partition table sudo parted /dev/sdb mklabel gpt
mkpart Create a new partition sudo parted /dev/sdb mkpart primary ext4 0% 100%
resizepart NUM END Resize a partition to new end position sudo parted /dev/sda resizepart 2 100%
rm NUM Delete a partition by number sudo parted /dev/sdb rm 1
set NUM FLAG on/off Set a flag on a partition (boot, lvm, raid) sudo parted /dev/sda set 1 boot on
-l List partition tables on all block devices sudo parted -l
-s Script mode - never prompt for user input sudo parted -s /dev/sdb mklabel gpt
align-check optimal NUM Check if partition is optimally aligned sudo parted /dev/sda align-check optimal 1

Practical Examples

#1 View partition table

Display the partition table with sizes, filesystem types, and flags.
$ sudo parted /dev/sda print
Output: Model: ATA VBOX HARDDISK (scsi)\nDisk /dev/sda: 107GB\nPartition Table: gpt\n\nNumber Start End Size File system Name Flags\n 1 1049kB 538MB 537MB fat32 EFI boot, esp\n 2 538MB 107GB 107GB ext4 primary

#2 Create GPT partition table on new disk

Initialize a new disk with GPT partition table. Required before creating partitions. WARNING: destroys all existing data.
$ sudo parted -s /dev/sdb mklabel gpt

#3 Create a single partition using full disk

Create a single partition spanning the entire disk with optimal alignment using percentages.
$ sudo parted -s /dev/sdb mkpart primary ext4 0% 100%

#4 Create multiple partitions

Split a disk into two equal partitions.
$ sudo parted -s /dev/sdb mkpart primary ext4 0% 50% && sudo parted -s /dev/sdb mkpart primary ext4 50% 100%

#5 Resize a partition

Extend partition 2 to use all available space. Follow with resize2fs /dev/sda2 for ext4 or xfs_growfs for XFS.
$ sudo parted /dev/sda resizepart 2 100%

#6 Set LVM flag

Mark partition 1 as an LVM physical volume. Required before using pvcreate.
$ sudo parted -s /dev/sdb set 1 lvm on

#7 List all disk partitions

Show partition tables for all block devices in the system.
$ sudo parted -l

Tips & Best Practices

parted changes are immediate: Unlike fdisk which requires writing changes, parted applies changes IMMEDIATELY. There is no undo. Double-check the device path before any destructive operation.
Use percentages for alignment: Use 0% and 100% instead of exact byte values for optimal partition alignment. This ensures partitions align to physical sector boundaries.
GPT vs MBR: Use GPT for disks larger than 2TB, UEFI systems, or when you need more than 4 primary partitions. MBR is only needed for legacy BIOS systems.
Resize requires filesystem resize too: parted resizepart only changes the partition boundary. You also need to resize the filesystem: resize2fs (ext4), xfs_growfs (XFS), or btrfs filesystem resize (Btrfs).

Frequently Asked Questions

What is the difference between parted and fdisk?
parted supports both GPT and MBR, can resize partitions, and applies changes immediately. fdisk traditionally only supported MBR (modern fdisk handles GPT too) and writes changes only when you press w.
How do I create a GPT partition on a new disk?
sudo parted -s /dev/sdX mklabel gpt && sudo parted -s /dev/sdX mkpart primary ext4 0% 100% && sudo mkfs.ext4 /dev/sdX1
Can I resize a partition without data loss?
Growing a partition is safe — extend with parted, then resize the filesystem. Shrinking requires unmounting, resizing the filesystem FIRST (resize2fs), then shrinking the partition with parted.
How do I convert MBR to GPT?
Use gdisk (not parted) for non-destructive conversion: sudo gdisk /dev/sda, then press w to write GPT. Backup data first. parted mklabel gpt destroys all data.

Master Linux with Professional eBooks

Curated IT eBooks covering Linux, DevOps, Cloud, and more

Browse Books →