Linux Full Tutorial -- Part 11: Disk Management & Storage

By Suraj Ahir 2025-12-25 11 min read

← Part 10Linux Tutorial · Part 11 of 12Part 12 →
Linux Full Tutorial -- Part 11: Disk Management & Storage

Disk management is a critical Linux skill -- "disk full" is one of the most common causes of production outages. Whether you need to add storage to a running server, find what is consuming disk space, or set up a new volume on AWS EC2, these commands and concepts are essential for anyone managing Linux systems.

Checking Disk Usage

df and du -- the daily disk commands
# df -- disk filesystem usage
df -h                  # Human readable (GB, MB)
df -h /                # Root filesystem only
df -T                  # Show filesystem type
df -i                  # Show inode usage (not just space)

# du -- disk usage of directories and files
du -sh /var/log        # Total size of /var/log
du -sh *               # Size of each item in current dir
du -sh /* 2>/dev/null  # Size of each top-level directory

# Find the largest directories
du -h /var | sort -rh | head -20

# Find large files
find / -type f -size +100M 2>/dev/null
find /var/log -type f -size +50M

# ncdu -- interactive disk usage navigator
sudo apt install ncdu
ncdu /var

Listing Block Devices

lsblk, fdisk, blkid
lsblk                    # Show block devices (disks and partitions)
lsblk -f                 # Show filesystems and UUIDs

# Example output:
# NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
# sda      8:0    0   20G  0 disk
# sda1     8:1    0   20G  0 part /
# sdb      8:16   0  100G  0 disk   (unformatted additional disk)

sudo fdisk -l            # Detailed partition info
blkid                    # Block device UUIDs and filesystems

# On AWS EC2:
# Root volume: /dev/xvda
# Additional EBS: /dev/xvdb, /dev/xvdc, etc.

Formatting and Mounting a New Disk

Set up a new EBS volume on AWS EC2
# After attaching new EBS volume in AWS console:
# 1. Check it appears
lsblk  # See /dev/xvdb with no MOUNTPOINT

# 2. Format with ext4 filesystem
sudo mkfs.ext4 /dev/xvdb

# 3. Create mount point
sudo mkdir -p /data

# 4. Mount temporarily
sudo mount /dev/xvdb /data

# 5. Make it permanent (survive reboot)
# Get the UUID
blkid /dev/xvdb
# UUID=abc123...

# Add to /etc/fstab
echo "UUID=abc123 /data ext4 defaults 0 2" | sudo tee -a /etc/fstab

# Test fstab before rebooting
sudo mount -a

# Verify
df -h /data

Managing /etc/fstab

Understanding fstab entries
cat /etc/fstab
# Format: device  mountpoint  fstype  options  dump  pass
# UUID=abc123 /data      ext4    defaults 0 2
# UUID=def456 /var/log   ext4    defaults 0 2
# /dev/xvda1  /          ext4    defaults 0 1

# Options:
# defaults: rw, suid, dev, exec, auto, nouser, async
# noexec:   cannot execute binaries from this mount
# ro:       read only
# noatime:  do not update access time (performance)

# Pass field: 0=skip, 1=check first (root), 2=check after

Swap Space

Managing swap
free -h                 # Show memory and swap usage
swapon --show           # Show active swap devices

# Create a 2GB swap file
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

# Make permanent
echo "/swapfile none swap sw 0 0" | sudo tee -a /etc/fstab

# Check swappiness (0-100, lower = less aggressive)
cat /proc/sys/vm/swappiness
sudo sysctl vm.swappiness=10

Frequently Asked Questions

What causes "No space left on device" errors?

Either disk space is full (df -h shows 100% use) or inodes are exhausted (df -i shows 100% inode use). For space: find and delete large files, compress logs, clean package cache (apt clean). For inodes: find directories with many small files (du --inodes).

How do I extend an EBS volume on AWS EC2?

In AWS console, modify the EBS volume size. Then in Linux: sudo growpart /dev/xvda 1 extends the partition. sudo resize2fs /dev/xvda1 extends the filesystem (for ext4). No reboot needed. lsblk and df -h verify the new size.

What is an inode?

Every file and directory has an inode storing metadata (permissions, owner, timestamps, pointers to data blocks). Each filesystem has a fixed number of inodes. If you create millions of tiny files, you can exhaust inodes even with disk space remaining. df -i shows inode usage.

What filesystem should I use on Linux?

ext4 is the standard for most Linux servers -- stable, well-supported, good performance. xfs is better for very large files and high-throughput workloads. btrfs supports snapshots and copy-on-write. For cloud (EBS, GCS), ext4 or xfs are the standard choices.

How do I safely unmount a disk?

sudo umount /data -- Linux will refuse if anything is still using the mount. If umount fails: fuser -m /data shows which processes are using it. lsof /data shows open files. Kill those processes or move out of the directory, then unmount.

In Part 12, we cover Linux system hardening -- securing your servers against common attacks and vulnerabilities.

Key takeaways

Continue reading
Part 12 — Production Linux Practices
Server hygiene that saves you.
Suraj Ahir — author of SRJahir Tech

Written by

Suraj Ahir

Cloud & DevOps engineer running four live production services on my own AWS infrastructure. I write everything on this site myself — no ghostwriters, no AI filler.

← Part 10Linux Tutorial · Part 11 of 12Part 12 →
← Back to Blog
Disclaimer: Educational content only.

LVM: Logical Volume Management

Flexible disk management for servers
# LVM lets you resize volumes without downtime
# PV (Physical Volume) -> VG (Volume Group) -> LV (Logical Volume)

# Set up LVM on a new disk
sudo pvcreate /dev/xvdb            # Create physical volume
sudo vgcreate data-vg /dev/xvdb   # Create volume group
sudo lvcreate -L 50G -n data-lv data-vg  # Create logical volume

# Format and mount
sudo mkfs.ext4 /dev/data-vg/data-lv
sudo mount /dev/data-vg/data-lv /data

# Extend logical volume (can be done while mounted)
sudo lvextend -L +20G /dev/data-vg/data-lv
sudo resize2fs /dev/data-vg/data-lv  # Extend filesystem

# List LVM information
sudo pvs    # Physical volumes
sudo vgs    # Volume groups
sudo lvs    # Logical volumes

Disk Performance Testing

Benchmark disk performance on EC2
sudo apt install fio

# Test sequential write speed
fio --name=seqwrite --rw=write --bs=128k --size=1G     --numjobs=4 --runtime=60 --filename=/tmp/testfile

# Test random read (typical for databases)
fio --name=randread --rw=randread --bs=4k --size=1G     --numjobs=4 --runtime=60 --filename=/tmp/testfile     --iodepth=64

# Simple throughput test
dd if=/dev/zero of=/tmp/test bs=1M count=1024 oflag=direct
# Watch real-time disk I/O
iostat -xz 2  # Every 2 seconds