Sagar.BlogArticle
All posts
All posts
Linux

fdisk & lsblk — Partition Management

View disk partition tables with lsblk and fdisk, manage partitions, and format filesystems on Linux.

March 23, 20255 min read
linuxdiskfdisklsblkpartitions

lsblk — List Block Devices

lsblk shows all storage devices and their partitions in a clean tree view — no root required.

lsblk                          # Tree view of all disk devices
lsblk -f                       # Include filesystem type + UUID
lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINT  # Custom columns

Sample lsblk Output

# NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
# sda      8:0    0   500G  0 disk
# ├─sda1   8:1    0   512M  0 part /boot/efi
# ├─sda2   8:2    0    50G  0 part /
# └─sda3   8:3    0   449G  0 part /home
# sdb      8:16   1    32G  0 disk
# └─sdb1   8:17   1    32G  0 part /mnt/usb

fdisk — Partition Management

sudo fdisk -l                  # List all disks and partitions
sudo fdisk -l /dev/sda         # Check a specific disk
sudo fdisk /dev/sdb            # Interactive partitioning (careful!)

fdisk Interactive Commands

KeyAction
pPrint partition table
nNew partition
dDelete partition
tChange partition type
wWrite changes and exit
qQuit without saving

blkid & mkfs

# View UUIDs and filesystem types
sudo blkid
sudo blkid /dev/sda1

# Format a partition (ERASES ALL DATA)
sudo mkfs.ext4 /dev/sdb1       # Format as ext4
sudo mkfs.xfs /dev/sdb1        # Format as XFS
sudo mkfs.vfat /dev/sdb1       # Format as FAT32 (USB compatible)

Formatting a partition with mkfs permanently erases all data on it. Double-check your device name before running.

Quick Check

Which command shows all block devices without requiring root privileges?

Exercise

Run lsblk -f to see all block devices with their filesystem types and UUIDs.