System and processes

The parted command

Creates, deletes and inspects partitions on MBR or GPT disks.

Syntax

sudo parted [opciones] [dispositivo [comando [opciones]]]Try it in the terminal →

Most useful options

-l, --listPrints the partitions of every disk and exits, without entering interactive mode.
-s, --scriptNever asks anything. It is the mode for scripts.
-f, --fixIn script mode it answers fix to exceptions. Only in recent parted versions: use it if you know what will be fixed.
-j, --jsonJSON output. Only in recent parted versions.

Copy-ready examples

$ sudo parted -llists every disk and its partitions. Changes nothing.
$ sudo parted /dev/sdb unit GiB print freeshows the table of /dev/sdb in GiB, with the free gaps. Read only.
$ sudo parted -s /dev/sdb mklabel gpt mkpart P1 ext4 1MiB 100%warning: creates a new GPT table and one partition covering the whole disk. The previous table is gone: back up first and check that /dev/sdb is the right disk.

You can try them in the browser terminal: it does not touch your computer.

Typical mistakes

  • Each interactive command is applied to the disk when it runs. There is no save step as in fdisk: double-check before pressing Enter.
  • According to the manual, the kernel only knows about the changes once parted exits. Until then it may still see the old table.
  • On GPT tables, mkpart takes a name before the filesystem: mkpart P1 ext4 1MiB 100%. The manual says the name is required on GPT.
  • With MB or GB, parted computes a range and not an exact position. For exactness use s, MiB or GiB.

Differences from similar commands

  • fdisk: also creates partitions, but it applies changes only when you write the save command. parted applies them as each command runs.
  • mkfs.ext4: formats ext4 inside a partition. parted only defines the partition and its type.

FAQ

Can I list the disks without sudo?

Listing with -l usually also needs administrator rights, because it reads the /dev devices. To modify the table, sudo is always required.

How do I change the size of a partition?

With resizepart, which moves the end of the partition. The manual warns that it does not modify the filesystem inside: that step is separate.

Is there a way to undo a change?

There is no undo command and no history. Before touching a disk, keep its data somewhere else.

More System and processes commands

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course