parted  is  a disk partitioning and partition resizing program.  It allows you to create, destroy, resize, move and copy ext2, linux-swap, FAT, FAT32, and reiserfs partitions.  It can create, resize, and move Macintosh HFS partitions, as well as detect jfs, ntfs, ufs, and xfs partitions. 

It is useful for creating space for new operating systems, reorganising disk usage, and copying data to new hard disks.

More importantly, compare with another popular disk partition utility fdisk, it has no 2TB limitation as fdisk has.

Start to use parted

In most of cases, you would like to specify a device for parted to work with, if not, then parted will attepmt to guess one, which more likely is /dev/sda

# parted /dev/sdb
GNU Parted 2.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.

Get help

help command will print list of commands that parted supports, futher more, if you want to know the command usage, more info, then run  help <command>, for example:

(parted) help mklabel                                                     
  mklabel,mktable LABEL-TYPE               create a new disklabel (partition
        table)

    LABEL-TYPE is one of: aix, amiga, bsd, dvh, gpt, mac, msdos, pc98, sun,
        loop

List current partition

(parted) print
Error: /dev/sdb: unrecognised disk label

No label, create a label first

Make label

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

Now, you can use print command to list current partition                                       

(parted) print                                                            
Model: Linux device-mapper (multipath) (dm)
Disk /dev/mapper/ddnlun1: 8002GB
Sector size (logical/physical): 4096B/4096B
Partition Table: gpt

Number  Start  End  Size  File system  Name  Flags

Make new partition

Here is the mkpart command usage

(parted) help mkpart                                                      
  mkpart PART-TYPE [FS-TYPE] START END     make a partition

    PART-TYPE is one of: primary, logical, extended
        FS-TYPE is one of: ext4, ext3, ext2, fat32, fat16, hfsx, hfs+, hfs, jfs,
        swsusp, linux-swap(v1), linux-swap(v0), ntfs, reiserfs, hp-ufs, sun-ufs,
        xfs, apfs2, apfs1, asfs, amufs5, amufs4, amufs3, amufs2, amufs1, amufs0,
        amufs, affs7, affs6, affs5, affs4, affs3, affs2, affs1, affs0,
        linux-swap, linux-swap(new), linux-swap(old)
        START and END are disk locations, such as 4GB or 10%.  Negative values
        count from the end of the disk.  For example, -1s specifies exactly the
        last sector.
        
        'mkpart' makes a partition without creating a new file system on the
        partition.  FS-TYPE may be specified to set an appropriate partition
        ID.

Example:

(parted) mkpart primary 0GB 100GB                                          
(parted) print                                                            
Model: Linux device-mapper (multipath) (dm)
Disk /dev/mapper/ddnlun1: 8002GB
Sector size (logical/physical): 4096B/4096B
Partition Table: gpt

Number  Start  End    Size    File system  Name     Flags
 1      134MB  100GB  99.9GB               primary

Make file system

Surely you can create all supported filesystems if you want, here is just one example.

mkfs /dev/mapper/ddnlun1p5
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=1 blocks, Stripe width=32768 blocks
6103040 inodes, 24412160 blocks
1220608 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
745 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
    4096000, 7962624, 11239424, 20480000, 23887872

Writing inode tables: done                            
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 33 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

Rename a partition

Command: name number name
Sets the name for the partition number (GPT, Mac, MIPS and PC98 only). The name can be placed in quotes.

Example:

(parted) name 1 'Linux VM1'

Set partition attributes

Command: disk_set flag state
Changes a flag on the disk. A flag can be either “on” or “off”. Some or all of these flags will be available, depending on what disk label you are using:

‘pmbr_boot’
(GPT) - this flag enables the boot flag on the GPT’s protective MBR partition.

The disk’s flags are displayed by the print command on the "Disk Flags:" line. They are also output as the last field of the disk information in machine mode.

(parted) disk_set pmbr_boot on
Set the PMBR’s boot flag.

Align check partition check

Determine whether the starting sector of partition n meets the disk’s selected alignment criteria. align-type must be ‘minimal’, ‘optimal’ or an abbreviation.

Here is the help output:

(parted) help align-check                                                 
  align-check TYPE N                        check partition N for TYPE(min|opt)
        alignment

    NUMBER is the partition number used by Linux.  On MS-DOS disk labels,
        the primary partitions number from 1 to 4, logical partitions from 5
        onwards.

Example:

(parted) align-check opt 8                                                
8 aligned

