Disk Partitioning in Linux Using fdisk, parted, and partprobe

Disk partitioning is the process of dividing a storage device into separate, logical sections (partitions) so they can be formatted and used efficiently. Linux provides several tools for this, with fdisk, parted, and partprobe being among the most commonly used.

What is Disk Partitioning?

Disk partitioning is essential when:

  • Installing a new OS
  • Preparing a new hard drive
  • Creating dedicated mount points (e.g., /home, /var, /data)
  • Managing space efficiently and securely

A typical hard disk can have:

  • MBR (Master Boot Record): Supports up to 4 primary partitions or 3 primary + 1 extended
  • GPT (GUID Partition Table): Supports up to 128 partitions and is required for disks >2TB

fdisk – Command-Line Partitioning Tool for MBR Disks

fdisk is a powerful and interactive tool to create and manage partitions on MBR-based storage devices.

Syntax:

sudo fdisk /dev/sdX

Where /dev/sdX is the disk (e.g., /dev/sda, /dev/sdb)

Example Walkthrough:

  1. Open fdisk:
sudo fdisk /dev/sdb
  1. Common Commands Inside fdisk:
    | Command | Description |
    |———|——————————-|
    | m | Help |
    | n | Create a new partition |
    | d | Delete a partition |
    | p | Print current partition table |
    | t | Change partition type |
    | w | Write changes to disk |
    | q | Quit without saving |
  2. Create a Partition:
Command (m for help): n
Select type: primary (p) or extended (e)
Choose partition number
Set starting and ending sectors or size
  1. Write the Partition Table:
Command (m for help): w

parted – Advanced Partitioning for MBR and GPT

parted supports both MBR and GPT partition tables and is scriptable, making it ideal for large disks and automation.

Syntax:

sudo parted /dev/sdX

Example: Creating a GPT Partition

sudo parted /dev/sdb

Inside parted:

(parted) mklabel gpt
(parted) mkpart primary ext4 0% 10GB
(parted) print
(parted) quit

You can also do this in one line:

sudo parted -s /dev/sdb mklabel gpt mkpart primary ext4 0% 10GB

Checking Partition Table:

sudo parted /dev/sdb print

partprobe – Inform Kernel of Partition Table Changes

After using fdisk or parted, you may notice that Linux doesn’t immediately recognize the new partitions. partprobe tells the kernel to re-read the partition table without requiring a reboot.

Syntax:

sudo partprobe /dev/sdX

Example:

sudo partprobe /dev/sdb

Alternatively, use:

sudo kpartx -a /dev/sdb

Formatting the New Partition

Once created, partitions must be formatted before use.

Format with ext4:

sudo mkfs.ext4 /dev/sdb1

Format with xfs:

sudo mkfs.xfs /dev/sdb1

Mounting a Partition

sudo mkdir /mnt/data
sudo mount /dev/sdb1 /mnt/data

To make it permanent, add to /etc/fstab:

/dev/sdb1   /mnt/data   ext4   defaults   0 2

Summary Table

ToolSupported TableUse CaseInteractiveScripting
fdiskMBRLegacy BIOS-based partitioningYesNo
partedMBR & GPTModern large-disk setupYesYes
partprobeN/ARefresh kernel’s view of disksNoYes

✅ Conclusion

Partitioning is a foundational skill for Linux system admins. Whether you’re setting up a new server, deploying a new drive, or organizing data, mastering tools like fdisk, parted, and partprobe ensures you’re managing disks safely and efficiently.

Scroll to Top