Partitioning and Formatting a New Disk With parted and mkfs

GPT, alignment, and picking a filesystem, without the guesswork

Contents

Every disk that isn’t going straight into a ZFS pool eventually goes through the same three steps: partition it, format it, mount it. It’s routine enough that I still do it from memory, and routine enough that I’ve watched people get it wrong in ways that don’t surface until months later — a partition that’s misaligned against the drive’s real sector size, an mkfs run against the whole disk instead of a partition, a filesystem chosen by habit rather than by what the disk is actually for. None of these mistakes are dramatic at the time. All of them cost you something later.

MBR is dead, use GPT

If you’re formatting a disk over 2 TB, MBR (the classic DOS partition table) simply can’t address it — that’s a hard technical limit, not a preference. For anything smaller it’s still worth using GPT anyway: it supports more partitions without needing an extended-partition workaround, stores a backup copy of the partition table at the end of the disk so a corrupted primary copy is recoverable, and every disk utility written in the last decade assumes it by default. There’s no longer a real reason to reach for MBR on a Linux system unless you’re supporting genuinely ancient BIOS boot requirements.

1
sudo parted /dev/sdb mklabel gpt

That one line replaces whatever was on the disk with a fresh, empty GPT table. It immediately destroys the partition table, and the data sitting behind it survives only until something writes over it — treat this as the point of no return anyway, and double-check the device node before running it.

Partitioning with parted

parted can run interactively or take commands directly on the CLI, and for scripted or repeatable setups the direct form is worth learning even though it looks slightly awkward at first:

1
2
sudo parted -a optimal /dev/sdb -- mkpart primary ext4 0% 100%
sudo parted /dev/sdb print

-a optimal is the part people skip and shouldn’t — it tells parted to align the partition to the disk’s reported optimal I/O size rather than an arbitrary sector boundary. Misalignment on a modern 4Kn or 512e disk means a single logical filesystem block can straddle two physical sectors, forcing a read-modify-write cycle for what should be a single sector operation; on spinning disks this is a measurable performance tax, and on SSDs it accelerates wear by turning single-page writes into multi-page ones. 0% 100% tells parted to use the entire disk for this one partition rather than working out cylinder-aligned byte offsets by hand, which was necessary decades ago and is just unnecessary friction now.

For multiple partitions, repeat with explicit start/end percentages or sizes:

1
2
sudo parted -a optimal /dev/sdb -- mkpart primary ext4 0% 50%
sudo parted -a optimal /dev/sdb -- mkpart primary xfs 50% 100%

parted print afterward confirms both the layout and, usefully, flags any alignment warning directly — if it reports a partition as “not aligned for best performance,” fix it before formatting rather than after; resizing a partition once there’s a filesystem and data on it is a strictly more dangerous operation than getting it right the first time.

Choosing a filesystem: ext4, XFS, or btrfs

This is the step people spend the least thought on and probably shouldn’t. The three realistic mainstream choices for a general-purpose Linux data partition each have a genuinely different sweet spot.

ext4 is the conservative default: extremely mature, predictable, fast at small-file workloads, and the filesystem every recovery tool and every distribution’s installer has been tested against the longest. For a boot disk, a general-purpose data partition, or anything where you want the most boring, most-tested option, it remains the right default.

1
sudo mkfs.ext4 -L data /dev/sdb1

XFS is the better choice for large files and high-throughput sequential workloads — media libraries, large database files, anything where you’re writing or reading multi-gigabyte files rather than millions of small ones. It scales better to very large filesystems and handles parallel I/O across multiple threads more gracefully than ext4 in most benchmarks, at the cost of slightly worse small-file and metadata-heavy performance, and it notably has no supported way to shrink a filesystem once created — only grow, so size the partition with headroom.

1
sudo mkfs.xfs -L media /dev/sdb2

