Linux parted Command: Inspect and Manage Partitions

parted is a GNU tool that queries disk partition tables and creates, deletes, or resizes partitions. You must strictly separate the task of reading disk structures from the actual modification task.

print shows the current partition table, while print free also displays the free space between partitions. The interactive modification commands of parted can be applied to the disk immediately without waiting for a separate save button. resizepart changes partition boundaries, and resizing the file system is a separate procedure.

Basic syntax

parted [option] [disk] [command]

The installed implementation and options may vary depending on the distribution. Check the current system documentation with man parted.

Examples

Viewing all disk structures

Check the partition table for each disk recognized by the system.

sudo parted -l

Free space on a specific disk

View the target disk and partition boundaries in read-only mode.

sudo parted /dev/sdb unit MiB print free

Contrast with another tool

Check the device model and capacity along with the current mount status.

lsblk -o NAME,SIZE,MODEL,TYPE,MOUNTPOINTS

Distinguishing Partition Boundaries and File Systems

parted print shows the partition table type of the disk and the start and end positions of partitions. The inquiry command does not create partitions or format file systems.

sudo parted /dev/sdb print

Structure of the example output (numbers vary by device):

Model: ...
Disk /dev/sdb: 20.0GB
Partition Table: gpt
Number  Start   End     Size    File system  Name

Creating or resizing partitions is separate from changing the size of the file system. Changing boundaries in parted does not automatically and safely expand or shrink the existing file system. In particular, shrinking requires checking data backup, whether it can be unmounted, and tool support for each file system first.

Main Options and Format

Options/Format Description
-l List the partition tables of all devices.
-s Run in script mode. Verification procedures may be reduced during changes.
unit unit Set the display and input units.
print free Display partitions and free space.
resizepart number end Change the end boundary of the partition. The file system size is separate.

Precautions when using

mklabel replaces the existing partition table and rm deletes partition entries, so do not run without a backup. -s can reduce interactive protection during modification operations. When changing sizes, plan the order of file system, encryption, and LVM layers together, and follow maintenance procedures on disks used in real environments.

Frequently Asked Questions

Do changes need to be saved before quitting parted?

Interactive parted change commands are usually applied to the disk immediately. Thinking of it like fdisk, where you save at the end with w, is dangerous.

Change boundaries in a new image file rather than a real disk

This example edits only a newly created 64 MiB file owned by the user. It does not use a /dev device, mount anything, or create an actual filesystem. Use Linux with GNU Parted and truncate installed. ext4 in mkpart is a partition type hint, not a call to mkfs.ext4. Script mode reduces prompts, so never substitute a production disk path for the image file.

(
set -eu
labdir=$(mktemp -d)
image="$labdir/disk.img"
truncate -s 64M "$image"
parted --script "$image" mklabel gpt
parted --script "$image" mkpart lab ext4 1MiB 33MiB
parted "$image" unit MiB print free
parted --script "$image" resizepart 1 49MiB
parted "$image" unit MiB print free
printf 'Lab image: %s\n' "$image"
)

The first output shows GPT partition 1 starting near 1 MiB and ending near 33 MiB; after resizepart its end is near 49 MiB. Display rounding can vary. No filesystem was created, so the lab verifies partition boundaries only. A real disk requires separate consideration of each layer’s supported growth or shrink operations and order. For cleanup, remove only disk.img in the temporary directory printed by this lab, never a real /dev device.

Official Documentation

The exact behavior of options and implementation differences can be checked in the official parted documentation.