7.2 GNU Parted & Partition Table Management (104.1)

Key Takeaways

  • GNU `parted` is a versatile partition manipulation program supporting both legacy MBR (`msdos`) and modern GPT (`gpt`) disk label types across disks of any capacity.
  • Unlike `fdisk` and `gdisk` (which stage operations in memory until explicitly saved), GNU `parted` commits partition modifications IMMEDIATELY to the physical storage disk upon execution.
  • The non-interactive scripting mode (`parted -s`) suppresses interactive confirmation prompts, enabling automated partitioning in unattended installation and provisioning scripts.
  • The `mkpart` command creates a partition table entry and sets its type flag, but it does NOT format or create an actual filesystem on that partition.
  • Proper partition alignment on 1 MiB (2048-sector) boundaries avoids performance degradation on 4096-byte physical sector Advanced Format drives and SSD storage.
Last updated: August 2026

7.2 GNU Parted & Partition Table Management

Quick Summary: GNU parted is an advanced disk partitioning and partition resizing tool that supports both MBR (msdos) and GPT (gpt) partition tables, as well as specialized disk labels like sun, mac, and bsd. Unlike traditional utilities (fdisk/gdisk) that buffer edits in RAM, parted applies changes immediately to the disk as each command executes. Using non-interactive scripting flags (-s), administrators can automate disk label creation (mklabel), partition creation (mkpart), and partition flag manipulation (set) in unattended provisioning workflows.


1. GNU Parted Architecture & Core Differences

GNU parted (Partition Editor) was developed to provide a unified command interface capable of managing disks larger than 2 TiB and handling multiple partition table formats seamlessly.

Critical LPIC-1 Distinctions: parted vs. fdisk

  1. Immediate Execution Model: In fdisk and gdisk, all partition deletions, creations, and type alterations are held safely in a volatile memory buffer until you explicitly type w. In GNU parted, every command alters the disk immediately upon pressing Enter. There is no "save and exit" or "quit without saving" safety net once a destructive command (such as rm or mklabel) is entered!
  2. Universal Partition Scheme Support: parted handles MBR (msdos), GPT (gpt), Sun disklabels (sun), Apple Partition Maps (mac), and raw loop devices (loop).
  3. Filesystem Awareness vs Creation: While parted accepts filesystem type arguments in its mkpart syntax (e.g., ext4, xfs, linux-swap), parted only sets the partition type ID / GUID. It does not format or lay down filesystem metadata on the disk sectors. Administrators must still invoke mkfs or mkswap after using parted.

2. Command Syntax & Global Options

GNU parted operates in two distinct operational modes: interactive mode and command-line (scriptable) mode.

Command Syntax:
  parted [options] [device [command [options...]]]

Global Command-Line Options

Option FlagLong FormOperational Description & LPIC-1 Context
-s--scriptScript mode (Never prompts the user). Suppresses interactive prompts, confirmation warnings, and automatically selects default answers or aborts on fatal errors. Essential for automated provisioning.
-m--machineMachine-parseable output. Outputs information as colon-delimited text (/dev/sda:500GB:scsi:512:4096:gpt:...) suitable for parsing via awk, cut, or Python.
-l--listLists the partition layout, model, disk size, and flags for all attached block devices.
-a <type>--align <type>Sets partition alignment policy for newly created partitions: none, cylinder, minimal, or optimal (default: optimal).
-h--helpDisplays command-line syntax help.
-v--versionDisplays GNU parted version information.
# Inspect partition layouts across all system storage drives non-interactively
# parted -l
Model: ATA Micron_5300_MTFD (scsi)
Disk /dev/sda: 480GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name  Flags
 1      1049kB  538MB   537MB   fat32              boot, esp
 2      538MB   480GB   479GB   ext4

3. Core Interactive Commands Reference

When invoked with just a device path (e.g., parted /dev/sdb), parted enters its interactive prompt (parted).