btrfs is worth reaching for specifically when you want checksumming and snapshots without going all the way to ZFS — it’s mainlined, has mature single-disk and mirrored redundancy, and its snapshot/send-receive tooling is genuinely good. Its RAID5/6-equivalent parity modes still carry long-standing data-loss caveats, so stick to single-disk or mirrored configurations if you go this route; Btrfs snapshots managed with Snapper is a solid pattern for a desktop or a lightly-loaded server that wants rollback capability without the operational overhead of a full ZFS pool.

1
sudo mkfs.btrfs -L snapshots /dev/sdb3

Labels over UUIDs over device names

Whichever filesystem you pick, give it a label at creation time (-L above) — it’s the cheapest insurance against the single most common post-reboot headache: device names shifting. /dev/sdb today is not guaranteed to be /dev/sdb after adding or removing a drive, a controller change, or sometimes just a kernel update reordering enumeration. Mounting by label, or better, by UUID, sidesteps this entirely:

1
2
lsblk -f
sudo blkid /dev/sdb1

In /etc/fstab, reference the partition by UUID rather than device name:

1
UUID=3a8f1c2e-9b7d-4e21-9f0a-6c1d2e3f4a5b  /mnt/data  ext4  defaults,noatime  0  2

noatime is worth defaulting to on anything that isn’t specifically relying on access-time tracking (mail servers, some backup tools) — it removes a write on every single file read, which adds up meaningfully on a busy filesystem and costs you nothing most people actually use.

Mounting and verifying

1
2
3
sudo mkdir -p /mnt/data
sudo mount /dev/sdb1 /mnt/data
df -hT /mnt/data

df -hT confirms both that the mount succeeded and which filesystem type actually landed — a useful sanity check if you’ve been copy-pasting commands across a multi-partition setup and want to confirm partition 2 really did end up XFS rather than accidentally ext4 from a stray copy-paste. Test with mount -a after editing fstab and before rebooting; a syntax error in fstab that only surfaces at boot, on a headless server with no physical console handy, is a genuinely unpleasant way to spend an evening.

Resizing later, and why it’s easier to plan around than to do

Growing a partition after the fact is possible but more fragile than getting the size right up front, and each filesystem behaves differently. parted resizepart can grow a partition into adjacent free space without touching the filesystem inside it, but the filesystem itself then needs its own resize step — resize2fs for ext4, xfs_growfs for XFS (mounted, since XFS only supports online growth), and btrfs filesystem resize for btrfs. All three handle growing reasonably safely. Shrinking is a different story: ext4 supports offline shrinking with resize2fs before the partition itself is shrunk, XFS supports no shrinking at all — full stop, by design — and btrfs technically supports it but it’s slow and best avoided on anything large. If there’s any chance a partition will need to grow later, either leave unallocated space after it during initial partitioning, or use LVM underneath so growth doesn’t require touching partition boundaries at all.

1
2
sudo parted /dev/sdb resizepart 1 100%
sudo resize2fs /dev/sdb1

Checking sector size before you trust “optimal” alignment

-a optimal does the right thing on almost every consumer and enterprise disk sold in the last decade, but it’s still worth confirming what the drive is actually reporting rather than assuming parted got the right answer, particularly on USB enclosures and some cheap SATA-to-USB bridges that lie about their real sector geometry:

A hard disk drive opened up, showing the platter, the actuator arm and its read-write head.
The platter and read-write head of a hard disk. Partition tables and alignment describe how the drive’s sectors are carved up. Photo: Hard disk platters and head by Mfield, Matthew Field, http://www.photography.mattfield.com, CC BY-SA 3.0, via Wikimedia Commons.
1
2
3
$ sudo blockdev --getss --getpbsz /dev/sdb
512
4096

The first number is the logical sector size, the second the physical sector size — a classic 512e drive (physical 4Kn sectors, presented as logical 512-byte sectors for compatibility with old software) shows exactly this split. lsblk -o NAME,PHY-SEC,LOG-SEC gives the same information in table form across every block device at once, which is the faster check when you’re setting up several disks in one sitting:

1
2
3
4
$ lsblk -o NAME,PHY-SEC,LOG-SEC /dev/sdb /dev/sdc
NAME PHY-SEC LOG-SEC
sdb     4096     512
sdc      512     512

