Disk Partitioning with fdisk

fdisk is the standard interactive tool for partitioning MBR (Master Boot Record) and GPT disks on Linux. It works in a menu-driven mode where changes are staged in memory and only written to disk when you save. Understanding fdisk well enough to safely partition a new data disk is an essential skill for Ubuntu server administration.

When to use fdisk

ToolPartition tableBest for
fdiskMBR and GPTInteractive partitioning of new disks
partedMBR and GPTScripting, large disks (>2TB), GPT-only features
gdiskGPT onlyGPT-specific partition types (UEFI, EFI System)

Use fdisk for interactive partitioning of disks up to 2 TB. Use parted for larger disks or automation. Both work fine for GPT on modern systems.

Inspecting disks and partitions

# List all block devices and their partitions
lsblk
lsblk -f    # Include file system info

# List all disks and their partition tables
sudo fdisk -l

# List a specific disk
sudo fdisk -l /dev/sdb

# Show partition table type and partitions
sudo parted /dev/sdb print

lsblk output showing disks and partitions

NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda      8:0    0   50G  0 disk
├─sda1   8:1    0   49G  0 part /
└─sda2   8:2    0    1G  0 part [SWAP]
sdb      8:16   0  500G  0 disk            ← New unpartitioned disk

Creating partitions with fdisk

⚠️ WARNING: Partitioning a disk that has data will destroy that data. Always verify you have the correct disk with lsblk and fdisk -l before running any partitioning commands. On a production server, confirm the disk is /dev/sdb (not sda which is usually the OS disk). Double-check disk size matches what you expect.

# Start fdisk on a new disk
sudo fdisk /dev/sdb

Interactive fdisk session — creating a single partition

Welcome to fdisk (util-linux 2.37.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): g       ← Create GPT partition table (use 'o' for MBR)
Created a new GPT disklabel.

Command (m for help): n       ← New partition
Partition number (1-128, default 1): 1
First sector (2048-1048575966, default 2048): [Enter]     ← Accept default start
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-1048575966, default 1048575966): [Enter]    ← Use entire disk

Created a new partition 1 of type 'Linux filesystem' and of size 500 GiB.

Command (m for help): p       ← Print partition table to verify
Device     Start        End    Sectors  Size Type
/dev/sdb1  2048  1048575966  1048573919  500G Linux filesystem

Command (m for help): w       ← Write changes to disk
The partition table has been altered.
Syncing disks.
# After creating partition: create file system and mount
sudo mkfs.ext4 /dev/sdb1
sudo mkdir -p /data
sudo mount /dev/sdb1 /data

# Add to /etc/fstab for persistent mount
UUID=$(sudo blkid -s UUID -o value /dev/sdb1)
echo "UUID=$UUID  /data  ext4  defaults,noatime  0  2" | sudo tee -a /etc/fstab
sudo mount -a    # Test

Deleting partitions

# Delete a partition in fdisk
sudo fdisk /dev/sdb
# d → delete partition
# 1 → partition number
# w → write changes

Partitioning for common scenarios

# Scenario: 500 GB data disk — one large partition for LVM (recommended for flexibility)
# In fdisk on /dev/sdb:
# g   → GPT
# n   → new partition
# 1, Enter, Enter   → one partition using all space
# t   → change type
# 30  → type "Linux LVM" (allows LVM to use it later)
# w   → write

# Scenario: Split disk into multiple partitions
# In fdisk on /dev/sdb:
# g   → GPT
# n → 1 → Enter → +100G     (first 100 GB)
# n → 2 → Enter → +200G     (next 200 GB)
# n → 3 → Enter → Enter     (rest of disk)
# w   → write

# After: make file systems and mount each
sudo mkfs.ext4 /dev/sdb1
sudo mkfs.xfs /dev/sdb2
sudo mkfs.ext4 /dev/sdb3

Conclusion

For adding a new data disk to an Ubuntu server, the standard workflow is: identify the disk with lsblk, partition with fdisk (create GPT table, single partition), format with mkfs.ext4 or mkfs.xfs, mount it, and add to /etc/fstab using its UUID. For disks that will be managed by LVM, set the partition type to "Linux LVM" in fdisk and then create the LVM physical volume with pvcreate.

FAQ

Is Disk Partitioning with fdisk important for Ubuntu administrators?+

Yes. It supports practical Ubuntu administration because it connects directly to server reliability, security, troubleshooting, or daily operations.

Should I practice this on a live server?+

Use a lab VM first. After you understand the command output and rollback path, apply the workflow carefully on real systems.

What should I do after reading this article?+

Run the practice commands, write down what each one shows, and continue to the next article in the Ubuntu roadmap.

Need help with Ubuntu administration?

Work directly with Muhammad Irfan Aslam for Ubuntu Server, Linux, cloud, Docker, DevOps, CI/CD, or infrastructure troubleshooting support.

Hire Me for Support