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
fdiskis 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
| Advantage | Description |
|---|---|
| Lightweight | Uses very little system resources |
| Fast | Immediate disk operations |
| Pre-installed | Available on almost all Linux systems |
| Reliable | Trusted tool for decades |
| Scriptable | Can automate partitioning |
| Terminal-based | Works on servers without GUI |
Also read about Mkfs Command in Linux: Complete Guide With Examples, Types
Disadvantages of fdisk
| Disadvantage | Explanation |
|---|---|
| Risky | Wrong command can destroy data |
| No GUI | Not beginner-friendly |
| Limited GPT features | Better tools exist (like parted) |
| No resizing live partitions | Requires unmounted disks |
| Manual work | Requires 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
| Command | Function |
|---|---|
fdisk -l | List all disks |
fdisk /dev/sda | Open disk |
n | Create partition |
d | Delete partition |
p | Print partition table |
w | Write changes |
q | Quit without saving |
t | Change partition type |
m | Help 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
| Tool | Interface | Best For |
|---|---|---|
| fdisk | CLI | Basic partitioning |
| cfdisk | CLI (menu) | Beginners |
| parted | CLI | GPT + large disks |
| gparted | GUI | Desktop users |
Fdisk command in Linux with examples

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
partedinstead
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
| Key | Function |
|---|---|
m | Help |
p | |
n | New |
d | Delete |
t | Type |
w | Write |
q | Quit |
g | GPT |
o | MBR |
l | List types |
Also read about What Is The Difference Between FAT And NTFS File Systems?