Where this actually bites is cheap USB-to-SATA bridges, which sometimes misreport physical sector size entirely — reporting 512 when the drive underneath is genuinely 4Kn, or the reverse. If parted print warns about alignment after you’ve already used -a optimal, don’t dismiss it as parted being overcautious; it’s picked up on a genuine mismatch between what the bridge reported and what the drive actually uses, and it’s worth partitioning that disk directly via a native SATA or NVMe connection if one is available, then moving it into the enclosure afterward.

When to reach for LVM instead

Plain partitions are the right choice when a disk’s layout is genuinely fixed for its lifetime — a boot disk, a single-purpose data drive that will never need repartitioning. The moment you expect to add space later, move a volume to a bigger disk without an outage, or want to snapshot a volume independent of the underlying filesystem’s own snapshot support, LVM is worth the extra layer of abstraction. A logical volume can be grown by adding a new physical disk to its volume group with zero partition-table surgery on the original disk, and can be shrunk or moved between physical disks live in ways a raw partition simply can’t. The tradeoff is one more layer to understand when something goes wrong — pvs, vgs, lvs become part of your troubleshooting vocabulary alongside lsblk and blkid. For a homelab data disk I expect to outgrow, I reach for LVM by default now; for a boot disk or a single-purpose drive, plain partitions stay simpler and there’s nothing to gain from the extra layer.

Troubleshooting the common failures

“Partition doesn’t show up after parted” almost always means the kernel hasn’t re-read the partition table — run partprobe /dev/sdb or simply re-run lsblk, and if neither picks it up, a reboot resolves it as a last resort on older kernels that are stubborn about a device already in use. “mkfs refuses with ‘device is busy’” means something still has a handle on the partition — check lsof and mount output for stale mounts, and make sure no LVM or mdadm metadata from a previous life of the disk is still registered; wipefs -a /dev/sdb1 clears stale filesystem/RAID signatures that parted alone won’t touch and is worth running on any disk that’s had a previous life before it goes back into service.

If a disk was previously part of a hardware or software RAID array and you’re repurposing it standalone, don’t skip the wipefs step — leftover RAID superblock metadata at the end of the disk has caused mdadm to “helpfully” reassemble a phantom array on boot more than once, pulling a disk you thought was independent back into an array it no longer belongs to.

A note on secure erasure before repurposing a disk

If a disk previously held sensitive data and you’re repurposing or disposing of it, parted mklabel gpt and mkfs do not securely erase anything — they only overwrite the partition table and filesystem metadata, leaving the actual data recoverable with the same tools used in a dd/ddrescue-style rescue. On a spinning disk, shred or a full-disk dd if=/dev/zero pass is the traditional approach, though it’s slow on anything multi-terabyte. On an SSD, overwriting doesn’t reliably reach every physical cell due to wear-levelling and overprovisioning, so the correct tool is blkdiscard (issues a TRIM/discard across the whole device) or the drive’s own ATA Secure Erase command via hdparm, not a dd pass — worth knowing while the drive is still in your hands, because there’s no fixing it once it’s gone.

Verdict

None of this is complicated once you’ve done it a handful of times, which is exactly why it’s worth doing carefully rather than from memory-on-autopilot the one time it matters — a misaligned partition or a filesystem choice that doesn’t match the workload doesn’t announce itself, it just quietly costs you throughput or wear for the life of the disk. GPT by default, -a optimal on every partition, a filesystem chosen for the actual access pattern rather than habit, and mounting by UUID rather than device name — that combination has never once bitten me, and every deviation from it eventually has.

Smarc
Written by Smarc

Founder and editor of Aside House. A lifelong tinkerer who self-hosts far more than is sensible, hardens Linux boxes for fun, and prods the latest AI tools to see what they can really do. The how-to guides here are the notes Smarc wishes had existed the first time round.

Smarc is the editor of Aside House. The homelab, the hardware and the opinions are real; the guides are drafted with AI assistance. Infrastructure details are genericised on purpose.