Here’s a Linux Parted Cheat Sheet covering the essential commands and concepts for managing partitions using the parted tool.
Linux Parted Cheat Sheet
GNU Parted is a command-line tool used for creating, resizing, and managing partitions on Linux.
Basic Commands
Command | Description |
---|---|
sudo parted -l | List all partitions and disks. |
sudo parted /dev/sdX | Start parted for disk /dev/sdX. |
sudo parted /dev/sdX print | Show partition table for /dev/sdX. |
sudo parted /dev/sdX mklabel gpt | Create a GPT partition table (use msdos for MBR). |
sudo parted /dev/sdX unit GB print | Display partitions in GB instead of sectors. |
quit | Exit parted. |
Creating a New Partition
Start parted on a specific disk
sudo parted /dev/sdX
Create a new partition (Example: 10GB ext4 starting at 1MB)
mkpart primary ext4 1MiB 10GB
Check changes
Format the partition (outside parted)
sudo mkfs.ext4 /dev/sdX1
Resizing a Partition
Unmount the partition before resizing
sudo umount /dev/sdX1
Resize the partition (Example: Resize to 20GB)
sudo parted /dev/sdX resizepart 1 20GB
Expand the filesystem (For ext4)
sudo resize2fs /dev/sdX1
Deleting a Partition
List partitions
sudo parted /dev/sdX print
Delete partition #1
sudo parted /dev/sdX rm 1
Converting Partition Tables
- Convert MBR to GPT (WARNING: This erases all data!)
sudo parted /dev/sdX mklabel gpt
- Convert GPT to MBR
sudo parted /dev/sdX mklabel msdos
Aligning Partitions (Performance Optimization)
Check alignment:
sudo parted /dev/sdX align-check optimal 1
Returns “1 aligned” if aligned correctly.
Other Useful Commands
Command | Description |
---|---|
sudo parted /dev/sdX print free | Show free space on the disk. |
sudo parted /dev/sdX set 1 boot on | Mark partition 1 as bootable. |
sudo parted /dev/sdX name 1 “MyPartition” | Name partition 1. |
sudo parted /dev/sdX rescue 100MB 500MB | Attempt to recover lost partitions. |
Example: Create and Format a Partition
sudo parted /dev/sdX mklabel gpt sudo parted /dev/sdX mkpart primary ext4 1MiB 50GB sudo mkfs.ext4 /dev/sdX1
Now, /dev/sdX1 is a 50GB ext4 partition ready to use!
This Linux Parted Cheat Sheet covers the essentials for managing partitions efficiently using parted.