Linux online course

GNU Parted Utility: List, Create, and Delete Linux Disk Partitions

Learn how to use GNU Parted to inspect partition tables, choose aligned boundaries, create or delete partitions, and prepare new storage safely.

GNU Parted is an interactive, text-based Linux utility for examining and modifying partition tables on block devices. A block device is a disk-like device represented by a path such as /dev/sda or /dev/nvme0n1.

A whole disk and its partitions are different device objects. For example, /dev/sda refers to an entire SATA or SCSI-style disk, while /dev/sda1 refers to one partition recorded on that disk. Similarly, /dev/nvme0n1 is a whole NVMe disk and /dev/nvme0n1p1 is one of its partitions.

What GNU Parted Manages

A partition table, also called a disk label, is metadata that records partition boundaries and attributes on a disk. Parted displays and changes this metadata; it does not normally create the filesystem that stores files inside a partition.

Deleting a partition removes its entry from the partition table. It is not the same as securely erasing the data that used to occupy that region. The old data may remain recoverable until it is overwritten, while the operating system can no longer access it through the deleted partition entry.

Partition Table Formats

Partition-table capabilities and terminology depend on the disk-label type. Common formats supported by Parted include the following:

  • MBR (msdos): A legacy format with limits on primary partitions. It supports an extended partition containing logical partitions.
  • GPT: A modern format designed for large disks and many partitions. GPT does not use extended or logical partitions.
  • APM: Apple Partition Map, historically associated with older Apple systems.
  • BSD disk label: A disk-label scheme used by BSD-derived systems.
FeatureMBRGPT
Primary partitionsUses directly defined primary entries, traditionally limited in numberUses a larger set of regular partition entries; the MBR primary-partition limit does not apply
Extended and logical partitionsAn extended partition can contain logical partitionsNot used
Typical use casesLegacy firmware and older operating systemsModern systems, large disks, and UEFI-based installations
Parted mkpart typeMay require primary, extended, or logical, depending on the layoutNormally creates a regular GPT partition; extended is invalid

MBR Partition Terms

  • A primary partition is a partition directly defined by an MBR partition entry.
  • An extended partition is an MBR container used to hold logical partitions.
  • A logical partition is a partition located inside an extended partition.

Start an Interactive Parted Session

Parted normally requires administrative privileges because it writes partition-table metadata. The command pattern is:

sudo parted /dev/sda

Replace /dev/sda only after confirming that it is the intended disk. Device names differ for NVMe, virtual, and removable storage. A read-only inventory command such as lsblk can help identify disks before opening Parted.

After startup, Parted displays an interactive prompt. Commands entered at that prompt apply to the selected device:

(parted)

For example, opening /dev/sda does not select /dev/sdb or one of its partitions. Every command in that session operates on the disk selected when Parted was launched.

Inspect the Current Partition Layout

Use print at the Parted prompt:

(parted) print

The output normally includes the disk path, model, capacity, sector size, partition-table type, and a partition table. Before changing anything, confirm that these details match your expectations.

Important columns include:

  • Number: The partition number used by commands such as rm.
  • Start and End: The boundaries of the partition on the disk.
  • Size: The space between those boundaries.
  • File system: A detected filesystem or partition-related indicator, when available.
  • Flags: Attributes such as boot-related or partition-role flags.

To inspect available unused regions in more detail, use:

(parted) print free

Do not choose boundaries or a partition number until you have reviewed this output. In particular, confirm that a proposed range lies entirely in free space and does not overlap an existing partition.

Units and Partition Boundaries

Parted can display and accept positions using units such as decimal MB and GB, binary MiB and GiB, disk sectors, and percentages. Default display units may be decimal megabytes, so an output of 3000MB is not necessarily the same number of bytes as 3000MiB.

Set an explicit unit when precise interpretation matters:

(parted) unit MiB
(parted) print

Partition boundaries should be aligned, meaning positioned on suitable storage boundaries. Good alignment avoids inefficient input/output and is especially important for SSDs, advanced-format disks, and some virtual storage. Use an explicit unit and sensible aligned values, or let Parted apply its alignment policy when available. Never assume that a rounded boundary is valid without checking the free-space output.

Creating a Partition with mkpart

The mkpart command starts partition creation. Depending on the disk-label type, it may request:

  • A partition type, such as primary, extended, or logical on MBR.
  • An intended content or filesystem hint, depending on the Parted version and interactive questions.
  • A start boundary.
  • An end boundary.

The filesystem hint describes the intended content; it does not format the partition. Creating a partition does not create a usable ext4, XFS, or other filesystem.

Example: Approximately 3 GB MBR Extended Partition

This example applies only to an MBR-formatted disk with a suitable unused region. First inspect the disk:

sudo parted /dev/sda
(parted) print free
(parted) unit MB

