Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

parted

Create, delete, resize and list partitions — in a menu or with one command line (good for scripts).

Level
RHCSA exam
Group
Disks and file systems
Needs root
Yes
Package
parted

What it does

parted DEVICE opens a prompt; parted DEVICE COMMAND runs one command. Unlike fdisk, parted writes every change at once. Positions are start and end (like 1MiB 1GiB); use MiB/GiB for exact powers of 1024 and good alignment.

-s (script mode) never asks questions — so be careful.

How to write it

parted [OPTION]... [DEVICE [COMMAND [ARGUMENT]...]...]

Main parts

print [free|all]
Show the table (and free space or all devices).
mklabel gpt|msdos
New empty partition table (deletes all partitions).
mkpart [NAME|TYPE] [FSTYPE] START END
New partition (GPT: a name; MBR: primary/extended/logical).
rm N
Remove partition N.
resizepart N END
Change the end of a partition.
name N NAME
Name a GPT partition.
set N FLAG on|off
Set a flag: boot, esp, lvm, raid, swap, bios_grub, msftdata …
toggle N FLAG
Toggle a flag.
type N TYPE-UUID
Set the GPT type UUID (newer parted).
unit UNIT
Units: s, B, KiB, MiB, GiB, %, compact …
align-check minimal|optimal N
Check alignment.
rescue START END
Find a lost partition.
disk_set / disk_toggle FLAG
Flags of the whole disk.
select DEVICE
Choose another disk.
quit
Leave.

Options 8

Most used

-s, --script
Never ask; for scripts.
-l, --list
List the tables of all disks.
-a, --align none|cylinder|minimal|optimal
Alignment of new partitions (default optimal).
-m, --machine
Machine-readable output.
-j, --json
JSON output.
-f, --fix
Answer "fix" to questions in script mode.
-h, --help
Show help.
-v, --version
Show the version.

Examples 10

$ run as a normal user# run as root (or with sudo)

  1. 1Show a disk

    parted /dev/vdb print

    Table type, partitions, sizes and flags.

  2. 2New GPT table

    parted -s /dev/vdb mklabel gpt

    Deletes all partitions on the disk at once.

  3. 3Create partitions in one go

    parted -s /dev/vdb mkpart data xfs 1MiB 2GiB
    parted -s /dev/vdb mkpart swap linux-swap 2GiB 3GiB

    GPT: the first word is the partition name.

  4. 4A partition for LVM

    parted -s /dev/vdb mkpart pv1 3GiB 100%
    parted -s /dev/vdb set 3 lvm on

    100% = to the end of the disk.

  5. 5Show free space in MiB

    parted /dev/vdb unit MiB print free

    Where can a new partition go?

  6. 6MBR with logical partitions

    parted -s /dev/vdc mklabel msdos mkpart primary 1MiB 1GiB mkpart extended 1GiB 100% mkpart logical 1GiB 2GiB

    More commands in one line.

  7. 7Grow a partition to the end of the disk

    parted /dev/vdb resizepart 3 100%

    After a VM disk was made bigger; then grow the PV or file system.

  8. 8EFI system partition

    parted -s /dev/vdd mkpart ESP fat32 1MiB 601MiB set 1 esp on

    For a UEFI boot disk.

  9. 9List all disks

    parted -l

    Every disk with its table.

  10. 10JSON for automation

    parted -j /dev/vdb print | jq '.disk.partitions[].size'

    Newer parted versions.

Watch out

  • parted writes at once: there is no "quit without saving".
  • mkpart does not create a file system; use mkfs afterwards (the FSTYPE word only sets the type).

Exit codes

0 :: Done. 1 :: Error.

Full manual

This page explains the command in simple words. The original manual has every detail.

In your terminal: man 8 parted