Mastering Parted: From MBR/GPT Basics to Automated Disk Partitioning
This guide explains the purpose and advantages of the Parted tool, compares MBR and GPT partition tables, demonstrates interactive and scripted usage with detailed command examples for creating, deleting, formatting, and mounting partitions on large disks, and provides a complete end‑to‑end workflow.
Parted Overview and Purpose
Parted is a disk (or RAID) partitioning and management tool that supports disks larger than 2 TB, unlike the traditional MBR scheme which limits to four primary partitions and cannot handle disks over 2 TB. It works with various file systems such as ext2, ext3, ext4, xfs, FAT, HFS, and more.
MBR vs. GPT
MBR (Master Boot Record) supports up to four primary partitions and cannot format disks larger than 2 TB. GPT (GUID Partition Table) overcomes these limits and is recommended for large disks.
Interactive Usage of Parted
# Start Parted on /dev/sdb
(parted) mklabel gpt
(parted) mkpart p1 xfs 0% 100%
(parted) print
# Example output
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name
1 1049kB 107GB 107GB xfs p1Deleting a Partition
# Start Parted on /dev/sdb
(parted) rm 1
(parted) print
# Remaining partitions after deletion
Number Start End Size File system Name
2 10.0GB 53.7GB 43.7GB xfs primary
3 53.7GB 107GB 53.7GB xfs primaryScripted (Non‑Interactive) Mode
Use the -s or --script option to prevent prompts, enabling automation in scripts.
Defining Partition Types and Viewing Information
# Create GPT label without prompts
parted -s /dev/sdb mklabel gpt
# View partition table
parted /dev/sdb printCreating and Deleting Partitions
The general command format is:
parted <disk> mkpart <type> [filesystem] <start> <end>Examples:
Create a single primary partition covering the whole disk: parted /dev/sdb mkpart primary xfs 0% 100% Create multiple primary partitions: parted /dev/sdb mkpart primary xfs 1G 10G, parted /dev/sdb mkpart primary xfs 10G 50%,
parted /dev/sdb mkpart primary xfs 50% 100%Formatting and Mounting
# Format partition 2 as XFS
mkfs.xfs /dev/sdb2
# Create mount point and mount
mkdir /data
mount /dev/sdb2 /data
# Verify
df -hT /dataComplete Example: 100 GB Disk
Goal: Use Parted to create a single partition that occupies the entire 100 GB disk and mount it to /data.
# Set GPT label
parted /dev/sdb mklabel gpt
# Create partition covering 0%–100%
parted /dev/sdb mkpart primary xfs 0% 100%
# Format and mount
mkfs.xfs /dev/sdb1
mkdir /data
mount /dev/sdb1 /data
# Add to /etc/fstab for auto‑mount
/dev/sdb1 /data xfs defaults 0 0Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Raymond Ops
Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
