Introduction
In Linux system management, disk partitioning is a key task to organize storage, improve performance and facilitate backup. Although there are graphic tools like GParted, the commandpartedoffers precise and scriptable control from the terminal, ideal for servers and environments without graphic interface.
What is parted?
parted(Partition Editor) is a command line utility that allows you to create, destroy, resize and manipulate partitions on hard drives and storage units. It supports various partition tables, including MSDOS, GPT, Apple and more, and works directly with the block device, which makes it powerful but also requires care.
Installation and verification
In most Linux distributions,partedcomes pre-installed. If not present, it can be installed by the package manager:
- Debian / Ubuntu:
sudo apt-get install parted - Fedora:
sudo dnf install parted - Arch Linux:
sudo pacman -S parted
To verify the version, runparted -v.
Basic concepts
Before handling a disk, it is essential to identify the right device withlsblkorfdisk -l. Suppose we work with/dev/sdb. When startingparted, an interactive prompt is opened:
sudo parted / dev / sdb
Within this environment, the commands are written without the prefixsudo, since you already have superuser privileges.
Create a new partition table
The first step is usually to define the partition table. For a new disk, GPT is chosen for its flexibility and disk support greater than 2 TB:
mklabel gpt
If you need compatibility with old BIOS systems, you can usemklabel msdos. This operation erases any existing table, so it should be done with caution.
Create partitions
With the list table, you can create partitions by specifying start, end and type of file system. For example, to create a 20 GB ext4 partition at the start of the disk:
mkpart primary ext4 0% 20GB
The number0%indicates the start of the disk and20GBthe size. After creating the partition, you can be assigned a label:
name 1 root
To format the partition, get out ofpartedand usemkfs.ext4 /dev/sdb1.
Reedit partitions
One of the advantages ofpartedis the ability to resize partitions without losing data, provided the file system admits it. To extend partition 1 to 30 GB:
resizepart 1 30GB
After changing the size, it must be runresize2fs /dev/sdb1(for ext4) for the file system to take advantage of the additional space.
Remove partitions
If a partition is no longer necessary, it is removed with:
rm 2
where2is the partition number to be deleted. This action is immediate and irreversible, so it is recommended to double check the number before it is executed.
Tags and file systems
In addition to partitioning operations,partedallows to assign names and verify the alignment. The appropriate alignment (for example, to multiple 1 MiB) improves performance in SSD units and advanced disks. It can be checked with:
align-check opt 1
A result of1indicates that the partition is correctly aligned.
Good practices
- Always back up critical data before modifying the partition table.
- Work on a screen session or tmux to avoid disconnection losses.
- Use
printcommon withinpartedto review the current state. - Prefer GPT for new disks, booking MSDOS only for legacy.
- Document each change in a changelog or script for reproducibility.
Conclusion
The commandpartedis an indispensable tool for advanced partition in Linux. Its command line interface provides flexibility, accuracy and the ability to automate tasks by scripts. With knowledge of their basic operations and appropriate precautions, managers can manage storage safely and efficiently, either on production servers or in personal workstations.


