Page Content

Tutorials

Fdisk Command In Linux With Examples, Features & Advantages

In this blog, we cover everything about the fdisk command in Linux with examples, including what fdisk is, how it works, its role in the operating system, important features, advantages and disadvantages, types of partition schemes, common fdisk commands, interactive mode commands, real-world examples, fdisk vs other tools, and best practices for safe disk partitioning.

What is fdisk in Linux?

Linux and Unix-like operating systems employ the command-line tool fdisk, which stands for Fixed Disk, to manage disk partitions. On storage devices including hard drives, SSDs, and USB drives, it enables system administrators to add, remove, resize, and alter disk partitions.

How It Works

Instead of moving your data, fdisk modifies the Partition Table at the very start of the disk.

  • The disk’s “map” is loaded into memory when fdisk is executed.
  • In an interactive menu, you make modifications (such as adding a new division).
  • Until you specifically instruct the application to “write” (w) the modifications to the disk, these changes are only virtual.

Also read about Basic Disk Management Commands In Linux With Examples

Functions in the Operating System

  • Disk initialization is the process of creating a raw disk’s first partition in order to prepare it to store data.
  • Partition management is the process of splitting a single physical drive into several logical drives, such as segregating user data from operating systems.
  • System ID Modification: Altering the kind of partition (for example, converting a regular Linux partition to an LVM member or a swap partition).
  • Verification: Making sure there are no overlapping boundaries by examining the partition table’s integrity.

Important Features

Interactive Menu: Simple single-letter instructions, such as n for new, d for delete, and p for print, are used in the interactive menu.

MBR & GPT Support: Current iterations of fdisk support both the more recent GPT (almost infinite size) and the more traditional MBR (2TB limit) standards.

Hex Code Assignment: This feature enables users to assign particular hexadecimal codes to partitions so that the operating system is aware of their function (e.g., 83 for Linux, 82 for Swap).

Non-Destructive Preview: To test layouts without really altering the data until you save, you can remove and re-create divisions in the interface.

Advantages of fdisk

AdvantageDescription
LightweightUses very little system resources
FastImmediate disk operations
Pre-installedAvailable on almost all Linux systems
ReliableTrusted tool for decades
ScriptableCan automate partitioning
Terminal-basedWorks on servers without GUI

Also read about Mkfs Command in Linux: Complete Guide With Examples, Types

Disadvantages of fdisk

DisadvantageExplanation
RiskyWrong command can destroy data
No GUINot beginner-friendly
Limited GPT featuresBetter tools exist (like parted)
No resizing live partitionsRequires unmounted disks
Manual workRequires technical knowledge

Types of Partition Schemes Handled

Primary Partitions: The primary partitions are the four basic divisions on the MBR.

Extended Partitions: A unique kind of container-like primary partition.

Logical Partitions: To get around the 4-partition MBR constraint, partitions are made inside an extended partition.

GPT Partitions: The most recent standard that does not require “Extended” containers and permits up to 128 partitions.

Swap Partition: Used as virtual memory.

Boot Partition: Stores bootloader files.

Common fdisk Commands

CommandFunction
fdisk -lList all disks
fdisk /dev/sdaOpen disk
nCreate partition
dDelete partition
pPrint partition table
wWrite changes
qQuit without saving
tChange partition type
mHelp menu

Real-World Example

Creating a new partition:

bash

sudo fdisk /dev/sdb
n   → create new
p   → primary
1   → partition number
w   → write

Then format it:

bash

mkfs.ext4 /dev/sdb1

Mount:

bash

ount /dev/sdb1 /mnt

Also read about Kill Process Linux: Commands, Signals And Real Examples

Fdisk vs Other Tools

ToolInterfaceBest For
fdiskCLIBasic partitioning
cfdiskCLI (menu)Beginners
partedCLIGPT + large disks
gpartedGUIDesktop users

Fdisk command in Linux with examples

Fdisk command in Linux
Fdisk command in Linux

fdisk is an interactive disk partitioning tool. Below are the most important fdisk commands with clear, practical examples.

List All Disks

Command:

bash

fdisk -l

Example Output:

Shows all available disks like:

bash

/dev/sda 500GB
/dev/sdb 1TB

Use case: Identify which disk you want to manage.

Open a Disk

Command:

bash

sudo fdisk /dev/sda

Use case: Opens the disk in interactive mode.

Display Help Menu

Command inside fdisk:

bash

m

Use case: Lists all available options.

Print Partition Table

Command:

bash

p

Use case: Shows current partitions on the disk.

Create a New Partition

Command:

bash

n

Example Flow:

mathematica

n → p → 1 → Enter → Enter

Creates a new primary partition using default size.

Delete a Partition

Command:

bash

d

Use case: Removes a selected partition.

Change Partition Type

Command:

bash

t

Example:

Change to Linux swap:

nginx

t → 82

Write Changes to Disk

Command:

bash

w

Use case: Saves all modifications.

Quit Without Saving

Command:

bash

q

Also read about What Is Btrfs File System In Linux? And Btrfs Vs Ext4 Vs XFS

Verify Partition Table

Command:

bash

fdisk -l /dev/sda

Create GPT Table

Command:

bash

g

Creates GUID Partition Table.

Create MBR Table

Command:

bash

o

Delete All Partitions

Example:

nginx

d → 1
d → 2
d → 3

Resize Partitio

fdisk cannot resize live partitions. You must:

  • Delete and recreate
  • Use parted instead

Complete Real Example

Step 1: Identify disk

bash

lsblk

Step 2: Open disk

bash

sudo fdisk /dev/sdb

Step 3: Create partition

mathematica

n → p → 1 → Enter → Enter

Step 4: Save

nginx

w

Step 5: Format

bash

mkfs.ext4 /dev/sdb1

Step 6: Mount

bash

mount /dev/sdb1 /mnt

Fdisk interactive mode commands

KeyFunction
mHelp
pPrint
nNew
dDelete
tType
wWrite
qQuit
gGPT
oMBR
lList types

Also read about What Is The Difference Between FAT And NTFS File Systems?

Hemavathi
Hemavathihttps://govindhtech.com/
Myself Hemavathi graduated in 2018, working as Content writer at Govindtech Solutions. Passionate at Tech News & latest technologies. Desire to improve skills in Tech writing.
Index