Master Disk Partitioning with Parted: From GPT Setup to Automated Scripts
This guide explains the purpose and features of the Linux 'parted' tool, compares MBR and GPT partition tables, demonstrates interactive and scripted commands for creating, listing, and deleting partitions, and shows how to format and mount them, providing practical examples for managing large disks.
Parted Overview
Parted is a GNU tool for creating, deleting, resizing, moving, and copying partitions on hard disks, supporting disks larger than 2 TB and a variety of file systems (ext2, ext3, ext4, xfs, swap, FAT, HFS, etc.). It is useful for preparing space for new OS installations or reallocating disk usage.
MBR vs GPT
Traditional MBR partition tables support up to four primary partitions and cannot handle disks larger than 2 TB, making GPT the preferred format for large disks. Parted can create GPT tables with the mklabel gpt command.
Interactive Usage
Creating a Partition
$ parted /dev/sdb
(parted) mklabel gpt
(parted) mkpart p1 xfs 0% 100%
(parted) printThe tool prompts for confirmation before destroying existing labels.
Deleting a Partition
$ parted /dev/sdb
(parted) rm 1
(parted) printScripted Operations
Use the -s or --script option to suppress prompts, enabling non‑interactive scripts.
$ parted -s /dev/sdb mklabel gpt
$ parted -s /dev/sdb mkpart primary xfs 0% 100%Viewing Partition Information
$ parted /dev/sdb print
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 0% 100% 107GB xfs p1Formatting and Mounting
$ mkfs.xfs /dev/sdb1
$ mkdir /data
$ mount /dev/sdb1 /data
$ df -hT /dataThe resulting filesystem shows the expected size and usage.
Full Example: 100 GB Disk
parted /dev/sdb mklabel gpt
parted /dev/sdb mkpart primary xfs 0% 100%
mkfs.xfs /dev/sdb1
mount /dev/sdb1 /data
df -hT /data
# Add to /etc/fstab for automatic mounting
/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.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
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.