Note: When in script mode, if the partition does not meet the alignment requirement, exit with status 1; otherwise (including on older kernels for which alignment data is not available), continue processing any remaining commands. Without --script, print either ‘N aligned’ or ‘N not aligned’.

Remove a partition

(parted) rm <partition No.>

Recuse a partition

Command: rescue start end
Rescue a lost partition that used to be located approximately between start and end. If such a partition is found, Parted will ask you if you want to create a partition for it. This is useful if you accidently deleted a partition with parted’s rm command, for example.

Example:

(parted) print
Disk geometry for /dev/hdc: 0.000-8063.507 megabytes
Disk label type: msdos
Minor    Start       End     Type      Filesystem  Flags
1          0.031   8056.032  primary   ext3
(parted) rm
Partition number? 1
(parted) print
Disk geometry for /dev/hdc: 0.000-8063.507 megabytes
Disk label type: msdos
Minor    Start       End     Type      Filesystem  Flags

OUCH! We deleted our ext3 partition!!! Parted comes to the rescue...

(parted) rescue
Start? 0
End? 8056
Information: A ext3 primary partition was found at 0.031MB ->
8056.030MB.  Do you want to add it to the partition table?
Yes/No/Cancel? y
(parted) print
Disk geometry for /dev/hdc: 0.000-8063.507 megabytes
Disk label type: msdos
Minor    Start       End     Type      Filesystem  Flags
1          0.031   8056.032  primary   ext3

It’s back! :)

Resizepart a partition

Command: resizepart number end
Moves the end position of partition number(of course no overlap to the next partition).

Note that this does not modify any filesystem present in the partition. If you wish to do this, you will need to use external tools, such as resize2fs

When growing a partition you will want to grow the filesystem afterwards, but when shrinking, you need to shrink the filesystem before the partition.

 Set

Command: set number flag state
Changes a flag on the partition with number number. A flag can be either “on” or “off”. Some or all of these flags will be available, depending on what disk label you are using:



‘bios_grub’
(GPT) - Enable this to record that the selected partition is a GRUB BIOS partition.

‘legacy_boot’
(GPT) - this flag is used to tell special purpose software that the GPT partition may be bootable.

‘boot’
(Mac, MS-DOS, PC98) - should be enabled if you want to boot off the partition. The semantics vary between disk labels. For MS-DOS disk labels, only one partition can be bootable. If you are installing LILO on a partition that partition must be bootable. For PC98 disk labels, all ext2 partitions must be bootable (this is enforced by Parted).

‘msftdata’
(GPT) - This flag identifies partitions that contain Microsoft filesystems (NTFS or FAT). It may optionally be set on Linux filesystems to mimic the type of configuration created by parted 3.0 and earlier, in which a separate Linux filesystem type code was not available on GPT disks. This flag can only be removed within parted by replacing it with a competing flag, such as boot or msftres.

‘msftres’
(GPT) - This flag identifies a "Microsoft Reserved" partition, which is used by Windows on GPT disks. Note that this flag should not normally be set on Windows filesystem partitions (those that contain NTFS or FAT filesystems).

‘irst’
(MS-DOS, GPT) - this flag identifies an Intel Rapid Start Technology partition.

‘esp’
(MS-DOS, GPT) - this flag identifies a UEFI System Partition. On GPT it is an alias for boot.

‘lba’
(MS-DOS) - this flag can be enabled to tell MS DOS, MS Windows 9x and MS Windows ME based operating systems to use Linear (LBA) mode.

‘root’
(Mac) - this flag should be enabled if the partition is the root device to be used by Linux.

‘swap’
(Mac) - this flag should be enabled if the partition is the swap device to be used by Linux.

‘hidden’
(MS-DOS, PC98) - this flag can be enabled to hide partitions from Microsoft operating systems.

‘raid’
(MS-DOS) - this flag can be enabled to tell linux the partition is a software RAID partition.

‘LVM’
(MS-DOS) - this flag can be enabled to tell linux the partition is a physical volume.

‘PALO’
(MS-DOS) - this flag can be enabled so that the partition can be used by the Linux/PA-RISC boot loader, palo.

‘PREP’
(MS-DOS, GPT) - this flag can be enabled so that the partition can be used as a PReP boot partition on PowerPC PReP or IBM RS6K/CHRP hardware.

‘DIAG’
(MS-DOS) - Enable this to indicate that a partition can be used as a diagnostics / recovery partition.

The print command displays all enabled flags for each partition.

Example:

(parted) set 1 boot on
Set the ‘boot’ flag on partition 1.