parted is GNU’s partition editor. It does the same job as fdisk, but it’s easy to use non-interactively in scripts, it handles sizes in human units and percentages, and it can resize partitions. It’s the common choice for big disks on dedicated servers and for provisioning scripts.

Important difference from fdisk: parted applies every command immediately. There’s no “write” step to back out of. Check the device name twice.

Inspect disks

sudo parted -l                       # all disks
sudo parted /dev/sdb print           # one disk
sudo parted /dev/sdb unit GiB print  # in GiB

Interactive mode

sudo parted /dev/sdb
(parted) mklabel gpt
(parted) mkpart data ext4 1MiB 100%
(parted) print
(parted) quit
  • mklabel gpt creates a new GPT partition table. It erases the existing table.
  • mkpart NAME FSTYPE START END creates a partition. The FSTYPE here only sets a type hint. It doesn’t format anything.
  • Starting at 1MiB and ending at 100% gives one partition using the whole disk, correctly aligned.

Script mode

-s (script) runs without prompts. That’s perfect for automation:

sudo parted -s /dev/sdb mklabel gpt
sudo parted -s /dev/sdb mkpart data ext4 1MiB 100%
sudo parted -s -a optimal /dev/sdb mkpart primary 1MiB 50%

Multiple partitions in one go:

sudo parted -s /dev/sdb -- mklabel gpt \
  mkpart data1 ext4 1MiB 1TiB \
  mkpart data2 xfs 1TiB 100%

The -- stops parted from treating negative values (like -1s for “the last sector”) as options.

Alignment

Misaligned partitions slow down SSDs and RAID arrays. Use 1MiB or percentage boundaries and you’re aligned. To check:

sudo parted /dev/sdb align-check optimal 1
# 1 aligned

Flags

sudo parted -s /dev/sdb set 1 lvm on      # LVM physical volume
sudo parted -s /dev/sdb set 1 raid on     # mdadm member
sudo parted -s /dev/sdb set 1 esp on      # EFI system partition
sudo parted -s /dev/sdb set 1 bios_grub on   # BIOS boot partition on GPT

Resize a partition

parted can grow a partition into free space that follows it:

sudo parted /dev/sdb resizepart 1 100%

Then grow the filesystem inside it:

sudo resize2fs /dev/sdb1      # ext4
sudo xfs_growfs /mnt/data     # XFS (by mount point)

For the root disk of a VPS after a plan upgrade, growpart is simpler and safe on mounted partitions. See resize a disk partition.

Shrinking a partition is possible, but you must shrink the filesystem first. XFS can’t shrink at all. Take a backup first.

Remove a partition

sudo parted /dev/sdb rm 2

Full example: new data disk on a dedicated server

DISK=/dev/sdb
sudo parted -s "$DISK" mklabel gpt mkpart data ext4 1MiB 100%
sudo partprobe "$DISK"
sudo mkfs.ext4 -L data "${DISK}1"
sudo mkdir -p /mnt/data
UUID=$(sudo blkid -s UUID -o value "${DISK}1")
echo "UUID=$UUID /mnt/data ext4 defaults,noatime,nofail 0 2" | sudo tee -a /etc/fstab
sudo systemctl daemon-reload && sudo mount -a
df -h /mnt/data

NVMe partitions are named with a p: /dev/nvme1n1p1. See mkfs and fstab.

parted vs fdisk vs gdisk

Tool Strengths
fdisk Familiar interactive tool, changes held until w
parted Script-friendly, human units, resizing, immediate changes
gdisk / sgdisk GPT specialist, can convert MBR to GPT, good scripting with sgdisk
sfdisk Dump and restore partition tables (sfdisk -d /dev/sda > table.txt)

All of them create compatible GPT tables. Use whichever you’re comfortable with. See fdisk.

Common messages

“The resulting partition is not properly aligned for best performance” — use 1MiB or percentage boundaries instead of sectors or megabytes.

“Partition(s) on /dev/sdb are being used” — partitions are mounted or part of RAID or LVM. Unmount or deactivate them first.

“You requested a partition from X to Y … The closest location we can manage is …” — the exact boundaries aren’t possible. Accept the suggestion if it’s close, or use percentages.

Quick reference

Task Command
List all sudo parted -l
New GPT sudo parted -s /dev/sdb mklabel gpt
Whole-disk partition sudo parted -s /dev/sdb mkpart data ext4 1MiB 100%
Set flag sudo parted -s /dev/sdb set 1 lvm on
Grow partition sudo parted /dev/sdb resizepart 1 100%
Check alignment sudo parted /dev/sdb align-check optimal 1
Delete sudo parted /dev/sdb rm 1

Related: LVM guide and software RAID.

  • Linux
  • Storage
  • Command Line