Home / Alt manpages / parted(8)

  • parted(8)
  • Admin command
  • linux

Inspect and Safely Plan Disk Changes with parted

You will use GNU Parted to identify a disk, inspect its partition table, check alignment, and understand the commands that would change it. The examples target the installed GNU Parted 3.6 package. Allow 15 minutes for inspection, or longer if you need to confirm a device from a server inventory. The inspection steps are read-only. Partition-table changes are not.

You need a shell and the parted package. Most inspection commands can run as an ordinary user, although reading all block devices may require elevated access on your system. Have a current backup before changing a real disk. A partition table is not a safe place to experiment with a guessed device name.

1. Confirm the installed command

Start by checking which executable will run and which version it reports:

$ command -v parted
/usr/sbin/parted
$ parted --version
parted (GNU parted) 3.6

The exact path can differ. The version on this machine is package parted 3.6-4build1. Keep that detail with an incident record or change plan because option output and supported partition-table features can vary between releases.

Checkpoint

You have confirmed the command and version. If parted is missing, stop here and use your normal package-management process. Do not copy a partitioning binary from an untrusted source.

2. List disks without selecting one

Ask Parted to list the partition layouts it can see:

$ sudo parted --list

Use sudo only if the system refuses access to a device or omits information you need. The output normally identifies a device, its size, the partition-table type, and each partition's start, end, size, file system and flags. On a machine with no accessible block devices, there may be no useful output at all.

For a script or a tool that needs stable parsing, request machine-readable output:

$ sudo parted --machine --list
$ sudo parted --json --list

The installed binary accepts both --machine and --json. Machine output is intended for parsers; JSON is usually easier to inspect with tools such as jq. Do not parse the human-readable table with whitespace splitting when a structured mode is available.

Record the complete device path before continuing. A name such as /dev/sda or /dev/nvme0n1 is a placeholder in this guide, not a recommendation for your host.

3. Inspect one named device

Once a device has been independently identified, print its table directly:

$ sudo parted /dev/DEVICE print
Model: YOUR-DISK-MODEL (scsi)
Disk /dev/DEVICE: ...
Partition Table: gpt

The model and sizes are examples of fields to look for, not output you should expect verbatim. Check that the device identity, capacity and partition-table type match your change record. If the command says the device is busy or reports an unknown table, do not respond by trying random repair or force options. Investigate mounts, encryption, software RAID and the storage inventory first.

Use print free when you need to see unallocated regions:

$ sudo parted /dev/DEVICE print free

Parted also supports print devices and print all. The first asks for available devices; the latter includes all found partitions. These commands display information. They do not create free space or move data.

4. Check alignment before planning a change

Misaligned partitions can reduce storage performance. Check a known partition number with each supported alignment test:

$ sudo parted /dev/DEVICE align-check minimal 1
$ sudo parted /dev/DEVICE align-check optimal 1

Replace 1 with the partition number shown by print. The command accepts minimal and optimal. Minimal alignment follows the device topology's minimum requirement; optimal alignment aims for the device's preferred boundary. Read the result rather than assuming that a partition number is aligned because it starts at a round-looking value.

When creating a partition interactively or with a command, the --align=optimal option selects optimal alignment for newly created partitions. It does not repair an existing partition:

$ sudo parted --align=optimal /dev/DEVICE print

This last command only demonstrates the option alongside a read-only command. It does not change the table.

5. Plan a new partition without touching the real disk

The commands that change state include mklabel, mkpart, rm, resizepart, set and name. A short command can have irreversible consequences. In particular, mklabel creates a new partition table and can make existing partitions inaccessible. Do not run the following forms on a real device until the target, backup and recovery plan have been reviewed.

$ sudo parted /dev/DEVICE mklabel gpt
$ sudo parted --align=optimal /dev/DEVICE mkpart primary ext4 1MiB 100%

For a GPT table, the installed manual requires a name with the form documented for GPT partition creation, while the file-system type is optional. The ext4 word here describes the intended partition type to Parted; it does not format the partition and does not create a file system. Formatting is a separate, destructive operation.

Safer planning uses a disposable test disk or virtual machine. If you use a loop-backed test image, verify the loop device before every command and detach it afterwards. Do not use a path copied from an example as a substitute for that verification. A real change should be preceded by a device inventory, an unmount check and a backup that has been tested.

6. Understand script mode and recovery boundaries

Interactive Parted can ask questions. The --script option prevents user intervention, which is useful for automation but dangerous if the target is wrong. It does not make a destructive command safe:

$ sudo parted --script /dev/DEVICE print

Use --fix only when you have deliberately decided how to handle an exception in script mode. It automatically answers "fix" to exceptions; it is not a general validation or repair switch. Never add it merely to make an unattended job continue.

Some changes have no simple undo. If rm deletes a partition entry, the usual recovery is to recreate the exact entry boundaries from a trusted record, or use a specialist recovery process if the boundaries are unknown. If resizepart changes a partition end, the manual says it does not resize the file system inside it. Coordinate partition and file-system resizing with the file-system's own tools, and keep the old layout and backup until the result has been checked.

7. Verify the result after an approved change

After a change window, reread the table and compare it with the approved layout:

$ sudo parted /dev/DEVICE print
$ sudo parted --json /dev/DEVICE print

Check the device, table type, start and end positions, partition names and flags. If the operation was intended to create a file system, verify that separately with a suitable read-only inspection command. Parted's successful exit status only tells you that its command completed; it does not prove that an application can mount or use the new layout.

Done means

  • You confirmed the installed GNU Parted version and the exact target device.
  • You inspected the table with print, and used structured output when a parser needed it.
  • You checked minimal or optimal alignment for existing partitions where relevant.
  • Every state-changing command had an approved target, backup and recovery plan.
  • You know that partition changes and file-system changes are separate operations.
  • You reread the final table and compared it with the intended layout.