GNU Parted Cheat Sheet farukguler.com
⚠️ CRITICAL WARNING: Parted makes immediate, irreversible changes to disk structures. Always verify commands before execution as these operations can cause permanent data loss. Back up important data before partitioning operations.
Fundamentals
Basic Invocation
parted [OPTIONS] [DEVICE [COMMAND...]]
Standard invocation syntax
parted /dev/nvme0n1
Interactive mode for NVMe disk
parted -s /dev/sda mklabel gpt
Non-interactive (script) mode
NVMe Note: NVMe partitions are typically named like /dev/nvme0n1p1 (e.g., nvme0n1 = disk, p1 = first partition)
Interactive vs Script Mode
# Interactive (prompts for confirmation):
parted /dev/sda
# Script mode (no prompts, for automation):
parted -s /dev/sda mklabel gpt
Information Commands
print [free|all|devices|list]
Displays partition table in different views
unit s print
Show information in sectors
help [COMMAND]
Get detailed help for specific command
partprobe /dev/sda
Inform kernel about partition table changes
lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,UUID
View block devices and filesystems
Advanced Invocation Options
Option |
Description |
Example |
-l, --list |
List partition layouts on all block devices |
parted -l |
-m, --machine |
Machine-parsable output (for scripts) |
parted -m /dev/sda print |
-j, --json |
JSON format output |
parted -j /dev/sda print |
-a, --align |
Set alignment (none, cylinder, minimal, optimal) |
parted -a optimal /dev/sda |
-f, --fix |
Auto-answer "fix" in script mode |
parted -s -f /dev/sda mklabel gpt |
parted -j /dev/sda print
Example JSON output:
{
"disk": {
"path": "/dev/sda",
"size": "500GB",
"model": "Samsung SSD 870",
"partitions": [...]
}
}
Partition Table Operations
mklabel LABEL-TYPE
Create a new partition table (destroys existing table)
Supported Label Types
gpt
Modern GUID Partition Table (GPT)
Max partitions: 128 (standard), up to 264 theoretical
Max disk size: 8ZB
Features: Names, UUIDs, CRC32 checksums
msdos
Traditional MBR partition table
Max partitions: 4 primary (or 3+1 extended with logical drives)
Max disk size: 2TB
Features: Boot flag, simple structure
bsd
BSD disk label
Used on: BSD systems
sun
Sun disk label
Used on: Solaris/SunOS
Features: VTOC structure
MBR Limitation: MBR cannot address disks larger than 2TB. For disks >2TB, always use GPT.
Disk Flags (GPT Specific)
disk_set FLAG STATE
Modify disk-level flags (GPT only)
pmbr_boot
Sets protective MBR boot flag for BIOS compatibility
Values: on/off
implicit_partition_table
Enables implicit partition table (advanced use)
Values: on/off
Partition Operations
Partition Creation
mkpart [PART-TYPE] [FS-TYPE] START END
Create a new partition (does not create filesystem)
Parameter |
Description |
Examples |
PART-TYPE |
primary, extended, logical (for MBR) primary only for GPT |
primary, extended, logical |
FS-TYPE |
(Optional) Filesystem type hint (does not format) |
ext4, fat32, ntfs, xfs, btrfs, linux-swap |
START |
Partition start position |
1MiB, 2048s, 10%, 1GB |
END |
Partition end position |
100%, -1s (end of disk), 500GB |
ext2
ext3
ext4
fat16
fat32
xfs
btrfs
ntfs
hfs
linux-swap
Calculation: Partition size = END - START. For example, 1MiB-1001MiB equals exactly 1000MiB.
Advanced Partition Creation
mkpart PART-NAME PART-TYPE [FS-TYPE] START END
Create partition with name (GPT only)
mkpartfs PART-TYPE FS-TYPE START END
Create partition and filesystem (experimental, not recommended)
Partition Modification
rm NUMBER
Delete partition by number
resizepart NUMBER END
Resize partition (END position only)
move NUMBER START END
Move partition to new location
set NUMBER uuid 123e4567-e89b-12d3-a456-426614174000
Change partition UUID (GPT only)
cp [FROM-DEVICE] FROM-NUMBER TO-NUMBER
Copy partition (same or different device)
name NUMBER NAME
Set partition name (GPT only)
toggle NUMBER FLAG
Toggle partition flag state
align-check TYPE NUMBER
Check partition alignment (TYPE: minimal/optimal)
Partition Type and UUID
type NUMBER ID-or-UUID
Change partition type or UUID
System |
Value |
Description |
MBR |
0x83 |
Linux partition |
MBR |
0x82 |
Linux swap |
MBR |
0x8e |
Linux LVM |
GPT |
123e4567-e89b-12d3-a456-426614174000 |
Custom UUID format |
Lost Partition Recovery
rescue START END
Search for lost partitions in specified range
parted /dev/sda rescue 0% 100%
Search entire disk for lost partitions
TIP: Before recovery, check original disk geometry with cat /sys/block/sdX/size and sector size with cat /sys/block/sdX/queue/hw_sector_size
testdisk /dev/sda
Advanced recovery tool for complex cases
Partition Flags
set NUMBER FLAG STATE
Set partition flag (STATE: on/off)
boot
Bootable flag (MBR)
Table: MBR
Use: Mark active boot partition
esp
EFI System Partition
Table: GPT
Use: UEFI boot (typically FAT32 formatted)
bios_grub
BIOS boot partition
Table: GPT
Use: GRUB core.img location (1-2MB, no filesystem)
lvm
LVM physical volume
Table: Both
Use: LVM storage
raid
RAID member
Table: Both
Use: Software RAID arrays
msftres
Microsoft reserved
Table: GPT
Use: Windows dynamic disks
chromeos_kernel
ChromeOS kernel partition
Table: GPT
Use: ChromeOS specific
bls_boot
Boot Loader Specification
Table: GPT
Use: Modern boot systems
Units and Alignment
Supported Units
Unit |
Description |
Precision |
Example |
s |
Sectors (typically 512B) |
Exact |
2048s |
B |
Bytes |
Exact |
1048576B |
MiB/GiB |
Binary units (1024-based) |
Exact |
1GiB = 1,073,741,824B |
MB/GB |
Decimal units (1000-based) |
Approximate |
1GB ≈ 1,000,000,000B |
% |
Percentage of device size |
Approximate |
50% |
Unit Note: For exact positioning, use sectors ("s"), bytes ("B"), or binary units ("MiB", "GiB"). Decimal units ("MB", "GB") may be rounded by parted.
Alignment Control
align-check TYPE NUMBER
Check partition alignment (TYPE: minimal/optimal)
parted -a optimal /dev/sda mkpart primary ext4 1MiB 100%
Create partition with optimal alignment
4K Sector Warning: For Advanced Format (4K physical sector) drives, ensure partitions are aligned to 1MiB (2048-sector) boundaries for optimal performance.
cat /sys/block/sdX/queue/physical_block_size
cat /sys/block/sdX/queue/logical_block_size
parted /dev/sda unit GiB print
Display sizes in GiB units
Practical Examples
UEFI System
Legacy BIOS
LVM Setup
RAID Setup
Resizing
MBR→GPT
GPT Partitioning for UEFI System
# Create GPT table with aligned partitions
parted -s /dev/nvme0n1 mklabel gpt
# EFI System Partition (ESP) - FAT32 formatted (550MB recommended)
parted -s /dev/nvme0n1 mkpart ESP fat32 1MiB 551MiB
parted -s /dev/nvme0n1 set 1 esp on
# Boot partition (ext4)
parted -s /dev/nvme0n1 mkpart primary ext4 551MiB 2GiB
# Swap partition
parted -s /dev/nvme0n1 mkpart primary linux-swap 2GiB 10GiB
# Root partition (remaining space)
parted -s /dev/nvme0n1 mkpart primary ext4 10GiB 100%
# Verify layout
parted -s /dev/nvme0n1 print
# Format partitions
mkfs.fat -F32 /dev/nvme0n1p1 # ESP
mkfs.ext4 /dev/nvme0n1p2 # /boot
mkswap /dev/nvme0n1p3 # swap
mkfs.ext4 /dev/nvme0n1p4 # /
MBR Partitioning for Legacy BIOS
# Create MBR partition table
parted -s /dev/sda mklabel msdos
# BIOS boot partition (for GRUB, 1MB unformatted)
parted -s /dev/sda mkpart primary 1MiB 2MiB
parted -s /dev/sda set 1 bios_grub on
# Boot partition
parted -s /dev/sda mkpart primary ext4 2MiB 2GiB
parted -s /dev/sda set 2 boot on
# Swap partition
parted -s /dev/sda mkpart primary linux-swap 2GiB 10GiB
# Root partition (remaining space)
parted -s /dev/sda mkpart primary ext4 10GiB 100%
# Verify layout
parted -s /dev/sda print
# Format partitions
mkfs.ext4 /dev/sda2 # /boot
mkswap /dev/sda3 # swap
mkfs.ext4 /dev/sda4 # /
LVM Physical Volume Setup
# Create GPT table
parted -s /dev/sdb mklabel gpt
# Create single partition for LVM
parted -s /dev/sdb mkpart primary ext4 1MiB 100%
parted -s /dev/sdb set 1 lvm on
# Verification
parted -s /dev/sdb print
# Initialize as LVM physical volume
pvcreate /dev/sdb1
# Create volume group
vgcreate vg_data /dev/sdb1
# Create logical volume
lvcreate -L 100G -n lv_home vg_data
# Format and mount
mkfs.ext4 /dev/vg_data/lv_home
mount /dev/vg_data/lv_home /home
RAID Array Member Disk
# Create GPT table
parted -s /dev/sdc mklabel gpt
# Create RAID partition
parted -s /dev/sdc mkpart primary ext4 1MiB 100%
parted -s /dev/sdc set 1 raid on
# Repeat for other disks (sdd, sde, etc.)
# Verification
parted -s /dev/sdc print
# Create RAID array (with modern metadata)
mdadm --create /dev/md0 --level=1 --raid-devices=2 \
--metadata=1.2 /dev/sdc1 /dev/sdd1
# Check status
cat /proc/mdstat
mdadm --detail /dev/md0
# Create filesystem
mkfs.ext4 /dev/md0
Resizing Partitions
# First check current layout
parted /dev/sda print free
# Resize partition 3 to 20GB (must be adjacent to free space)
parted /dev/sda resizepart 3 20GiB
# For ext2/ext3/ext4 filesystems:
e2fsck -f /dev/sda3 # Check filesystem first
resize2fs /dev/sda3 # Resize filesystem to match partition
# For XFS filesystems (must be mounted):
xfs_growfs /mount/point
# For LVM logical volumes:
lvextend -L +10G /dev/vg00/lv_root
resize2fs /dev/vg00/lv_root
Warning: Only certain filesystems can be safely resized. Always backup data before resizing operations.
Convert MBR to GPT Without Data Loss
# Using gdisk (requires package 'gdisk')
gdisk /dev/sda
# In gdisk interactive mode:
x # Enter experts menu
e # Relocate backup data structures to end of disk
w # Write changes
y # Confirm
# Then set GPT flags as needed
parted /dev/sda set 1 esp on
Important: Always have backups before conversion. Some systems may require BIOS boot partition for GPT.
Complex Partition Layout
# Create GPT table with various partition types
parted -s /dev/nvme0n1 mklabel gpt
# EFI System Partition (550MB)
parted -s /dev/nvme0n1 mkpart ESP fat32 1MiB 551MiB
parted -s /dev/nvme0n1 set 1 esp on
# BIOS boot partition (for compatibility, 1MB)
parted -s /dev/nvme0n1 mkpart BIOS 551MiB 552MiB
parted -s /dev/nvme0n1 set 2 bios_grub on
# Boot partition (ext4)
parted -s /dev/nvme0n1 mkpart BOOT ext4 552MiB 2GiB
# Swap partition
parted -s /dev/nvme0n1 mkpart SWAP linux-swap 2GiB 10GiB
# LVM physical volume for remaining space
parted -s /dev/nvme0n1 mkpart LVM ext4 10GiB 100%
parted -s /dev/nvme0n1 set 5 lvm on
# Initialize LVM
pvcreate /dev/nvme0n1p5
vgcreate vg_system /dev/nvme0n1p5
lvcreate -L 50G -n lv_root vg_system
lvcreate -L 100G -n lv_home vg_system
lvcreate -l 100%FREE -n lv_var vg_system
# Format and mount partitions
mkfs.fat -F32 /dev/nvme0n1p1 # ESP
mkfs.ext4 /dev/nvme0n1p3 # /boot
mkswap /dev/nvme0n1p4 # swap
mkfs.ext4 /dev/vg_system/lv_root # /
mkfs.ext4 /dev/vg_system/lv_home # /home
mkfs.ext4 /dev/vg_system/lv_var # /var
Troubleshooting
Common Issues and Solutions
Partition Table Corruption
Symptoms: Partitions not recognized, strange errors
parted /dev/sda rescue 0% 100%
Attempt to recover lost partitions in specified range
Alternative: Use gdisk or testdisk for advanced recovery
Alignment Problems
Symptoms: Poor disk performance, especially on SSDs
parted /dev/sda align-check optimal 1
Check partition 1 alignment (returns "1 aligned" if correct)
Solution: Recreate partitions with proper alignment (1MiB boundaries)
4K Sector Drives
For Advanced Format (4K physical sector) drives:
cat /sys/block/sdX/queue/physical_block_size
cat /sys/block/sdX/queue/logical_block_size
Verify sector sizes. Ensure partitions are aligned to 1MiB (2048-sector) boundaries.
Debugging Commands
parted /dev/sda unit s print
Show exact sector numbers for debugging
fdisk -l /dev/sda
Cross-verify with fdisk
gdisk -l /dev/sda
Inspect GPT structures with gdisk
lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,UUID,PTTYPE
View block devices and partition table types
Secure Wipe
Warning: parted doesn't erase data, it only modifies partition tables. To securely wipe data:
dd if=/dev/zero of=/dev/sda bs=1M count=100
(Wipes first 100MB, use with caution)
Alternative: blkdiscard -s /dev/sda (for SSDs with TRIM support)