Parted command on Linux (partitioning disk) [Basic Guide]

The parted command in Linux was developed to partition and resize disk partitions. It allows you to create, destroy, resize, move, and copy ext2, Linux-swap, FAT, FAT32, ReiserFS, and HFS partitions. It is very useful for reorganizing disk usage as well as copying data to new disks.

Its use is for more experienced users, since it can create partitions directly at the prompt of shell.

If no command is entered as a parameter, parted will show its own command prompt.

The commands can be:

mklabel label-type
Creates a new partition table, which may be of the type “aix”, “amica”, “bsd”, “dvh”, “gpt”, “loop”, “mac”, “msdos”, “pc98″, or “sun”.

mkpart part-type [fs-type] start end
Creates a partition.
The part-type can be “primary”, “logical”, or “extended”.
The fs-type specifies the type of file system, which may or may not be entered. Accepted system types are: “btrfs”, “ext2″, “ext3″, “ext4″, “fat16″, “fat32″, “hfs”, “hfs”, “hfs+”, “linux-swap”, “ntfs”, “reiserfs” and “xfs”.
The start parameter defines the start of the partition. It’s an integer followed by a unit.
The end parameter defines the end of the partition. It’s an integer followed by a unit.
The drive may be the letter “s” for Sector, if the number entered is a sector on the disk, or “B” to indicate the start and end of the partition in Bytes. It is also possible to define the start and end of partitions on binary drives such as “MiB”, “GiB” and “TiB”.

name name
This command allows you to give a name to the partition. It can only be used on Mac, PC98, and GPT type partition tables.

print
Shows information about a partition.

To create a GPT partition table on the /dev/xvdb disk:

$ parted /dev/xvdb mklabel gpt 
Notice: The existing disk label on /dev/xvdb will be destroyed and all data on this disk will be lost. Do you
want to continue?
Yes/Yes/No/No?

Yes

Once the partition table has been created, the partition can be created:

# parted /dev/xvdb mkpart primary btrfs 1MiB 100% 
Information: You may need to update /etc/fstab.

Parted also allows you to view the newly created partition with the print command:

# parted /dev/xvdb print 
Model: Xen Virtual Block Device (xvd)
Disk /dev/xvdb: 8590MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File System Name & nbsp; Flag

1 1049kB 8589MB 8588MB primary

Learn much more about Linux in our online course. You can register here. If you already have an account, or want to create one, just log in or create your user here.

Did you like it?

Share

Uirá Endy Ribeiro

Uirá Endy Ribeiro is a Software Developer and Cloud Computing Architect with a 23-year career. He has master's degrees in computer science and fifteen IT certifications and is the author of 11 books recognized in the IT world market. He is also Director at Universidade Salgado de Oliveira and Director of the Linux Professional Institute - LPI Director's Board.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.

Need help?