CommandArgumentsPurpose & Detailed Behavior
help[command]Displays available command list or detailed syntax for a specific sub-command.
print`[freedevices
mklabel<label-type>Creates a new partition table / disklabel (e.g., mklabel gpt or mklabel msdos). WARNING: Destroys all existing partition table records immediately! Synonym: mktable.
mkpart<type> [fstype] <start> <end>Creates a new partition. On MBR, <type> must be primary, extended, or logical. On GPT, <type> is typically set to primary or used as the partition name. <start> and <end> accept units (e.g., 1MiB, 50GiB, 100%).
rm<number>Deletes partition <number> immediately. No confirmation in script mode.
name<number> <name>Sets the UTF-8 partition name for partition <number> (GPT disks only; unsupported on MBR).
set<number> <flag> <state>Toggles partition flags on or off (state = on or off). Flags include: boot, esp, lvm, raid, hidden, swap, diag.
unit<unit>Changes the default unit of measurement used for displaying and entering sizes. Supported units: s (sectors), B, KiB, MiB, GiB, TiB, compact, %, cyl.
align-check`<optimalminimal> <num>`
resizepart<number> <end>Adjusts the ending position of partition <number> (grows or shrinks partition boundaries).
quit(none)Exits the interactive (parted) prompt.

💡 LPIC-1 Exam Fill-in-the-Blank Alert: What GNU parted sub-command initializes a new partition table (such as gpt or msdos) on a block storage device? Answer: mklabel (or mktable)

Loading diagram...
Drive Sector Alignment: Unaligned vs 1 MiB Aligned

4. Sector Alignment Mechanics & SSD / Advanced Format Performance

Modern hard drives utilize Advanced Format (AF) with 4096-byte (4 KiB) physical sectors (even though firmware emulates 512-byte logical sectors for backward compatibility, known as 512e). Similarly, Solid State Drives (SSDs) and NVMe media organize storage into 4 KiB, 8 KiB, or 16 KiB NAND flash memory pages.

The Misalignment Penalty

If a partition starts at an unaligned sector (such as legacy MBR sector 63), a single 4096-byte operating system cluster read or write straddles across two physical storage sectors. This triggers a catastrophic read-modify-write performance penalty (reducing storage I/O throughput by up to 30–50%).

The 1 MiB (2048-Sector) Alignment Standard

To ensure flawless physical sector alignment across all underlying storage architectures (4K HDDs, SSDs, hardware RAID stripes, and SAN LUNs), modern Linux partitioning starts the first partition at offset 1MiB (Logical Sector 2048, since 2048 × 512 bytes = 1,048,576 bytes = 1 MiB).

# Verify partition alignment using parted align-check
# parted /dev/sdb align-check optimal 1
1 aligned

5. Automated Partitioning with Non-Interactive parted -s

In system administration and DevOps automation, storage initialization scripts invoke parted with the -s (--script) flag. Multiple sub-commands can be chained sequentially in a single command invocation.

Real-World Scripting Examples

Example 1: Initializing a 100 GiB GPT Data Disk with Ext4 and Swap Partitions

# 1. Create GPT disklabel
# parted -s /dev/sdb mklabel gpt

# 2. Create primary ext4 data partition from 1MiB to 80GiB
# parted -s /dev/sdb mkpart primary ext4 1MiB 80GiB

# 3. Create swap partition from 80GiB to 100GiB
# parted -s /dev/sdb mkpart primary linux-swap 80GiB 100GiB

# 4. Set the LVM flag on partition 1 (if intended for LVM)
# parted -s /dev/sdb set 1 lvm on

# 5. Print resulting layout in mebibytes
# parted -s /dev/sdb unit MiB print

Example 2: Complete One-Liner for UEFI Boot Disk Setup

# Initialize GPT, create 512MiB EFI System Partition, and allocate remainder to root
# parted -s /dev/nvme0n1 \
    mklabel gpt \
    mkpart ESP fat32 1MiB 513MiB \
    set 1 esp on \
    mkpart ROOT ext4 513MiB 100%

⚠️ LPIC-1 Trap — The mkpart Filesystem Parameter: In parted -s /dev/sdb mkpart primary ext4 1MiB 10GiB, the token ext4 is strictly a partition type hint that sets the appropriate partition type ID in the partition table. It does NOT run mkfs.ext4! You must still execute mkfs.ext4 /dev/sdb1 before mounting the partition.

Example 3: Resizing a Partition with resizepart

# Grow partition 2 to fill disk up to 200 GiB mark
# parted -s /dev/sdb resizepart 2 200GiB
Test Your Knowledge

How does GNU parted differ fundamentally from fdisk when performing partition operations in interactive mode?

A
B
C
D
Test Your Knowledge

An administrator executes the following command on a new disk: parted -s /dev/sdb mklabel gpt mkpart primary ext4 1MiB 50GiB What is the exact state of /dev/sdb1 after this command completes successfully?

A
B
C
D
Test Your Knowledge

Which command-line option causes GNU parted to operate in non-interactive script mode, suppressing all user confirmation prompts and warnings?

A
B
C
D