Understanding linux parted utility

The GNU parted utility is also used to view the existing partition table, change the size of existing partitions, or add partitions from free space or additional hard drives. This utility is more advanced than the fdisk utility. It supports more disk label types and offers additional commands. parted syntax is:

# parted [option] [device_name] [command [argument]]

Use parted interactively to enter commands one at a time. Include only the device as an argument to invoke interactive mode. Example:

# parted /dev/sda
GNU Parted 3.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted)

From the (parted) prompt, enter a command or type help to view the list of available commands. Get additional help on a specific command by typing help plus the command. Example:

Creating new partition using parted

The following example creates a new partition table by using the mklabel command. The disk label type must be one of the following: aix, amiga, bsd, dvh, gpt, mac, msdos, pc98, sun, or loop.

# parted /dev/sdb
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel gpt
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will
be lost. Do you want to continue?
Yes/No? Yes

Create a new partition using the mkpart subcommand. We will be creating ext4 partition of size 200MB.

(parted) mkpart
Partition name?  []? newpart                                             
File system type?  [ext2]? ext4                                          
Start? 0                                                                 
End? 200MB                                                              
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? I                                                        
(parted) print                                                          
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End    Size   File system  Name     Flags
 1      17.4kB  200MB  200MB               newpart

(parted)
NOTE : The primary, logical, and extended are the partition types of an msdos partition table. In the case of a gpt partition table, the partition type is used as the partition name.

Rename a partition

Renaming a partition to a new name is supported only in case of GPT partition. Follow the steps below:

(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start  End    Size   Type     File system   Name       Flags
 1      512B   200MB  200MB  gpt                    oldpart

(parted) name 1 'newpart'

(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start  End    Size   Type     File system   Name       Flags
 1      512B   200MB  200MB  gpt                    newpart

List partitions

To list the existing partitions and storage devices use the ‘parted -l’ command.

# parted -l
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  1075MB  1074MB  primary  xfs          boot
 2      1075MB  21.5GB  20.4GB  primary               lvm
 ....

Set partition table type

Use the mklabel subcommand to change the partition table type. The supported partition tables are: aix, amiga, bsd, dvh, gpt, mac, msdos, pc98, sun, loop. For example to change the partition type to gpt :

(parted) mklabel gpt
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will
be lost. Do you want to continue?
Yes/No? Yes
Related Post