Objective

Identify disks, create and manage partitions using fdisk and parted, format with filesystems, and understand MBR vs GPT partition tables.

Tools & Technologies

  • fdisk
  • parted
  • gdisk
  • lsblk
  • mkfs
  • blkid

Key Commands

lsblk -f
fdisk /dev/sdb
parted /dev/sdb print
mkfs.ext4 /dev/sdb1
blkid /dev/sdb1

Architecture Overview

graph TD DISK[Physical Disk /dev/sdb] --> PT{Partition Table} PT -->|MBR/DOS| PART1[/dev/sdb1\nprimary] PT -->|MBR/DOS| PART2[/dev/sdb2\nprimary] PT -->|GPT| PARTP1[/dev/sdb1] PT -->|GPT| PARTP2[/dev/sdb2] PART1 --> FS1[ext4 filesystem] PART2 --> FS2[swap] FS1 --> MOUNT[/mnt/data] style DISK fill:#1a1a2e,stroke:#00d4ff,color:#e0e0e0 style FS1 fill:#1a1a2e,stroke:#00ff88,color:#e0e0e0

Step-by-Step Process

01
Identify Disks

Always identify disks correctly before partitioning — wrong disk = data loss.

lsblk                # block device tree
lsblk -f             # show filesystems
fdisk -l             # list all disks + partitions
df -hT               # mounted filesystems
ls -la /dev/disk/by-id/  # stable device names
02
Partition with fdisk

fdisk is the traditional MBR partition tool. Changes are only written when you type w.

sudo fdisk /dev/sdb
# Interactive commands:
m   – help
p   – print current table
n   – new partition
  p   – primary
  1   – partition number
  (enter) – first sector default
  +10G – size
t   – change type (82=swap, 83=Linux)
w   – write and exit
# Apply:
partprobe /dev/sdb
03
Format Partitions

Create a filesystem on the partition. Common types: ext4 (general), xfs (performance), swap.

sudo mkfs.ext4 /dev/sdb1      # ext4
sudo mkfs.xfs /dev/sdb2       # XFS
sudo mkswap /dev/sdb3         # swap
sudo swapon /dev/sdb3         # activate swap

# Verify
blkid /dev/sdb1
lsblk -f
04
GPT with parted

parted supports GPT and is better for disks larger than 2TB.

sudo parted /dev/sdb
(parted) mklabel gpt
(parted) mkpart primary ext4 1MiB 10GiB
(parted) mkpart primary linux-swap 10GiB 12GiB
(parted) print
(parted) quit

Challenges & Solutions

  • fdisk -l may show stale partition table — run partprobe after changes
  • mkfs overwrites any existing data on the partition

Key Takeaways

  • Use GPT for all new disks — MBR is limited to 2TB and 4 primary partitions
  • blkid and lsblk -f show UUID — use UUID in /etc/fstab, never /dev/sdX names