Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Linux parted command

Linux parted command

Linux Command Reference Linux Command Reference


I. Overview of the parted command

parted is a powerful disk partitioning tool on Linux. It supports multiple partition table types (such as GPT and MBR) and can create, delete, resize, and manage disk partitions. Compared with the traditional fdisk, parted is especially suitable for large disks (over 2TB) and modern partitioning needs.

Main Features


II. Installation and basic syntax

Install parted

Most Linux distributions come with parted preinstalled. To install it:

# Debian/Ubuntu

sudo apt install parted



# CentOS/RHEL

sudo yum install parted

Basic command syntax

Example

parted

[

Option

]

[

Device

]

[

Command

[

Parameters

]

]

Common options

Option Description
-l List partition information for all block devices
-s Script mode (non-interactive)
-a Set the alignment type (min/opt/none)
-f Suppress some warning messages

III. Interactive mode

Enter interactive mode

Example

sudo

parted

/

dev

/

sdX

data to the child component via /dev/sdX Replace with your actual device name (e.g., /dev/sda) /dev/sda)

Common commands in interactive mode

View help

Example

help [command name]

View the partition table

Example

print

Change units

Example

unit GB # Switch to GB display

unit MB # Switch to MB display

Create a new partition

Example

mkpart [partition type] [file system type] start end

Example:

Example

mkpart primary ext4 1GB 10GB

Delete a partition

Example

rm [partition number]

Resize a partition

Example

resizepart [partition number] end

Set partition flags

Example

set [partition number] [flag] on/off

Common flags:boot, lvm, raid, swap etc.

Exit

Example

quit


IV. Common operation examples

Example 1: View all disk partitions

Example

sudo

parted

-l

Example output:

Model: ATA ST1000DM010-2EP1 (scsi)

Disk /dev/sda: 1000GB

Sector size (logical/physical): 512B/4096B

Partition Table: gpt

Disk Flags: 



Number  Start   End     Size    File system  Name  Flags

 1      1049kB  538MB   537MB   fat32              boot, esp

 2      538MB   1000GB  999GB   ext4

Example 2: Create a new partition table (GPT format)

Example

sudo

parted

/

dev

/

sdb mklabel gpt

Example 3: Create a primary partition (non-interactive)

Example

sudo

parted

-s

/

dev

/

sdb mkpart primary ext4 1MiB 10GiB

Example 4: Resize a partition

Example

sudo

parted

-s

/

dev

/

sdb resizepart

2

20GiB

Example 5: Set the boot flag

Example

sudo

parted

-s

/

dev

/

sda

set

1

boot on


V. Advanced features and notes

1. Partition alignment optimization

Modern disks (especially SSDs) need proper partition alignment for best performance:

Example

sudo

parted

-a

optimal

/

dev

/

sdb mkpart primary ext4

0

%

100

%

2. Convert the partition table type

Example

sudo

parted

/

dev

/

sdb mklabel msdos  

Convert to MBR

sudo

parted

/

dev

/

sdb mklabel gpt    

Convert to GPT

Warning: This will delete all partitions on the disk!

3. File system operations

parted only manages partitions; creating a file system requires additional commands:

Example

sudo

mkfs.ext4

/

dev

/

sdb1

4. Notes


VI. Comparison of parted with fdisk/gdisk

Feature parted fdisk gdisk
Interactive mode Supported Supported Supported
Script mode Supported Not supported Not supported
GPT support Is Limited support Is
Large disk support Is No (MBR only) Is
Immediate write Is No (requires the w command) No (requires the w command)
Resize a partition Is No No

Linux Command Reference Linux Command Reference