Alright, let’s talk about parted. This is the tool you reach for when fdisk starts giving you that look—you know, the one where it subtly hints it was designed in an era when a 2GB hard drive was a big deal. parted is its modern, GPT-capable successor. It’s a single tool that does it all: creates partitions, sets flags, and, most importantly, doesn’t faint at the sight of a multi-terabyte drive. It’s also a bit of a control freak; it makes changes immediately, so you have to know what you’re doing before you hit ‘Enter’. No take-backsies.

The Immediate Gratification (and Peril) Model

First, a crucial public service announcement: parted is not like other utilities. There is no safe, cozy “write buffer” where you can plan your entire partition table and then decide to quit without saving. The moment you issue a command like mkpart, it writes that change directly to the disk. This is fantastic for scripting and terrible for fat-fingering. There’s no ‘q’ to quit and forget. This is why we always, always start by…

Knowing Exactly What You’re Working With

Before you even think about making a change, you need to see the lay of the land. Blindly partitioning a disk is like doing brain surgery with a mirror and a stick. Don’t do it.

sudo parted /dev/sda print

This will spit out a lovely table. The first line tells you the disk’s path (/dev/sda), its size (a number so big it would make an 80s sysadmin weep), and the partition table type it’s using—either msdos (the old MBR style) or gpt. This is the most important piece of info. You can’t create a GPT partition table on a disk that’s already using MBR without obliterating all existing data. Which brings us to our next command.

Creating a spanking new GPT Table

So you’ve shoved a brand new, terrifyingly large drive into your machine. It’s raw. It’s unformatted. It’s probably using some weird OEM MBR table. Let’s fix that. This command will destroy any and all existing data on the disk. Let me say that again: this is a destructive operation. Make absolutely sure you’re targeting the correct disk (/dev/sdX).

sudo parted /dev/sdb mklabel gpt

Boom. Done. Your disk now has a shiny new GUID Partition Table (GPT). This isn’t a partition itself; it’s the framework that will hold the partitions. GPT is superior to MBR because it lets you have more than four primary partitions (128 by default in Linux!), allows partitions larger than 2TB, and stores a backup copy of the partition table at the end of the disk for better recovery chances. The designers finally got that one right.

Making Partitions That Make Sense

Now for the main event: creating a partition. We use the mkpart command. You need to specify three things: the name (just a label, useful for organization), the filesystem type (it doesn’t format the partition, it just sets a hint for it), and the start and end points.

Let’s say I want a partition for my vast collection of perfectly legal Linux ISOs. I’ll use the entire disk.

sudo parted /dev/sdb mkpart "Linux ISOs" ext4 0% 100%

Why 0% 100% instead of specific megabyte values? Because it’s smarter. It automatically aligns the partition to the optimal boundaries for modern storage (like SSD sectors), avoiding horrific performance issues. You can use MiB or GiB if you need precise control (e.g., 1MiB 500GiB), but percentages are usually the way to go for simple, large partitions.

The Arcane Art of Flags and Numbers

Sometimes, you need to do more than just make a big block of storage. You need a boot partition, or an ESP for UEFI. This is where flags come in.

For a UEFI system, you need a small FAT32 partition at the beginning of the disk with the esp (or boot on some older systems) flag set. Here’s how you’d do it:

sudo parted /dev/sdb mkpart "EFI System" fat32 1MiB 513MiB
sudo parted /dev/sdb set 1 esp on

Notice I started at 1MiB, not 0%. This is a best practice to ensure proper alignment. The partition number (1 in set 1) is assigned by parted when you create the partition. You can see all flags for a partition with print.

Resizing? Tread Carefully

Yes, parted can resize partitions. The command is resizepart. Here’s the massive, glaring caveat: it can only resize the partition entry in the table. It does not touch the filesystem inside the partition. If you shrink a partition, you must shrink the filesystem inside it first with something like resize2fs. If you grow a partition, you must grow the filesystem after. Get this order wrong, and you will have a very bad, no-good day involving data loss. The tool’s refusal to handle both steps is, in my opinion, a questionable choice that puts too much responsibility on the user. So, for resizing, my best practice is to use a dedicated tool like gparted (the GUI version) that handles both steps automatically, or be incredibly meticulous on the command line. parted is a brilliant, powerful tool, but it demands your respect and full attention. Wield it accordingly.