Categories: How-To

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.

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.

Share
Published by
Uirá Endy Ribeiro

Recent Posts

Sudo command on Linux (privilege scale) [Basic Guide]

The sudo command on Linux executes a given command as if it were another user.…

2 years ago

SS command on Linux (investigate the network) [Basic Guide]

The ss command on Linux is extremely useful for investigating sockets, providing various information about…

2 years ago

Free Linux command (memory usage) [Basic Guide]

Free Linux command shows the amount of total memory in use and available, as well…

2 years ago

Linux while command (loop – while) [Basic Guide]

The shell has structures for testing conditions and executing certain program sequences several times (loop),…

2 years ago

Linux fstab file (disk mount setup) [Basic Guide]

The /etc/fstab file stores the configuration of which devices should be mounted and what is…

2 years ago

Netcat command on Linux (Swiss network knife) [Basic Guide]

The Netcat Command in Linux or nc is a utility used to do “almost anything”…

2 years ago

This website uses cookies.