Storage Management & Partitioning

30 minLesson 9 of 16

Learning Objectives

  • List disks and partitions with lsblk and fdisk
  • Create and delete partitions using fdisk
  • Format partitions with mkfs (ext4, xfs)
  • Mount and unmount file systems
  • Configure persistent mounts in /etc/fstab

Disk Architecture in Linux

Linux represents disks as device files in /dev/:

DeviceType
/dev/sdaFirst SATA/SCSI disk
/dev/sdbSecond SATA/SCSI disk
/dev/nvme0n1First NVMe disk
/dev/sda1First partition on sda

Listing Disks and Partitions

lsblk — Block Devices

lsblk

Output:

NAME         MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
nvme0n1      259:1    0    8G  0 disk
├─nvme0n1p1  259:3    0  7.9G  0 part /
├─nvme0n1p14 259:4    0    4M  0 part
└─nvme0n1p15 259:5    0  106M  0 part /boot/efi
nvme1n1      259:0    0    5G  0 disk

fdisk — Detailed Disk Info

sudo fdisk -l

File System Info

# Show file system types
sudo lsblk -f
 
# Check specific partition
sudo blkid /dev/nvme0n1p1

File Systems

A file system organizes data on a partition. You must format a partition before using it.

File SystemDescriptionBest For
ext4Standard Linux FS, journalingGeneral purpose
xfsHigh-performance, scalableLarge files, databases
btrfsCopy-on-write, snapshotsAdvanced features
vfatFAT32, cross-platformBoot partitions, USB

Creating Partitions with fdisk

# Open fdisk on a disk
sudo fdisk /dev/nvme1n1

Interactive commands:

KeyAction
nCreate new partition
pPrint partition table
dDelete a partition
tChange partition type
wWrite changes and exit
qQuit without saving

Step-by-Step: Create a 2GB Partition

sudo fdisk /dev/nvme1n1
Command: n          # New partition
Select: p           # Primary
Partition number: 1 # First partition
First sector: Enter # Accept default
Last sector: +2G    # 2GB size
Command: w          # Write and exit

Verify:

lsblk

Formatting Partitions

Create a file system on the new partition:

# Format as ext4
sudo mkfs -t ext4 /dev/nvme1n1p1
 
# Format as xfs
sudo mkfs -t xfs /dev/nvme1n1p1
 
# Add a label
sudo e2label /dev/nvme1n1p1 "DATA"

Mount Points

A mount point is a directory where a partition's contents become accessible.

Mounting a Partition

# Create mount point
sudo mkdir -p /data
 
# Mount the partition
sudo mount /dev/nvme1n1p1 /data
 
# Verify
df -hT | grep data

Unmounting

sudo umount /data
# or
sudo umount /dev/nvme1n1p1
⚠️

You cannot unmount a partition if any process is using files on it. Use lsof /data to find which processes are accessing it.

Checking Mounted File Systems

# All mounted file systems
df -hT
 
# Specific mount
mount | grep nvme1n1

Persistent Mounts with /etc/fstab

Mounts created with mount are lost on reboot. Make them persistent:

# View current fstab
cat /etc/fstab

Example fstab entry:

# <device>              <mount>    <type>  <options>       <dump> <fsck>
UUID=b78a0d9e-5657...   /data      ext4    defaults        0      2
LABEL=DATA              /data      ext4    defaults        0      2

Columns Explained

ColumnPurpose
DeviceUUID, LABEL, or device path
Mount pointDirectory to mount on
TypeFile system type (ext4, xfs)
OptionsMount options (defaults, ro, noexec)
DumpBackup flag (0 = no)
FsckCheck order (0 = skip, 1 = root, 2 = others)

Adding a Persistent Mount

# Get the UUID
sudo blkid /dev/nvme1n1p1
 
# Edit fstab
sudo nano /etc/fstab
 
# Add line:
UUID=your-uuid-here /data ext4 defaults 0 2
 
# Test without rebooting
sudo mount -a
💡

Always use UUID in fstab instead of device names like /dev/sdb1. Device names can change between reboots, but UUIDs are permanent.

Deleting Partitions

# Unmount first
sudo umount /dev/nvme1n1p1
 
# Open fdisk
sudo fdisk /dev/nvme1n1
 
# Delete partition
Command: d
Command: w

Checking File System Health

# Check file system (must be unmounted)
sudo umount /dev/nvme1n1p1
sudo fsck /dev/nvme1n1p1
 
# Check and repair
sudo fsck -y /dev/nvme1n1p1

Summary

  • lsblk and fdisk -l list disks and partitions
  • fdisk creates/deletes partitions interactively
  • mkfs -t ext4 formats partitions with a file system
  • mount/umount attach/detach partitions to directories
  • /etc/fstab makes mounts persistent across reboots
  • Always use UUID in fstab for reliability
  • fsck checks and repairs file systems

Next Steps

Next, we'll cover LVM (Logical Volume Manager) — flexible storage that can be resized without downtime.