GNU Parted (usually called Parted) is
a program to manipulate disk partitions. It can create, delete or modify
hard disk partitions. It is really useful to create new space for operating
systems or copying data between hard disks.
It is made up of a library, libparted, and a CLI (Command Line Interface)
front-end, parted, but exist alternatives
front-end that let you use Parted graphically.
Originally it was written by Andrew Clausen and Lennert
Let's start talking about how to start Parted from terminal.
Note that after version 2.4 of Parted, the following
commands were removed: check, cp, mkfs, mkpartfs, move, resize. So this
article will not talk about this commands.
Parted has two modes: interactive
mode and command line
In command line mode, commands can be executed one at a time or all
In interactive mode, commands are executed one at a time, and they
modify the disk immediately.
To start Parted, type:
If you check on your terminal, the hash "#" should be replaced by
"(parted)". Now you are on Interactive
To check the list of available commands, type:
If you want to exit from (parted) and you want to go back to the
Create new partition table
The first thing to do if we are starting from scratch(for example if
we must recreate the partition table or when the device hasn't never been
partitioned before) is to create a partition table.
To do it, select the device in which you must create a partition
# parted /dev/sdx
and now, create a new partition table:
(parted) mklabel gpt
Type msdos, instead of gpt, if you want to create a MBR
To delete a specified partition, first of all use "print" to view
the existing partitions:
Print command will print on the screen all the partitions that are
in the hard disk. It is really useful because it gives you a lot of
informations about partitions: size, type, file system, etc.
And now type:
(parted) rm NUMBER
where NUMBER is the number of the partition to remove.
mkpart is used to create primary or
logical partition with START and END disk location.
His syntax is: mkpart PART-TYPE [FS-TYPE]
For example, if we want to create a new
partition of 5GB:
(parted) mkpart primary 0 5120
START and END are passed in MBs. Replace "primary" with "logical" if
you want to create a logical partition.
If you need to create a GRUB2 partition manually, you can use
mkpart to do it. Let's create a 2MB partition:
(parted) mkpart primary 1 3
(parted) name 1 grub2
(parted) set 1 bios_grub on
Let's create a boot partition(128MB):
(parted) mkpart primary 3 131
(parted) name 2 boot
(parted) set 2 boot on
Last command is necessary when we have UEFI interface (instead of
It's pretty the same thing for SWAP creation(in the example
(parted) mkpart primary 131 4227
(parted) name 3 swap
Create partition with our filesystem
Now we can create the partition that will host our OS:
(parted) mkpart primary 643 -1
(parted) name 4 'Private Space'
The "-1" means to assign all space disk at the partition.
To create the filesystem inside one of our partitions, use the
# mkfs.ext4 /dev/sdx
Note that after version 2.4, the mkfs commands was
removed from parted. mkfs is deprecated in favour of filesytem specific
If you delete accidentally a partition, you can rescue that
partition using rescue command.
(parted) rm 5
I have deleted my swap! Let's rescue it:
(parted) unit GB
help - Print general
mklabel - Create a
partition table, a new disk label:
(parted) mklabel label-type
(label-type must be replaced with
one of these supported disk labels: bsd, loop, gpt, mac, msdos, pc98,
mkpart - Create a new
partition, without creating a new filesystem on that
(parted) mkpart [PART-TYPE] START END
name - Set the name for
the partition number(GPT, Mac, PC98 only):
(parted) name 2 'Example'
print - Display partition
table and detailed informations:
quit - Quit from
rescue - Rescue a lost
partition that we know it was located between START and END. (This is
useful if we have deleted accidentally a partition with "rm"
End? 8056 (for example)
resizepart - Move the END
position of partition number. It is used to resize a
(parted) resizepart number END
rm - Remove a partition
with number NUMBER:
Partition number? 1 (for example)
select - Select the
device to edit with Parted. The device can be a partition, a Linux hard
disk device or other things:
(parted) select /dev/sdx
It is a graphical front-end program that use parted libraries. Many
operating systems have Gparted already included as utility to create
If you are on Ubuntu or one of his derivates, just type:
sudo apt-get install gparted
It is pretty simple to use. Let's see basic commands.
Create a new partition clicking the button that is
From this window you can assign space, choose if it will be
logical or primary partition, create file system and give it a
Create partition table and rescue a partition
From "Device" menu we can create a partition table and attempt a
data rescue. To understand what they are go in the section above to
understand how they work.
To edit existing partitions the first thing to do is unmount
partitions. In this case, the keys circled means that I have 3
Right-click on a partition and click "Unmount" for partitions or
"Swapoff" for linux-swap.
From now, you can edit without any problem the
You can delete it, resize or move, copy or change his format
To apply changes permanently, you have to click on the button
circled on the top. The red circle in the lower part is listing all
the changes you have already done but that are not applied permanently
To change device, click on the circled box to list all available
In conclusion, parted is an awesome tool that allows novice users
(gparted) and intermediate users (from terminal) to modify partitions and
filesystems. Some practice is requested to understand how to use this
commands without do any errors, but after that, you will have a powerful
tool in your hands.