Storage Devices and System Performance
Summary
This chapter covers storage management and performance monitoring. You'll learn about block and character devices, mounting file systems, disk partitions, and swap space. Master performance monitoring tools like df, du, free, vmstat, and iostat to understand system resource usage and identify bottlenecks. These skills are essential for system administration.
Concepts Covered
This chapter covers the following 35 concepts from the learning graph:
- Storage Devices
- Block Devices
- Character Devices
- Device Files
- Mount Command
- Umount Command
- Fstab File
- Disk Partitions
- Fdisk Command
- Lsblk Command
- Df Command
- Du Command
- USB Drives
- Flash Drives
- Swap Space
- Swap File
- Swap Partition
- File System Types
- Ext4 File System
- NTFS Support
- System Monitoring
- CPU Usage
- Memory Usage
- Disk Usage
- Free Command
- Vmstat Command
- Iostat Command
- Sar Command
- Performance Tuning
- CPU Benchmarks
- Disk Benchmarks
- GPU Performance
- System Load
- Load Average
- Bottleneck Analysis
Prerequisites
This chapter builds on concepts from:
Welcome to the Engine Room!
Ever wondered why your computer sometimes feels slow? Or why copying files to a USB stick takes forever? Or how the new NVMe drives can be 100 times faster than an old SD card?
This chapter takes you into the engine room of Linux—where you'll learn how storage works, how to monitor system performance, and how to benchmark everything. You'll become the mechanic who can diagnose why a system is running slow and tune it for maximum performance!
Storage Devices: Where Your Data Lives
Storage devices are the hardware that stores your data persistently—it survives when you turn off the power. Understanding storage is crucial because it's often the biggest bottleneck in system performance.
Types of Storage
| Type | Speed | Cost | Use Case |
|---|---|---|---|
| NVMe SSD | Very Fast | $$ | Primary OS, databases |
| SATA SSD | Fast | $$ | General purpose |
| HDD (Spinning) | Slow | $ | Bulk storage, backups |
| MicroSD | Slow | $ | Embedded devices, Pi |
| USB Flash | Slow-Medium | $ | Portable storage |
The speed differences are DRAMATIC. An NVMe drive can be 50-100x faster than a MicroSD card!
Block Devices and Character Devices
Linux represents hardware as files in /dev. There are two main types:
Block Devices
Block devices transfer data in blocks (chunks). These are your storage devices:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
Character Devices
Character devices transfer data one character at a time. These include:
- Terminals (
/dev/tty*) - Serial ports (
/dev/ttyUSB*) - Random number generator (
/dev/random) - Null device (
/dev/null)
1 2 3 4 | |
Device Files: Everything is a File
Device files in /dev represent hardware. This is the "everything is a file" philosophy in action!
Common Device Files
| Device | Description |
|---|---|
/dev/sda |
First SATA/SCSI disk |
/dev/nvme0n1 |
First NVMe drive |
/dev/mmcblk0 |
MicroSD card |
/dev/sda1 |
First partition on sda |
/dev/null |
Discards all input |
/dev/zero |
Infinite stream of zeros |
/dev/random |
Random data |
/dev/tty |
Current terminal |
1 2 3 4 5 6 7 8 9 10 11 12 | |
The Lsblk Command: List Block Devices
The lsblk command lists all block devices in a tree format, showing partitions and mount points.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | |
Understanding lsblk Output
1 2 3 4 5 6 7 | |
- NAME: Device name
- MAJ:MIN: Major/minor device numbers
- RM: Removable (1 = yes)
- SIZE: Device size
- RO: Read-only (1 = yes)
- TYPE: disk, part, rom, etc.
- MOUNTPOINT: Where it's mounted
Disk Partitions: Dividing Storage
Disk partitions divide a physical disk into logical sections. Each partition can have its own file system.
Why Partition?
- Separate OS from data
- Multi-boot systems
- Different file systems for different needs
- Easier backups and recovery
Partition Types
| Type | Description |
|---|---|
| Primary | Main partitions (max 4 on MBR) |
| Extended | Container for logical partitions |
| Logical | Partitions inside extended |
| GPT | Modern, supports many partitions |
The Fdisk Command: Partition Manager
The fdisk command creates and manages partitions. Use carefully—wrong commands can destroy data!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | |
Backup First!
Fdisk can destroy all data on a disk. Always backup before partitioning, and triple-check you're working on the correct disk!
Modern Alternative: parted
1 2 3 4 5 6 7 8 9 10 11 | |
The Mount Command: Attach File Systems
The mount command attaches a file system to a directory, making it accessible.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | |
Mount Options
| Option | Purpose |
|---|---|
ro |
Read-only |
rw |
Read-write |
noexec |
No execution of binaries |
nosuid |
Ignore SUID bits |
uid=N |
Owner user ID |
gid=N |
Owner group ID |
umask=NNN |
Permission mask |
The Umount Command: Detach File Systems
The umount command safely detaches file systems before removing media.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | |
Always Unmount!
Removing a USB drive without unmounting can corrupt data. Always umount first!
The Fstab File: Automatic Mounting
The fstab file (/etc/fstab) defines file systems to mount at boot time.
1 2 3 4 5 6 7 8 9 | |
Fstab Fields
- Device: UUID, LABEL, or /dev path
- Mount point: Where to mount
- Type: File system type
- Options: Mount options
- Dump: Backup flag (0 or 1)
- Pass: fsck order (0, 1, or 2)
Using UUIDs (Recommended)
1 2 3 4 5 6 7 8 | |
File System Types: Formats for Storage
File system types determine how data is organized on storage.
Common Linux File Systems
| Type | Description | Best For |
|---|---|---|
| ext4 | Linux standard | General purpose |
| xfs | High performance | Large files, servers |
| btrfs | Modern, snapshots | Advanced users |
| f2fs | Flash-optimized | SSDs, SD cards |
| ntfs | Windows | Sharing with Windows |
| exfat | Universal | USB drives, cross-platform |
| fat32 | Legacy | Boot partitions, old devices |
The Ext4 File System
The ext4 file system is the default for most Linux distributions. It's reliable, fast, and well-tested.
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
Ext4 Features
- Journaling (crash recovery)
- Up to 16TB file size
- Up to 1EB volume size
- Extents (efficient large files)
- Backward compatible with ext3
NTFS Support: Windows Compatibility
NTFS support lets you read and write Windows drives.
1 2 3 4 5 6 7 8 | |
USB Drives and Flash Drives
USB drives and flash drives are plug-and-play storage devices. Modern Linux auto-mounts them.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
Swap Space: Virtual Memory
Swap space extends RAM using disk storage. When RAM fills up, inactive pages move to swap.
Check Swap
1 2 3 4 5 6 | |
Swap File: File-Based Swap
A swap file is a regular file used as swap space. Flexible and easy to resize!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | |
Swap Partition
A swap partition is a dedicated partition for swap. Traditional but less flexible.
1 2 3 4 5 6 7 | |
The Df Command: Disk Free Space
The df command shows disk space usage for mounted file systems.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | |
Reading df Output
1 2 3 4 | |
Watch for Full Disks
Systems can crash when disks hit 100%. Monitor with df -h and set up alerts for 80%+ usage.
The Du Command: Disk Usage
The du command shows how much space files and directories use.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | |
Finding Space Hogs
1 2 3 4 5 6 7 8 9 | |
System Monitoring: Watch Your Resources
System monitoring tracks CPU, memory, disk, and network usage to identify problems.
Quick System Overview
1 2 3 4 5 6 7 8 | |
CPU Usage: Processing Power
CPU usage shows how busy your processor is.
1 2 3 4 5 6 7 8 9 10 11 12 | |
Understanding CPU Metrics
| Metric | Meaning |
|---|---|
| us | User space (your programs) |
| sy | System/kernel |
| ni | Nice (low priority) |
| id | Idle (unused) |
| wa | I/O wait (waiting for disk) |
| hi | Hardware interrupts |
| si | Software interrupts |
| st | Steal (virtualization) |
High wa (I/O wait) means your disk is the bottleneck!
Memory Usage: RAM Status
Memory usage shows how RAM is being used.
1 2 3 4 5 6 7 | |
Understanding Memory
- total: Physical RAM
- used: Currently in use
- free: Completely unused
- buff/cache: Disk cache (available if needed)
- available: Actually available for programs
Free Memory Isn't Wasted
Linux uses "free" RAM for disk caching. Look at "available", not "free"!
The Free Command: Memory Details
The free command shows memory and swap usage.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | |
The Vmstat Command: Virtual Memory Stats
The vmstat command shows memory, swap, I/O, and CPU statistics.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
Understanding vmstat Output
1 2 3 | |
| Column | Meaning |
|---|---|
| r | Processes waiting for CPU |
| b | Processes in uninterruptible sleep |
| swpd | Virtual memory used |
| free | Idle memory |
| si/so | Swap in/out (bad if high!) |
| bi/bo | Blocks read/written to disk |
| us/sy/id/wa | CPU percentages |
The Iostat Command: I/O Statistics
The iostat command shows disk I/O statistics—essential for storage analysis!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | |
Reading iostat Output
1 2 3 | |
| Metric | Meaning |
|---|---|
| r/s, w/s | Reads/writes per second |
| rkB/s, wkB/s | KB read/written per second |
| await | Average I/O wait time (ms) |
| %util | Percentage of time device is busy |
%util near 100% = disk is saturated (bottleneck!)
The Sar Command: System Activity Reporter
The sar command collects and reports system activity data over time. Great for historical analysis!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | |
Enable sar Data Collection
1 2 3 4 5 6 7 8 9 10 | |
System Load and Load Average
System load measures how busy the system is. Load average shows the load over 1, 5, and 15 minutes.
1 2 3 4 5 6 7 8 9 10 | |
Understanding Load Average
- Load = 1.0 means one CPU core is 100% busy
- Load < cores = system can handle more
- Load > cores = system is overloaded
On a 4-core system: - 1.0 = 25% utilized - 4.0 = 100% utilized (all cores busy) - 8.0 = 200% load (processes waiting)
Bottleneck Analysis: Finding the Slow Part
Bottleneck analysis identifies what's limiting your system's performance.
The Three Main Bottlenecks
| Bottleneck | Symptoms | Check With |
|---|---|---|
| CPU | High load, low idle% | top, htop, mpstat |
| Memory | Swap usage, OOM killer | free, vmstat (si/so) |
| Disk I/O | High iowait, slow operations | iostat (%util, await) |
Quick Bottleneck Detection
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | |
Disk Benchmarks: Measuring Speed
Disk benchmarks measure how fast your storage actually is. This is where things get fun!
Benchmarking Tools
| Tool | Purpose | Complexity |
|---|---|---|
time |
Simple timing | Easy |
dd |
Basic throughput | Easy |
hdparm |
Read speed | Easy |
fio |
Full I/O testing | Advanced |
ioping |
I/O latency | Easy |
bonnie++ |
Comprehensive | Medium |
sysbench |
CPU, memory, I/O | Medium |
The Time Command: Simple Timing
The time command measures how long a command takes to run.
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
Understanding Time Output
- real: Actual elapsed time (includes waiting for I/O)
- user: CPU time executing your code
- sys: CPU time in kernel operations
If real >> user + sys, you're waiting for I/O!
The Dd Command: Raw Disk Speed
The dd command can measure raw read/write speed. It's basic but universally available.
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
Important dd Flags
| Flag | Purpose |
|---|---|
bs=SIZE |
Block size (4K, 1M, 1G) |
count=N |
Number of blocks |
oflag=direct |
Bypass cache (real disk speed) |
iflag=direct |
Direct read (bypass cache) |
conv=fdatasync |
Ensure data is written |
dd Can Destroy Data
Be VERY careful with dd! of=/dev/sda will wipe your disk!
The Hdparm Command: Drive Info and Testing
The hdparm command reads drive information and tests read speed.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | |
The -t (buffered) result is what matters for actual disk speed!
The Fio Command: Flexible I/O Tester
The fio command is the most powerful I/O benchmarking tool. It can simulate almost any workload.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | |
Key fio Metrics
| Metric | Meaning |
|---|---|
| IOPS | I/O Operations Per Second |
| BW | Bandwidth (throughput) |
| lat | Latency (response time) |
| slat | Submission latency |
| clat | Completion latency |
The Ioping Command: I/O Latency
The ioping command measures I/O latency—how quickly the disk responds to requests.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | |
Output Example
1 2 3 4 5 6 | |
Low latency = responsive disk. NVMe drives have latency under 0.1ms!
The Bonnie++ Command: Comprehensive Testing
The bonnie++ command runs a comprehensive suite of I/O tests.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
Bonnie++ tests: - Sequential read/write - Random seeks - File creation/deletion
The Sysbench Command: Multi-Purpose Benchmarking
The sysbench command benchmarks CPU, memory, and disk I/O.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | |
CPU Benchmarks: Testing Processing Power
CPU benchmarks measure raw computing power.
1 2 3 4 5 6 7 8 9 10 11 | |
GPU Performance: Graphics Processing
GPU performance matters for graphics, machine learning, and video processing.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | |
Performance Tuning: Making It Faster
Performance tuning optimizes system settings for better performance.
Quick Tuning Tips
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
Case Study: Raspberry Pi 5 NVMe Performance
Here's the exciting part! The Raspberry Pi 5 introduced PCIe support, allowing you to connect NVMe SSDs. The performance difference compared to MicroSD is INCREDIBLE!
The Hardware Setup
| Storage Type | Interface | Theoretical Max |
|---|---|---|
| MicroSD (A2) | SD 3.0 | ~100 MB/s |
| USB 3.0 SSD | USB 3.0 | ~400 MB/s |
| NVMe SSD | PCIe 2.0 x1 | ~450 MB/s |
The Pi 5's PCIe is limited to gen 2 x1, but that's still MUCH faster than SD!
Benchmark Comparison Script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
Real-World Results
Typical results comparing storage on Raspberry Pi 5:
| Metric | MicroSD | USB 3.0 SSD | NVMe SSD |
|---|---|---|---|
| Sequential Read | 45 MB/s | 350 MB/s | 450 MB/s |
| Sequential Write | 30 MB/s | 300 MB/s | 400 MB/s |
| Random 4K Read | 2,500 IOPS | 25,000 IOPS | 50,000 IOPS |
| Random 4K Write | 1,500 IOPS | 20,000 IOPS | 45,000 IOPS |
| I/O Latency | 3-10 ms | 0.3-0.5 ms | 0.1-0.2 ms |
The NVMe drive is 10-20x faster for random I/O!
This makes a HUGE difference for: - Boot time (10 seconds vs 40 seconds) - Database performance - Compilation speed - Application responsiveness
Setting Up NVMe on Raspberry Pi 5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | |
Boot from NVMe
To boot your Pi 5 from NVMe (maximum speed!):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
Why Such a Big Difference?
| Factor | MicroSD | NVMe |
|---|---|---|
| Interface | Serial (SD bus) | Parallel (PCIe) |
| Queue Depth | 1 command | 65,535 commands |
| Latency | 3-10 ms | 0.05-0.1 ms |
| IOPS | 2,000-5,000 | 50,000-100,000 |
NVMe can handle many operations simultaneously (parallelism), while SD cards process commands one at a time!
Quick Reference: Storage and Performance
Storage Commands
| Task | Command |
|---|---|
| List disks | lsblk |
| Disk info | sudo fdisk -l |
| Mount device | sudo mount /dev/sdb1 /mnt/usb |
| Unmount | sudo umount /mnt/usb |
| Check space | df -h |
| Check usage | du -sh * |
Monitoring Commands
| Task | Command |
|---|---|
| Memory | free -h |
| CPU + processes | top or htop |
| I/O stats | iostat -x 2 |
| System activity | vmstat 2 |
| Load average | uptime |
Benchmark Commands
| Task | Command |
|---|---|
| Time command | time command |
| Disk speed | dd if=/dev/zero of=test bs=1M count=1024 oflag=direct |
| Read speed | sudo hdparm -t /dev/sda |
| I/O latency | ioping /dev/sda |
| Full benchmark | fio --name=test --rw=read --size=1G |
Key Takeaways
You're now a storage and performance expert!
- Block devices: Storage as files in /dev
- Mount/umount: Attaching file systems
- fstab: Automatic mounting at boot
- df/du: Space usage monitoring
- vmstat/iostat: System performance stats
- Benchmarking: time, dd, hdparm, fio, ioping
- NVMe >> SD: 10-100x faster for random I/O!
Performance Detective!
You can now diagnose why systems are slow, identify bottlenecks, and prove that NVMe is worth every penny on your Raspberry Pi 5!
What's Next?
Now you understand storage and performance, you're ready to explore the Raspberry Pi in depth! The next chapter covers setting up and configuring your Pi for all kinds of projects.
Quick Quiz: Storage and Performance
- What command shows disk space usage for mounted file systems?
- How do you mount a USB drive to /mnt/usb?
- What does high I/O wait (wa%) indicate?
- Which tool measures I/O latency?
- What makes NVMe faster than MicroSD?
- How do you safely remove a USB drive?
- What file configures automatic mounting at boot?
Quiz Answers
df -hsudo mount /dev/sdb1 /mnt/usb- The disk is the bottleneck - processes are waiting for I/O
ioping(also fio shows latency)- PCIe interface with parallel commands, deep queue depth, and low latency
sudo umount /mnt/usbthen physically remove/etc/fstab
References
- Linux Filesystem Hierarchy - Official Filesystem Hierarchy Standard documentation
- ext4 Filesystem Guide - Kernel.org wiki on ext4 filesystem
- fstab Configuration - Ubuntu community guide to /etc/fstab configuration
- df and du Commands - Checking disk space usage on Linux
- Mount Command Tutorial - Comprehensive mount command examples
- lsblk Command Guide - Red Hat guide to listing block devices
- iostat Performance Monitoring - Using iostat to monitor I/O statistics
- vmstat Tutorial - Virtual memory statistics monitoring
- free Command Explained - Understanding Linux memory usage with free
- Swap Space Management - Creating and managing swap files
- fio Benchmarking Guide - Official fio flexible I/O tester documentation
- hdparm Disk Testing - Benchmarking disk performance with hdparm
- NVMe vs SATA Performance - Understanding SSD interface differences
- Raspberry Pi 5 PCIe Setup - Official Pi 5 documentation for NVMe
- System Performance Tuning - Kernel virtual memory tuning parameters
- Block Device Concepts - Kernel documentation on block devices
- ioping Latency Testing - GitHub repository and documentation for ioping
- sysbench Benchmarking - Scriptable database and system performance benchmark
- Understanding Load Average - Brendan Gregg's deep dive into load averages
- Bottleneck Analysis Guide - Red Hat guide to identifying performance bottlenecks