Disk Management
Learn how Linux interacts with storage devices, how disks and filesystems work, and how Linux mounts and manages storage.
Difficulty: Beginner
Estimated reading time: 80 min
Introduction
Every Linux system relies on storage.
Whether it is:
- a laptop
- a cloud server
- a Docker host
- a Kubernetes node
- a NAS
- a VPS
Linux constantly interacts with disks.
Understanding disk management is extremely important because many real-world Linux problems involve:
- full disks
- corrupted filesystems
- missing mounts
- failed drives
- partitioning mistakes
- storage permissions
For DevOps and infrastructure work, storage knowledge becomes critical.
Especially when working with:
- databases
- containers
- backups
- cloud volumes
- persistent storage
Linux storage management is very powerful, but initially it can feel confusing.
This chapter explains the entire process step-by-step.
Understanding Storage Basics
What Is a Disk?
A disk is a storage device.
Examples:
- SSD
- HDD
- NVMe drive
- USB flash drive
- cloud volume
Linux treats these devices as block devices.
What Is a Block Device?
A block device stores data in blocks.
Linux exposes disks through:
/dev
Example devices:
| Device | Meaning |
|---|---|
/dev/sda |
First SATA disk |
/dev/sdb |
Second SATA disk |
/dev/nvme0n1 |
NVMe drive |
/dev/loop0 |
Loop device |
Understanding Partitions
What Is a Partition?
A partition divides a physical disk into logical sections.
Example:
Disk
├── Partition 1
├── Partition 2
└── Partition 3
Each partition can contain:
- a filesystem
- swap
- another operating system
Why Partitions Exist
Partitions help separate data.
Examples:
| Partition | Purpose |
|---|---|
/ |
Root filesystem |
/home |
User files |
swap |
Virtual memory |
/boot |
Bootloader files |
This improves:
- organization
- security
- recovery
- flexibility
Listing Disks
lsblk
One of the most important storage commands:
lsblk
Example output:
sda
├── sda1
├── sda2
└── sda3
Breakdown:
| Item | Meaning |
|---|---|
sda |
Physical disk |
sda1 |
Partition 1 |
sda2 |
Partition 2 |
Better Output
lsblk -f
Displays:
- filesystems
- UUIDs
- mount points
Very useful in real systems.
Viewing Disk Usage
df
Display filesystem usage:
df -h
| Option | Meaning |
|---|---|
-h |
Human-readable sizes |
Example:
Filesystem Size Used Avail Use%
/dev/sda1 50G 20G 28G 42%
Understanding df
df shows:
- mounted filesystems
- used space
- free space
Very important for troubleshooting.
Finding Large Directories
du
Disk usage by directory:
du -sh /var/log
| Option | Meaning |
|---|---|
-s |
Summary |
-h |
Human-readable |
Analyze Large Directories
du -sh /*
Very common during disk cleanup.
Understanding Filesystems
What Is a Filesystem?
A filesystem organizes data on disks.
Without a filesystem:
Linux cannot store files properly.
Examples of filesystems:
| Filesystem | Description |
|---|---|
| ext4 | Most common Linux filesystem |
| xfs | Popular on servers |
| btrfs | Advanced modern filesystem |
| FAT32 | Windows-compatible |
| NTFS | Windows filesystem |
ext4
Most common Linux filesystem.
Reliable and stable.
Used by many Linux distributions.
Creating Filesystems
mkfs
Create filesystem:
sudo mkfs.ext4 /dev/sdb1
Meaning:
Create ext4 filesystem on partition
WARNING
Formatting destroys data.
Always verify device names carefully.
Wrong device selection can wipe disks.
Mounting Filesystems
What Is Mounting?
Linux does not automatically expose disks directly.
A filesystem must be:
Mounted into the directory tree.
Example:
Disk partition
↓
Mounted to:
/mnt/storage
Manual Mount
Example:
sudo mount /dev/sdb1 /mnt
Now filesystem contents appear inside:
/mnt
Verify Mounts
mount
or:
lsblk
Unmounting
umount
Remove filesystem mount:
sudo umount /mnt
Important:
umount
not:
unmount
Why Unmounting Matters
Unmounting ensures:
- data flushes correctly
- filesystem remains consistent
- corruption risk decreases
Very important for USB drives.
Persistent Mounts
The /etc/fstab File
Linux stores permanent mount configurations inside:
/etc/fstab
Example:
UUID=abc123 /data ext4 defaults 0 2
Understanding fstab
| Field | Meaning |
|---|---|
| Device | Disk or UUID |
| Mount point | Directory |
| Filesystem | ext4, xfs, etc |
| Options | Mount behavior |
Why UUIDs Matter
Device names can change:
/dev/sda
/dev/sdb
UUIDs are stable identifiers.
View UUIDs:
blkid
Swap Space
What Is Swap?
Swap is disk space used as virtual memory.
When RAM fills up:
Linux may move inactive memory pages to disk
View Swap
swapon --show
or:
free -h
Why Swap Exists
Swap helps:
- prevent crashes
- handle memory spikes
- support hibernation
Though modern systems rely more heavily on RAM.
Understanding Inodes
Filesystem Metadata
Linux filesystems use:
inodes
to track file metadata.
Each file consumes:
- inode
- storage blocks
Inode Problems
Sometimes disks appear free but cannot create files.
Cause:
inode exhaustion
Check:
df -i
Disk Health
SMART Monitoring
Disks expose health information through SMART.
Install tools:
sudo apt install smartmontools
Check health:
sudo smartctl -a /dev/sda
Useful for detecting failing drives.
Finding Open Files
lsof
List open files:
lsof
Example:
lsof /var/log/syslog
Useful when:
- unmounting fails
- files remain locked
Common Storage Problems
Disk Full
Check:
df -h
Usually caused by:
- logs
- backups
- Docker images
- large databases
Mount Fails
Possible causes:
- wrong filesystem
- corrupted partition
- incorrect fstab entry
Permission Problems
Mounted disks may have ownership issues.
Fix using:
chown
chmod
Real-World Example
Adding New Storage to a Server
Typical workflow:
Step 1 — Detect Disk
lsblk
Step 2 — Create Filesystem
sudo mkfs.ext4 /dev/sdb1
Step 3 — Create Mount Point
sudo mkdir /data
Step 4 — Mount Disk
sudo mount /dev/sdb1 /data
Step 5 — Configure Persistent Mount
Edit:
sudo vim /etc/fstab
Add:
UUID=abc123 /data ext4 defaults 0 2
This resembles real infrastructure administration.
Docker and Storage
Containers and Volumes
Docker heavily relies on Linux storage concepts.
Examples:
- bind mounts
- Docker volumes
- overlay filesystems
Understanding Linux mounts makes Docker much easier to understand.
Example
docker run -v /data:/app/data nginx
This uses Linux mount concepts internally.
Cloud Infrastructure and Storage
Cloud Volumes
Cloud providers expose disks similarly:
| Cloud Provider | Storage |
|---|---|
| AWS | EBS |
| Azure | Managed Disks |
| GCP | Persistent Disks |
Linux still manages them using:
- partitions
- filesystems
- mounts
Same concepts everywhere.
Linux Philosophy and Storage
Linux storage management reflects Unix philosophy:
- everything represented as files
- flexible filesystem hierarchy
- modular design
- explicit mounting
This flexibility is one reason Linux became dominant in servers and cloud infrastructure.
The Bigger Picture
Once you understand Linux storage management, many mysterious system behaviors start making sense.
You begin understanding:
- how disks integrate into Linux
- how filesystems organize data
- how servers manage storage
- how containers persist data
- how cloud infrastructure handles volumes
Storage is one of the foundations of infrastructure engineering.
What Comes Next
In the next chapter, we will explore:
- cron jobs
- task scheduling
- recurring automation
- background jobs
- timers
- automated Linux workflows
This is where Linux systems start automating themselves.