- Parted manages partitions and tables (MBR/GPT) with sector-specific accuracy and interactive or non-interactive mode, ideal for automation.
- Combines parted with native tools of each FS (mkfs, fsck, resize2fs, xfs_growfs) for safe and supported operations.
- Best practices: backups, checking with lsblk/dmesg, using UUIDs in fstab, and checking with df -TH and mount.

If you work with disks in GNU/Linux, sooner or later you will need one. Reliable tool for splitting, growing, or inspecting partitionsIn that scenario, GNU parted It becomes a must-have: it is fast, powerful and accepts both interactive and online use. commands non-interactive.
In this article, you'll find a practical and detailed guide to mastering parted, with real-world commands, example output, and typical administration scenarios. You'll also see how to combine it with utilities such as lsblk, mkfs, e2fsck, resize2fs o xfs_growfs, and how to leave the automatic assembly ready in /etc/fstab.
What is GNU parted and what is it for?
GNU parted is a utility designed to manage partitions and partition tables on disks and other block devices. It supports schemes such as MBR/MS-DOS and GPT, and operations such as creating, resizing, moving, listing, and deleting partitions. It also allows you to change the disk label with mklabel and work with optimal sector alignment to maximize performance.
Parted is used interactively (by joining a program session) or by running one-liners from the shell. In both modes, it's important to remember that partitioning can affect your data: make backups and always confirm that you're operating the system. correct device.
Modes of use: interactive and non-interactive
In interactive mode you open a session on a device: parted /dev/sdX. Then, at the prompt (parted), you write commands like help, print, mkpart, resizepart, rm, unit s o quitIn non-interactive mode, you can chain operations and automate tasks with scripts, for example: parted -s /dev/sdb mklabel gpt mkpart primary ext4 1GB 10GB.
General syntax and basic commands
The generic form is: parted . Where It's something like /dev/sda; the defines the action (e.g. mklabel, mkpart, print), and the They adjust behavior. Among the most commonly used are: mklabel to create the partition table, mkpart to create partitions, print to list, resizepart to expand or shrink and rm To erase.
- Create partition table:
mklabel gptomklabel msdosdepending on whether you need GPT or MBR. GPT allows many more primary partitions. - Create partition:
mkpartwith sizes like1GB,10GBor sectors if activeunit s. It is used to define the limits of the space that the file system will occupy. - List partitions:
printand variants such asprint devicesoprint freeto see devices and free slots. - Resize:
resizepart N FINadjusts the final boundary of partition number N. Be careful to do it in coherence with the file system.. - Eliminate:
rm Ndeletes partition N from the table (does not delete the data itself, but dereferences it).
MBR vs GPT: Limits and Advantages
With MBR (msdos) you are limited to four primary partitions, although you can use an extended partition to add logical partitions (it is common to talk about up to 23 logical partitions in classic examples). With GPT, the modern EFI/UEFI standard, you can get up to dozens of primary partitions (typically 128) without the complexity of extended versions; if you need to migrate, see how convert disk from MBR to GPT without losing data.
A common example in MBR is to create a primary partition that goes from 1024MiB to 2048MiB. In parted, as soon as you enter the device, you would simply invoke mkpart indicating those limits, and that's it: you create a small primary partition in a specific range without depending on rounded GB sizes.
Check partition style and work by sectors
You can inspect a disk like this: parted /dev/xvdb, and inside write p to see the partition style. In the output, the field Partition Table Enter "msdos" for MBR or "gpt" for GPT. To exit, type q. If you want millimeter precision, use unit s to measure in sectors and avoid doubts about start/end points. This helps recreate partitions respecting exact borders.
Practical examples: from zero to productive
Let's start with a typical scenario: creating a GPT on a new disk and creating the first partition. In non-interactive mode, you could run: # parted /dev/sdb mklabel gpt and continue with # parted /dev/sdb mkpart primary ext4 1GB 10GB. Then you format and mount. It is a fast and reproducible flow.
Typical interactive session
Intervening with parted in a guided manner is very convenient. For example: # parted /dev/sdb, you'll see something like "GNU Parted XY Using /dev/sdb". Then: (parted) mklabel gpt, (parted) mkpart primary ext4 1GB 20GB, (parted) print y (parted) quitIn seconds, you have your first GPT table and the created partition.
List devices, partitions and slots
In interactive, print devices It shows you the detected disks, for example: /dev/sdb (268MB), /dev/sda (12,7GB). With print free You get a map per disk with the free space between partitions, ideal for deciding where to create the next one. contiguous partition.
Work by sectors and check output
In many procedures the unit is changed with unit s and is used p to see exact numbers. A textbook case on a system disk /dev/xvda could display something like this: total size 167772160s, logical/physical sector 512B/512B, msdos table and a partition 1 from 2048s to 83886079sWith that we locate the next free sector to create /dev/xvda2.
Create a new partition by sectors
Inside parted: mkpart, you indicate type primary, "ext4" file system for information purposes, start 83886080 and end 167772159. After confirming, you return to p to verify the new entry has been added. The next step is the file system: mkfs -t ext4 /dev/xvda2.
Format and mount
Ext4 formatting typically displays information about inodes, groups, and superblock copies. When the process completes with "done," you can mount: mount /dev/xvda2 /opt and check with df -TH that something like this appears /dev/xvda2 ext4 43G 51M 40G 1% /opt. It's that simple to put the new one into production. allocated space.
Inspect with lsblk and disassemble
lsblk It offers a clear tree of devices, capabilities, and mount points. It's the most visual way to confirm that /dev/xvdc (for example) has 60 GB, which /dev/xvdc1 It takes up 10 GB and is mounted on /mnt/sdc. If you need to operate, please disassemble first with umount /mnt/sdc and list again.
Resize a partition and its file system
There are two common approaches. One, extending an existing partition with resizepart; another option is to recreate the partition, respecting the start sector and setting a larger end sector. In both cases, remember that the file system must support the expansion. For ext3/ext4, the standard way is to run e2fsck -f and then resize2fs.
Recipe by sectors on a data disk
In a classic example of /dev/xvdc 60 GB, unmount, enter parted with parted /dev/xvdc, you select unit s, you check with p, you delete partition 1 with rm 1 and recreate it with the appropriate limits: mkpart opt 2048s 125829119. You confirm with p that /dev/xvdc1 exists again with the new ending.
For ext3/ext4, adjust the FS: e2fsck -f /dev/xvdc1 followed by resize2fs /dev/xvdc1, see again with lsblk the new capacity and mount: mount /dev/xvdc1 /mnt/sdc.
In XFS, filesystem growth is done online: you mount first and then run xfs_growfs /dev/xvdc1. Then you check with lsblk o df -TH that the increase has materialized in the partition and the mount point. It is a very direct operation.
Create GPT and partition on a new disk
On cloud servers it is common to receive an empty disk, for example /dev/vdb. Check it out with lsblk and enters parted: parted /dev/vdb. One p returns "Partition Table: unknown", creates GPT with mklabel gpt, change to unit s and create the partition: mkpart test 2048s 100%.
Get out of parted with q, confirm with lsblk that exists /dev/vdb1, format with mkfs -t ext4 /dev/vdb1, create a mount point with mkdir /mnt/sdc and mounts: mount /dev/vdb1 /mnt/sdc. A query df -TH should show something like /dev/vdb1 ext4 106G 63M 101G 1% /mnt/sdc. Operation completed.
Automatic mounting with fstab
Get the UUID with blkid /dev/vdb1, you will see an output of the style /dev/vdb1: UUID=0b3040e2-1367-4abb-841d-ddb0b92693df TYPE="ext4". Opens vi /etc/fstab, enters into editing with i and add a line like: UUID=0b3040e2-1367-4abb-841d-ddb0b92693df /mnt/sdc ext4 defaults 0 2. Save with :wq. Disassemble with umount /dev/vdb1 and test mount -a. One mount | grep /mnt/sdc returns the line with type ext4 and options, you're done.
Complete scenarios with multiple partitions
Suppose you want a 160 GB external drive divide into five parts: FAT32, EXT4, NTFS, swap and XFS for /home. First locate the device with dmesg | tail y fdisk -l o parted -l, where you will see something like Disk /dev/sdb: 160GB. Go into parted /dev/sdb, delete old partitions rm N, create GPT with mklabel gpt and start creating:
- Partition 1: 20 GB for FAT32, for example with
mkpart Windowsfat fat32 1 20000. Perfect for exchange. - Partition 2: 50 GB for EXT4, for example
mkpart LinuxExt ext4 20000 70000. - Partition 3: 50 GB for NTFS, with
mkpart WindowsNTFS ntfs 70001 120000. - Partition 4: 4 GB for swap,
mkpart Swap linux-swap 120001 124000. - Partition 5: the rest for XFS (HOME), with
mkpart HOME xfs 124001 160000. This way you can take advantage of all the space.
Check the result with print to see sizes, names and flags. When you leave with quit, it will only be necessary to apply the corresponding formats mkfs.vfat, mkfs.ext4, mkfs.ntfs, mkswap y mkfs.xfs as you have decided.
Using print, help, and auxiliary commands
If you need contextual help, at the parted prompt run ? o help to see options like align-check (check alignment), rescue (try to recover a lost partition indicating start/end) or check (note: oriented to older FS and with limited support). With print and its variants you get the current photo of the device.
Warnings about mkpartfs and check
Parted includes historical commands such as mkpartfs o check to manipulate file systems, but they are not its strong suit. In fact, the program itself warns: "It is not as robust as specific tools like e2fsprogs and its support will be discontinued." The current recommendation is to use parted for partitions and native FS utilities to create or verify.
NOTICE: FS manipulation with parted (mkpartfs, check) is considered non-robust and support for many types has been deprecated.
mkfs,fsck, e2fsprogs, etc., which are the correct tools for each FS.
Quick diagnostics: lsblk and dmesg
lsblk Lists block devices and their partitions with sizes, types, and mount points. It is key to identifying /dev/sda, /dev/sdb, /dev/sdc and the numerical suffixes of their partitions, such as sda1, sdb2, etc. This way you avoid working on the wrong disk.
dmesg displays the latest kernel messages. Useful when you connect a USB and you want to confirm if it has entered as /dev/sdb o /dev/sdc. With dmesg | tail You immediately detect the event of connecting or removing the device, which is essential before running destructive commands.
Formatting partitions: mkfs and options
After creating a partition, it must be formatted with the desired FS. For compatibility between systems (Windows, macOS and Linux), exFAT is a common choice. Debian-derived distributions install support for sudo apt install exfat-utils and then run sudo mkfs.exfat -n MiUnidadExFat /dev/sdbX to name and format.
For native use on GNU/Linux, EXT4 is reliable and flexible: sudo mkfs.ext4 -L MiUnidadExt4 /dev/sdx1. After that, you can disconnect and reconnect so that the graphical environment mounts it automatically or perform the manual process with mount and your mount point.
Secure erase: dd with zeros or random
Format Deleting the partition table doesn't actually delete the data. If you want to prepare a disk for recycling or trade-in, you can overwrite it with zeros: sudo dd if=/dev/zero of=/dev/sdx. This method fills all sectors with 0x00 and makes it difficult information retrieval.
For added privacy, please enter random data: sudo dd if=/dev/urandom of=/dev/sdx. Some people repeat this several times in "paranoia mode"; it's slower, but the probability of recovering something is close to zero. Remember to replace the x by the correct device and not by a specific partition if you want to erase the entire disk.
Safety tips before touching partitions
Always make backups and follow good practices hard drive maintenance in Linux, validate device and partition with lsblk and check sector numbers if you're recreating partitions while preserving the boot. Avoid working with mounted systems when deleting, moving, or resizing. If in doubt, use a graphical environment like GParted for a clearer view, although parted It's perfect when you're looking for speed on a console.
Symptoms, cause and resolution
Symptoms: disks that won’t mount, partitions that don’t appear, unallocated space that isn’t used, or “unrecognized disk label” messages. Causes: missing table, poorly defined partitions, FS not expanding after resizing, or previous errors. Resolution: create or correct table with mklabel, define partitions with mkpart, check by sectors with unit s, adjust the FS with the system tools and secure the mount with fstab.
Additional use cases and tips
To list all detected disks at a glance: (parted) print devices. To see free spaces: (parted) print free. If you need to check the alignment: (parted) align-check min 1 o opt. And if you missed a partition entry but know its approximate range, (parted) rescue INICIO FIN can help you get it back.
If you want to know the partition style and get out quickly: parted /dev/xvdb, type p and check if Partition Table says "msdos" or "gpt"; type q to exit. This check, although simple, is the basis for deciding whether you are going to migrate to GPT with mklabel gpt.
Resize without service interruption (XFS) or with check (EXT)
For XFS, remember: first mount the partition to its point and then run xfs_growfs. For EXT3/EXT4, go through first e2fsck -f, then resize2fs and finally mount or remount. Check the result with lsblk y df -TH.
When resizing by sectors, it respects the boot sector when recreating the partition so as not to break the contents. parted allows you to work precisely if you use unit s and you lean on it print previo.
If they provide you, for example, the sectors 2048s , the Boot y 125829119 as the end, make sure the new end is equal to or greater than and confirm with Yes when parted suggests adjusting bounds. Then, resize the FS with its specific tool so that the system sees the expanded space.
Post-assembly checks
Usa df -TH to view usage by mount point with "human" sizes and clear units. Complemented with mount to inspect active options, and with blkid if you need the UUID for /etc/fstab. Keeping these checks handy avoids confusion and ensures that your startup scripts mount the records where he plays.
If this type of content makes your daily life easier, it's worth supporting the work behind it. Many guides invite you to visit a donation section; your support helps us continue creating up-to-date technical tutorials on System Administration.
Mastering parted will allow you to create and manage partitions with ease, migrate from MBR to GPT when needed, resize without fear, and automate boot. With the examples seen (creating tables, using unit s, sector re-creation, EXT and XFS growth, mounting and fstab) you now have a complete itinerary of real work with disks in Linux.
Passionate writer about the world of bytes and technology in general. I love sharing my knowledge through writing, and that's what I'll do on this blog, show you all the most interesting things about gadgets, software, hardware, tech trends, and more. My goal is to help you navigate the digital world in a simple and entertaining way.

