parted Command
Create, resize, move, and delete disk partitions with support for GPT and MBR partition tables.
Syntax
parted [OPTIONS] [DEVICE [COMMAND [PARAMETERS]...]]
parted [OPTIONS] DEVICE
The parted command is a disk partitioning tool that can handle both GPT and MBR partition tables. It can be used interactively or with command-line arguments.
Common Options
| Option |
Description |
-a, --align |
Set alignment for newly created partitions |
-l, --list |
List partition layout on all block devices |
-m, --machine |
Display machine parseable output |
-s, --script |
Never prompt for user intervention |
-v, --version |
Display version information |
-h, --help |
Display help message |
--pretend-input-tty |
Pretend to be a tty for scripting |
-f, --fix |
Automatically fix partition table problems |
Parted Commands
| Command |
Description |
Example |
print |
Display partition table |
print |
mklabel |
Create new partition table |
mklabel gpt |
mkpart |
Create new partition |
mkpart primary ext4 1MiB 100% |
rm |
Delete partition |
rm 1 |
resizepart |
Resize partition |
resizepart 1 100% |
move |
Move partition |
move 1 32s |
set |
Set partition flag |
set 1 boot on |
unit |
Set default unit |
unit MiB |
Basic Examples
Viewing partition information
# List all partitions on all devices
sudo parted -l
# View specific device partitions
sudo parted /dev/sdb print
# Machine-readable output
sudo parted -m /dev/sdb print
# View partition table type
sudo parted /dev/sdb print | grep "Partition Table"
Display partition information and layout
Creating partition tables
# Create GPT partition table
sudo parted /dev/sdb mklabel gpt
# Create MBR partition table
sudo parted /dev/sdb mklabel msdos
# Create partition table non-interactively
sudo parted -s /dev/sdb mklabel gpt
# Verify partition table creation
sudo parted /dev/sdb print
Create new partition tables on disks
Creating partitions
# Create primary partition using entire disk
sudo parted /dev/sdb mkpart primary ext4 1MiB 100%
# Create partition with specific size
sudo parted /dev/sdb mkpart primary ext4 1MiB 10GiB
# Create multiple partitions
sudo parted /dev/sdb mkpart primary ext4 1MiB 5GiB
sudo parted /dev/sdb mkpart primary ext4 5GiB 10GiB
# Create partition with name (GPT only)
sudo parted /dev/sdb mkpart "Data Partition" ext4 1MiB 100%
Create new partitions with various configurations
Advanced Usage
Partition resizing
# Resize partition to use all available space
sudo parted /dev/sdb resizepart 1 100%
# Resize partition to specific size
sudo parted /dev/sdb resizepart 1 20GiB
# Resize with unit specification
sudo parted /dev/sdb unit MiB resizepart 1 20480
# Check partition after resize
sudo parted /dev/sdb print
Resize existing partitions (filesystem resize needed separately)
Partition flags and attributes
# Set boot flag
sudo parted /dev/sdb set 1 boot on
# Set LVM flag
sudo parted /dev/sdb set 1 lvm on
# Set RAID flag
sudo parted /dev/sdb set 1 raid on
# Remove flag
sudo parted /dev/sdb set 1 boot off
# View all flags
sudo parted /dev/sdb print
Set partition flags and attributes
Scripted operations
# Complete disk setup in one command
sudo parted -s /dev/sdb mklabel gpt mkpart primary ext4 1MiB 100%
# Multiple operations script
sudo parted -s /dev/sdb \
mklabel gpt \
mkpart "Boot" fat32 1MiB 512MiB \
mkpart "Root" ext4 512MiB 100% \
set 1 esp on
# Automated partitioning script
#!/bin/bash
DEVICE="/dev/sdb"
sudo parted -s $DEVICE mklabel gpt
sudo parted -s $DEVICE mkpart primary ext4 1MiB 100%
sudo parted -s $DEVICE print
Automate partitioning operations with scripts
Interactive Mode
Using parted interactively
# Start interactive mode
sudo parted /dev/sdb
# Interactive commands:
(parted) print # Show partition table
(parted) help # Show help
(parted) unit MiB # Set unit to MiB
(parted) mklabel gpt # Create GPT table
(parted) mkpart primary ext4 1 100% # Create partition
(parted) set 1 boot on # Set boot flag
(parted) print # Verify changes
(parted) quit # Exit parted
Use parted in interactive mode for step-by-step operations
Interactive session example
$ sudo parted /dev/sdb
GNU Parted 3.3
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:
(parted) mklabel gpt
(parted) mkpart primary ext4 1MiB 100%
(parted) print
(parted) quit
Example interactive session creating a partition
Practical Examples
UEFI system setup
# Create UEFI-compatible disk layout
sudo parted -s /dev/sdb mklabel gpt
# Create EFI System Partition
sudo parted -s /dev/sdb mkpart "EFI System" fat32 1MiB 512MiB
sudo parted -s /dev/sdb set 1 esp on
# Create root partition
sudo parted -s /dev/sdb mkpart "Root" ext4 512MiB 100%
# Verify layout
sudo parted /dev/sdb print
Set up disk for UEFI boot system
Multi-partition setup
# Create complex partition layout
sudo parted -s /dev/sdb mklabel gpt
# Boot partition
sudo parted -s /dev/sdb mkpart "Boot" ext4 1MiB 1GiB
# Swap partition
sudo parted -s /dev/sdb mkpart "Swap" linux-swap 1GiB 5GiB
# Root partition
sudo parted -s /dev/sdb mkpart "Root" ext4 5GiB 25GiB
# Home partition
sudo parted -s /dev/sdb mkpart "Home" ext4 25GiB 100%
# Set boot flag
sudo parted -s /dev/sdb set 1 boot on
Create multiple partitions for different purposes
LVM setup
# Prepare disk for LVM
sudo parted -s /dev/sdb mklabel gpt
# Create LVM partition
sudo parted -s /dev/sdb mkpart "LVM" ext4 1MiB 100%
sudo parted -s /dev/sdb set 1 lvm on
# Verify LVM flag
sudo parted /dev/sdb print
# Initialize as LVM physical volume
sudo pvcreate /dev/sdb1
Prepare partitions for LVM (Logical Volume Management)
Units and Alignment
Supported units
| Unit |
Description |
Example |
s |
Sectors (512 bytes) |
2048s |
B |
Bytes |
1048576B |
KiB |
Kibibytes (1024 bytes) |
1024KiB |
MiB |
Mebibytes (1024² bytes) |
1MiB |
GiB |
Gibibytes (1024³ bytes) |
10GiB |
TiB |
Tebibytes (1024⁴ bytes) |
1TiB |
% |
Percentage of disk |
100% |
Alignment options
# Optimal alignment (default)
sudo parted -a optimal /dev/sdb mkpart primary ext4 1MiB 100%
# Minimal alignment
sudo parted -a minimal /dev/sdb mkpart primary ext4 1MiB 100%
# No alignment
sudo parted -a none /dev/sdb mkpart primary ext4 1MiB 100%
# Check alignment
sudo parted /dev/sdb align-check optimal 1
Control partition alignment for optimal performance
Safety and Best Practices
Important Safety Notes
- Data Loss Risk - Partitioning operations can destroy data
- Backup First - Always backup important data before partitioning
- Unmount Filesystems - Unmount partitions before modifying them
- Double-check Device - Verify you're working on the correct disk
- Test Commands - Use print command to verify before making changes
Safe partitioning workflow
# 1. Identify the correct device
lsblk
sudo fdisk -l
# 2. Backup partition table
sudo sfdisk -d /dev/sdb > partition_backup.txt
# 3. Unmount any mounted partitions
sudo umount /dev/sdb*
# 4. Check current partition table
sudo parted /dev/sdb print
# 5. Perform partitioning operations
sudo parted -s /dev/sdb mklabel gpt
sudo parted -s /dev/sdb mkpart primary ext4 1MiB 100%
# 6. Verify results
sudo parted /dev/sdb print
lsblk /dev/sdb
Follow safe practices when partitioning disks
Recovery and troubleshooting
# Restore partition table from backup
sudo sfdisk /dev/sdb < partition_backup.txt
# Fix partition table issues
sudo parted -f /dev/sdb print
# Check filesystem after partition changes
sudo fsck /dev/sdb1
# Rescue mode for damaged partition tables
sudo parted /dev/sdb rescue 1MiB 100%
# Use testdisk for advanced recovery
sudo testdisk /dev/sdb
Recovery options for partition table problems
Troubleshooting
Common Issues
- Device busy - Partitions are mounted or in use
- Permission denied - Need root privileges
- Alignment warnings - Partition not optimally aligned
- Invalid partition table - Corrupted or unrecognized format
Common solutions
# Check what's
using the device
sudo lsof /dev/sdb
sudo fuser -v /dev/sdb
# Force unmount if needed
sudo umount -f /dev/sdb*
sudo umount -l /dev/sdb* # Lazy unmount
# Check device permissions
ls -l /dev/sdb
# Fix alignment issues
sudo parted /dev/sdb align-check optimal 1
# Repair partition table
sudo parted -f /dev/sdb print
sudo parted /dev/sdb rescue 1MiB 100%
Resolve common partitioning issues