If the free region permits boundaries near 1000 MB and 4000 MB, the interactive command can be illustrated as:

(parted) mkpart extended 1000MB 4000MB

The range is approximately 3 GB using decimal megabytes. It is only an example: adjust both boundaries to the actual free space, avoid overlap, and use aligned positions. On some versions, Parted asks questions interactively instead of accepting all values on one line.

On a GPT disk, do not request an extended partition. Use a regular GPT partition through the prompts, supplying a suitable filesystem hint if requested:

(parted) mkpart

Follow the prompts for the intended content and valid start and end boundaries. Then inspect the result:

(parted) print

Verify the new partition number, start, end, size, filesystem indicator, and flags. Also confirm that the remaining free space is what you expect.

Deleting a Partition with rm

First identify the correct partition number with print. Then remove its partition-table entry:

(parted) print
(parted) rm 3
(parted) print

rm 3 means “remove partition number 3” from the selected disk. The final print is required verification: confirm that the entry is gone and that the region is now shown as free space.

Saving Changes and Exiting

Reread the final partition table before leaving Parted or proceeding to filesystem creation. In the normal workflow, quit exits the interactive session and finalizes pending changes:

(parted) print
(parted) quit

If the final layout is not correct, stop and investigate before formatting or mounting anything.

Example Partitioning Workflow

StageActionVerification
Select diskIdentify disks with a non-destructive listing command, then run sudo parted /dev/sdaCheck the device name, model, and capacity
Inspect layoutRun print free and select explicit units if neededLocate partition numbers and unused space
Create partitionRun mkpart with a valid type, hint, and non-overlapping boundariesEnsure the command accepts the requested disk-label-specific type
Review resultRun printCheck number, boundaries, size, filesystem indicator, and flags
Delete partitionRun rm with the verified partition numberRun print again and confirm free space
Exit and format if neededRun quit, then create a filesystem only on the verified new partitionCheck the kernel, filesystem signature, and mount result

After Creating a Partition

A new partition normally needs a filesystem before it can be mounted and used for files. For example, after replacing N with the verified partition number, an ext4 filesystem can be created with:

sudo mkfs.ext4 /dev/sdaN

After formatting, mount the filesystem at a suitable mount point and verify that it is available. If it must be mounted automatically at boot, configure a persistent mount using its stable identifier in /etc/fstab. Also check whether the kernel has recognized the updated partition layout. If other tools do not show the new partition immediately, re-read the partition table with an appropriate system tool or reconnect/reboot when necessary. Do this only after ensuring affected partitions are not mounted or in use.

Troubleshooting

The Wrong Disk Was Selected

If the device name, size, model, or layout shown by print does not match expectations, exit without making further changes. Recheck the disks with a read-only listing command and reopen only the verified device.

mkpart Rejects the Requested Type

An extended partition is valid for an MBR disk but not for GPT. Run print and check the disk-label type. Use a GPT-compatible regular partition, or use MBR only when its limitations are acceptable.

The Boundaries Overlap a Partition

The requested range may fall inside an existing partition or outside available free space. Run print free, choose a range fully marked as free, and retry with valid aligned boundaries.

The New Partition Is Not Visible

The kernel or another storage tool may still have a cached partition table. Re-read the table with an appropriate system tool, or reconnect/reboot when necessary. Do not do this while affected partitions are mounted or actively used.

The Partition Cannot Be Mounted

Possible causes include no filesystem, an incorrect partition path, or filesystem errors. Verify the device path, inspect its filesystem signature, create a filesystem if the partition is intentionally blank, and then mount the correct path.

Permission Denied or the Table Cannot Be Written

Parted may not have administrative privileges, or the disk may be read-only or in use. Start it with appropriate privileges and check whether mounted filesystems, swap, RAID, or LVM are using the target device.

Command Reference

CommandPurposeKey inputs or cautions
printDisplays disk details and partition entriesUse before and after changes; print free also shows unused regions
mkpartCreates a partition entryProvide the disk-label-appropriate type or content hint and valid start/end boundaries
rmRemoves a partition-table entryConfirm the partition number with print; data may become inaccessible
unitChanges display and input unitsUnits include MB, MiB, GB, GiB, sectors, and percentages
quitLeaves the interactive sessionReview the final table first; this normally finalizes pending changes

Key Exam Notes

  • Parted manages partition tables on whole block devices; a partition such as /dev/sda1 is contained by a disk such as /dev/sda.
  • MBR supports primary, extended, and logical arrangements; GPT does not use extended partitions.
  • print reveals the disk label, partition numbers, boundaries, sizes, filesystem indicators, and flags.
  • rm removes a partition-table entry; it does not securely erase the former contents.
  • mkpart creates a partition entry, not a filesystem.
  • Always verify the device and back up data before making partition-table changes.

For related Linux command-line foundations, see Linux, showing the full path of shell commands, and the Linux file structure.