Linux Storage
Linux storage spans the full stack from physical block devices through partition tables, filesystems, and the Virtual Filesystem Switch (VFS) to application-level syscalls. Mastery of this stack is essential for tuning databases, container runtimes, and high-throughput services where I/O is the bottleneck.
Overview
Overview Linux presents storage to applications through a deep software stack that begins at the physical block device and surfaces to userspace as familiar POSIX file operations. Understanding the full path — block device, partition, filesystem, VFS, page cache, syscall — is critical for any engineer who needs to reason about performance, durability, or capacity on Linux systems.
The Virtual Filesystem Switch (VFS) is the kernel's unifying abstraction. It defines a common set of in-memory objects (superblock, inode, dentry, file) and function pointer tables (inode_operations, file_operations, address_space_operations) that every filesystem must implement. This design allows ext4, XFS, btrfs, tmpfs, and network filesystems to coexist and be mounted at different points in a single directory tree without the application caring which is which.
ext4 is the default filesystem on most Linux distributions. It extended the original ext2/3 design with extents (contiguous block ranges that replace indirect-block trees, dramatically reducing metadata for large files), a journal for crash consistency via the JBD2 layer, and delayed allocation (also called allocate-on-flush) to improve contiguity. Its three journal modes trade durability for performance: ordered mode protects against metadata corruption after a crash; writeback mode maximizes throughput; full data journaling provides the strongest guarantee.
XFS was designed by SGI for high-concurrency, large-file workloads. It partitions the disk into allocation groups that each have their own inode allocator and free-space B-trees, allowing multiple threads to allocate simultaneously without a global lock. XFS pioneered delayed allocation and supports reflink (shared data extents, enabling instant CoW copies), sparse files, and direct I/O for database use cases. It does not support shrinking, and its lack of data journaling makes fsync-heavy workloads depend entirely on correct barrier ordering.
btrfs brings copy-on-write semantics to the filesystem layer. Every write goes to a new location, so the old version remains intact until a transaction commits. This enables atomic snapshots (a snapshot captures the B-tree root at a point in time in microseconds), subvolumes (independent filesystem trees within one btrfs pool), online defragmentation, and checksumming of both data and metadata. The CoW design also means that fragmentation grows over time on update-heavy workloads, and the recommended use case today is read-heavy or snapshot-heavy environments rather than high-IOPS databases.
LVM, md RAID, and overlay filesystems sit between raw block devices and the filesystem layer. LVM adds logical indirection: physical volumes are pooled into a volume group, and logical volumes are carved out on demand, with online resize, snapshots, thin provisioning, and live migration (pvmove) available. md provides software RAID, with RAID 1 for pure mirroring, RAID 5/6 for parity-based redundancy, and RAID 10 for the combined throughput and redundancy sweet spot.
A small LVM layout shows the indirection at work. Two physical disks, /dev/sdb and /dev/sdc, each become a physical volume with pvcreate /dev/sdb and pvcreate /dev/sdc. Then vgcreate data-vg /dev/sdb /dev/sdc combines them into one volume group, a single pool. From that pool, lvcreate -L 100G carves a logical volume named data, which is formatted with mkfs.xfs /dev/data-vg/data and mounted at /data. A second lvcreate -L 20G carves one named logs, formatted with mkfs.ext4 and mounted at /var/log. Later, lvcreate --snapshot takes a snapshot of data. The snapshot works by copy-on-write, and it serves for backup or rollback.
overlayfs layers two directory trees (lower read-only, upper read-write) into a unified mount, which is the mechanism Docker uses to implement image layers and container writable layers efficiently without copying. A container image is a stack of read-only layers: for example, layer 1 holds the base OS, layer 2 the runtime and layer 3 the app code. The overlayfs mount takes those image layers as its lowerdir, adds a writable upperdir, and uses a workdir to stage copy-on-write. The running container writes only to the upperdir and sees the union view through VFS. Removing the container discards the upper layer, and the image layers stay as they were.
Key concepts
- ext4 Journal Modes and Inode Structure
- XFS Allocation Groups and Delayed Allocation
- btrfs Copy-on-Write, Subvolumes, and Snapshots
- LVM: Physical Volumes, Volume Groups, Logical Volumes, and Thin Provisioning
- mdadm Software RAID
- overlayfs, bind mounts, and tmpfs
- /etc/fstab Options, UUIDs, and Mount Flags
Interview questions
- Walk me through the full path of a write() system call from the application to the physical disk, including where data can be lost on a crash at each step.
- When would you choose XFS over ext4 for a database server, and what specific mount and filesystem options would you configure?
- What are the risks of LVM thin provisioning in production, and how do you mitigate them?
- How does overlayfs work, and how does Docker use it to implement image layers and container storage?
- Why might df and du report different values for the same directory, and how do you diagnose and resolve each cause?
Sign up free to read the full topic
More Linux topics
Start free on Cariara · Coding problems · System design studio