Disk partitioning means dividing a physical storage device (HDD/SSD) into logical sections called partitions.
These partitions are used to install OS, store files, or create special-purpose areas like swap.
Linux offers tools like fdisk (for MBR disks) and gdisk (for GPT disks) to manage partitions.
1. Partition Tables: MBR vs GPT
MBR (Master Boot Record)
GPT (GUID Partition Table)
2. fdisk — For MBR (and can handle GPT too)
fdisk is a command-line tool used to create and manage partitions.
List all disks using fdisk
sudo fdisk -l
Open a disk for editing
sudo fdisk /dev/sda
Once inside, you’ll use interactive commands:
Common fdisk Commands
| Key |
Action |
n |
Create a new partition |
d |
Delete a partition |
p |
Print the partition table |
t |
Change partition type |
w |
Write changes (save) |
q |
Quit without saving |
Example: Create a new partition using fdisk
-
Open fdisk:
sudo fdisk /dev/sda
-
Press n → new partition
-
Select primary
-
Choose partition number
-
Accept default start sector
-
Set size (example: +20G)
-
Press w to save
After creating partition, you must format it:
sudo mkfs.ext4 /dev/sda3
3. gdisk — For GPT Partitioning
gdisk works like fdisk but is specifically designed for GPT disks.
It is often referred to as the "GPT fdisk".
Start gdisk
sudo gdisk /dev/sda
Common gdisk Commands
| Key |
Action |
n |
Create new GPT partition |
d |
Delete partition |
p |
Print partition table |
t |
Change partition type (uses hex codes like EF00, 8300) |
w |
Write changes |
q |
Quit without saving |
Example Partition Type Codes
| Code |
Meaning |
8300 |
Linux filesystem |
8200 |
Linux swap |
EF00 |
EFI System Partition |
0700 |
Windows NTFS/exFAT |
4. After Partitioning — Format the Partition
Depending on usage:
For Linux filesystem
sudo mkfs.ext4 /dev/sda2
For swap area
sudo mkswap /dev/sda3
sudo swapon /dev/sda3
For FAT32 (USB drives)
sudo mkfs.vfat /dev/sdb1
5. Mounting the Partition
Once formatted:
sudo mkdir /mnt/data
sudo mount /dev/sda2 /mnt/data
To make it persistent, add to /etc/fstab.
6. Checking Partitions
Using lsblk:
lsblk
Using parted:
sudo parted -l
In Summary
| Tool |
Used For |
Partition Table Type |
| fdisk |
Basic partitioning |
MBR + GPT |
| gdisk |
Advanced GPT partitioning |
GPT only |
| parted |
Large disks, resizing |
MBR + GPT |