Mastering Disk Partitioning with fdisk on Linux

Only users with root privileges or those granted sudo access can execute partitioning operations. Most modern Linux distributions include fdisk by default, including Ubuntu, Debian, Fedora, CentOS, Arch Linux, and Raspbian. On systems where it’s not in the default PATH, install it via the util-linux package.

Basic Syntax

fdisk [options] <device>

Replace <device> with the target block device, such as /dev/sda or /dev/nvme0n1.

Common Options

Option Description
-l List all partitions on all devices or a specified device
-u Display sector counts instead of cylinders (modern default)
-s Display the size (in blocks) of a specific partition
-v Show version information

Practical Examples

1. List All Disk Patritions

sudo fdisk -l

This displays all detected storage devices and their partition layouts, including sizes, types, and start/end sectors.

2. Inspect a Specific Disk

sudo fdisk -l /dev/nvme0n1

Focuses output on the NVMe drive, useful for systems with multiple disks.

3. Enter Interactive Mode

sudo fdisk /dev/sdb

Launches the interactive prompt for the target device. You’ll see a Command (m for help): prompt.

4. Display Current Partition Table

Within the interactive session, type:

p

Prints the current partition table with details like device name, start/end sectors, size, and filesystem type.

5. Create a New Partition

In interactive mode, enter:

n

You’ll be prompted to choose:

  • Partition type (primary or extended)
  • Partition number
  • First sector (default recommended)
  • Last sector or size (e.g., +10G for a 10GB partition)

After confirmation, the partition is created in memory but not written to disk.

6. Delete an Existing Partition

Type:

d

Then select the partition number to remove. This does not erase data — it only removes the partition entry from the table.

7. Write Changes to Disk

w

Commits all changes to the partition table. The system may need to rescan the device using partprobe or a reboot to recognize new partitions.

8. Exit Without Saving

q

Abandons all unsaved modifications and exits the utility safely.

Important Considerations

  • Always verify the target device using lsblk or sudo fdisk -l before proceeding — selecting the wrong disk can lead to data loss.
  • After creating a partition, use mkfs (e.g., mkfs.ext4 /dev/sdb1) to format it with a filesystem.
  • Some systems require a reboot or partprobe to reload partition tables after changes.
  • For GPT disks, consider using gdisk instead of fdisk, as fdisk has limited GPT support on older versions.
  • Never run fdisk on a mounted root filesystem unless you're certain of the consequences.

Related Utilities

  • lsblk — List block devices in a tree format
  • partprobe — Notify the kernel of partition table changes
  • mkfs — Create filesystems on partitions
  • blkid — Display UUIDs and filesystem types of block devices
  • mount / umount — Attach or detach filesystems
  • parted — Advanced partitioning tool with scriptable interface
  • fsck — Check and repair filesystem integirty
  • df — Show mounted filesystem usage

Tags: fdisk partitioning lsblk blkid mkfs

Posted on Thu, 10 Sep 2026 16:36:53 +0000 by Ange52