All posts

fdisk vs parted: create Linux partitions the right way

Huma ShaziaJune 29, 2026 at 4:47 PM8 min read
fdisk vs parted: create Linux partitions the right way

Key Takeaways

fdisk vs parted: create Linux partitions the right way
Source:
  • Use GPT for disks over 2TB or UEFI systems; MBR only for legacy BIOS compatibility
  • fdisk handles interactive partitioning; parted allows scriptable, immediate changes
  • Always verify your target disk with lsblk before writing any partition table

Partitioning a disk in Linux divides one physical drive into isolated sections the kernel treats as separate devices. You do this to separate the operating system from user data, carve out swap space, run multiple OSes, or limit blast radius when a filesystem corrupts. The two command-line tools that handle the job are fdisk and parted. Picking the right one depends on your partition table format and whether you need scripting.

ℹ️

Disclosure

Some links in this post are affiliate links — Logicity earns a commission if you sign up, at no extra cost to you. We only link products we have used or actively recommend.

This tutorial walks through identifying your disk safely, choosing between MBR and GPT, creating partitions with both tools, formatting with ext4 or xfs, mounting temporarily and permanently via /etc/fstab, and deleting partitions when you're done. Every step runs on a standard terminal. If you're managing cloud VMs on DigitalOcean, Cloudways, or bare-metal servers, these commands are identical.

Advertisement

GPT vs MBR: which partition table do you need?

A disk cannot hold partitions until it has a partition table, a small structure at sector zero that records where each partition starts and ends. MBR (Master Boot Record, also shown as msdos) is the legacy format. It addresses disks up to 2.2 TB and caps you at four primary partitions. Need more? You convert one primary into an extended partition containing logical partitions, a workaround that dates back to the 1980s.

GPT (GUID Partition Table) is the modern standard baked into UEFI. It supports disks up to roughly 9.4 zettabytes, allows 128 partitions by default, and stores a backup of the table at the disk's end. Unless you're dealing with ancient BIOS hardware, GPT is the safer choice.

Check what your disk already uses before changing anything:

bash
sudo fdisk -l /dev/vda

Look for the Disklabel type line. It reports dos for MBR or gpt for GPT.

Identify the correct disk before you touch anything

Partitioning the wrong device destroys data. Always confirm your target. The lsblk command lists block devices with their mount points:

bash
lsblk

You'll see something like vda with children vda1, vda2 if partitions exist. A fresh attached volume, say vdb, appears with no children. That empty disk is your target. Double-check size and serial with:

bash
sudo fdisk -l /dev/vdb

How to create a partition using fdisk

fdisk is an interactive, menu-driven tool. It buffers your changes in memory and writes nothing until you confirm with w. That buffer gives you a chance to abort mistakes.

  1. Launch fdisk on the target disk: sudo fdisk /dev/vdb
  2. Press g to create a new GPT table (or o for MBR).
  3. Press n to add a partition. Accept defaults for partition number and first sector. For the last sector, enter +50G to create a 50 GB partition, or press Enter to use all remaining space.
  4. Press t to change the partition type if needed. Type 1 for EFI System, 20 for Linux filesystem, or L to list codes.
  5. Press p to print the table and verify.
  6. Press w to write changes and exit. This is destructive.

After writing, the kernel re-reads the table. Verify with lsblk; you should see vdb1.

How to create a partition using parted

parted writes changes immediately. No buffer, no undo. That makes it dangerous but also scriptable, a key difference for automation.

  1. Open the disk: sudo parted /dev/vdb
  2. Create a GPT label: mklabel gpt (or mklabel msdos for MBR).
  3. Create a partition: mkpart primary ext4 0% 100% allocates the full disk. Replace 100% with 50GB or another value to leave space.
  4. Print to verify: print
  5. Quit: quit

Because parted commits instantly, run print before quit to confirm your layout.

Format the partition with ext4 or xfs

A partition is useless until it has a filesystem. ext4 is the default on most distributions. xfs handles large files well and is Red Hat's default. Pick one:

Code sample: sudo mkfs.ext4 /dev/vdb1

Or for xfs:

Code sample: sudo mkfs.xfs /dev/vdb1

mkfs destroys existing data on that partition. Triple-check your device path.

Advertisement

Mount the partition temporarily

Create a mount point and attach the filesystem:

Code sample: sudo mkdir -p /mnt/data
sudo mount /dev/vdb1 /mnt/data

Run df -h to confirm the mount. This disappears after a reboot.

Make the mount permanent with fstab

Edit /etc/fstab to persist the mount. Use the partition's UUID instead of /dev/vdb1 because device names can shift between boots. Get the UUID with:

Code sample: sudo blkid /dev/vdb1

Add a line to /etc/fstab:

Code sample: UUID=<your-uuid> /mnt/data ext4 defaults 0 2

Test with sudo mount -a. If no errors appear, the mount survives reboots.

How to delete a partition

In fdisk, press d, select the partition number, then w to write. In parted, run rm 1 (where 1 is the partition number). Both actions are irreversible once written.

Common errors and how to fix them

  • Device or resource busy: unmount the partition first with sudo umount /mnt/data.
  • Partition table entries are not in disk order: run sudo partprobe /dev/vdb to re-read the table.
  • Kernel still uses old table: reboot or run partprobe.
  • fstab mount fails on boot: boot into recovery, comment out the bad line, then fix the UUID.
ℹ️

Logicity's Take

fdisk is fine for interactive, one-off work. parted's instant writes make it the better choice for provisioning scripts and infrastructure-as-code pipelines. If you automate server setup with Ansible or Terraform on DigitalOcean or AWS, parted's non-interactive mode integrates cleanly. For GUI-based partition management on a workstation, GParted wraps parted with a visual editor. On enterprise Linux, Red Hat's Cockpit web console also exposes partition tools for teams that avoid raw CLI.

Frequently Asked Questions

Can I resize a partition without losing data?

ext4 and xfs support online growth but not shrinking while mounted. Use resize2fs for ext4 or xfs_growfs for xfs after expanding the partition with parted or fdisk. Shrinking requires unmounting first and is riskier.

Should I use fdisk or parted for GPT?

Both support GPT. fdisk buffers changes, so mistakes can be cancelled before writing. parted writes immediately, making it faster for scripts but less forgiving.

What happens if I partition the wrong disk?

You lose all data on that disk. There is no undo. Always verify with lsblk and fdisk -l before running any write command.

Do I need to reboot after creating a partition?

Usually not. Running sudo partprobe /dev/vdb forces the kernel to re-read the table. A reboot is only necessary if partprobe fails on a busy device.

Also Read
How to tune AI agents that actually keep working

Server provisioning is part of a broader automation stack; this piece covers keeping automated systems reliable.

ℹ️

Need Help Implementing This?

If your team manages cloud infrastructure and wants hands-on guidance on disk provisioning, automation pipelines, or Linux server hardening, reach out to the Logicity team. We help engineering orgs ship faster with fewer surprises.

Advertisement
H

Huma Shazia

Senior AI & Tech Writer

Produced with AI assistance and reviewed by the Logicity editorial team. Learn more in our Editorial Policy.