Plan du site  
pixel
pixel

Articles - Étudiants SUPINFO

GNU Parted

Par Fabrizio ASTA Publié le 07/04/2016 à 15:20:31 Noter cet article:
(0 votes)
Avis favorable du comité de lecture

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 Buytenhek.

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.

How to start Parted

Parted has two modes: interactive mode and command line mode.

In command line mode, commands can be executed one at a time or all together.

In interactive mode, commands are executed one at a time, and they modify the disk immediately.

To start Parted, type:

sudo parted

If you check on your terminal, the hash "#" should be replaced by "(parted)". Now you are on Interactive mode.

To check the list of available commands, type:

(parted) help

If you want to exit from (parted) and you want to go back to the terminal, type:

(parted) quit

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 table:

# 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 layout.

Delete partitions

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.

Create new partitions

mkpart is used to create primary or logical partition with START and END disk location.

His syntax is: mkpart PART-TYPE [FS-TYPE] START END

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.

Create GRUB2 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

Create BOOT partition

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 BIOS).

Create SWAP partition

It's pretty the same thing for SWAP creation(in the example 4GB):

(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 command "mkfs.<type>":

# 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 mkfs.<type> utils.

Rescue a partition

If you delete accidentally a partition, you can rescue that partition using rescue command.

For example:

(parted) print

(parted) rm 5

(parted) print

I have deleted my swap! Let's rescue it:

(parted) unit GB

(parted) rescue

Start? 11,8

End? 12,9

(parted) print

Commands list

help - Print general help:

(parted) help

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, sun)

mkpart - Create a new partition, without creating a new filesystem on that partition:

(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:

(parted) print

quit - Quit from Parted:

(parted) quit

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" command.)

(parted) rescue

Start? 0

End? 8056 (for example)

resizepart - Move the END position of partition number. It is used to resize a partition:

(parted) resizepart number END

rm - Remove a partition with number NUMBER:

(parted) rm

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

Gparted

It is a graphical front-end program that use parted libraries. Many operating systems have Gparted already included as utility to create partitions graphically.

Install Gparted

If you are on Ubuntu or one of his derivates, just type:

sudo apt-get install gparted

How to use it

It is pretty simple to use. Let's see basic commands.

Create a new partition

Create a new partition clicking the button that is circled:

From this window you can assign space, choose if it will be logical or primary partition, create file system and give it a name.

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.

Edit existing partitions

To edit existing partitions the first thing to do is unmount partitions. In this case, the keys circled means that I have 3 partitions mounted:

Right-click on a partition and click "Unmount" for partitions or "Swapoff" for linux-swap.

From now, you can edit without any problem the partitions:

You can delete it, resize or move, copy or change his format to:

Applying changes

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 yet.

Change device

To change device, click on the circled box to list all available devices:

Conclusion

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.

A propos de SUPINFO | Contacts & adresses | Enseigner à SUPINFO | Presse | Conditions d'utilisation & Copyright | Respect de la vie privée | Investir
Logo de la société Cisco, partenaire pédagogique de SUPINFO, la Grande École de l'informatique, du numérique et du management Logo de la société IBM, partenaire pédagogique de SUPINFO, la Grande École de l'informatique, du numérique et du management Logo de la société Sun-Oracle, partenaire pédagogique de SUPINFO, la Grande École de l'informatique, du numérique et du management Logo de la société Apple, partenaire pédagogique de SUPINFO, la Grande École de l'informatique, du numérique et du management Logo de la société Sybase, partenaire pédagogique de SUPINFO, la Grande École de l'informatique, du numérique et du management Logo de la société Novell, partenaire pédagogique de SUPINFO, la Grande École de l'informatique, du numérique et du management Logo de la société Intel, partenaire pédagogique de SUPINFO, la Grande École de l'informatique, du numérique et du management Logo de la société Accenture, partenaire pédagogique de SUPINFO, la Grande École de l'informatique, du numérique et du management Logo de la société SAP, partenaire pédagogique de SUPINFO, la Grande École de l'informatique, du numérique et du management Logo de la société Prometric, partenaire pédagogique de SUPINFO, la Grande École de l'informatique, du numérique et du management Logo de la société Toeic, partenaire pédagogique de SUPINFO, la Grande École de l'informatique, du numérique et du management Logo du IT Academy Program par Microsoft, partenaire pédagogique de SUPINFO, la Grande École de l'informatique, du numérique et du management

SUPINFO International University
Ecole d'Informatique - IT School
École Supérieure d'Informatique de Paris, leader en France
La Grande Ecole de l'informatique, du numérique et du management
Fondée en 1965, reconnue par l'État. Titre Bac+5 certifié au niveau I.
SUPINFO International University is globally operated by EDUCINVEST Belgium - Avenue Louise, 534 - 1050 Brussels