OS Notes
Linux file systems — ext4 architecture, inodes, journaling, directory hierarchy (FHS), other file systems (XFS, Btrfs, ZFS), mounting, and file system management commands.
Introduction
The file system is how the operating system organizes data on storage devices — transforming raw disk blocks into the familiar hierarchy of files and directories. Linux supports dozens of file systems, each designed for different use cases. Understanding file system internals helps you choose the right one for your workload, troubleshoot performance issues, and recover from data corruption.
The beauty of Linux is the VFS (Virtual File System) layer — it provides a uniform interface so that applications use the same system calls (open, read, write) regardless of whether the underlying storage is ext4, XFS, NFS, or even a virtual filesystem like /proc.
Linux Directory Hierarchy (FHS)
The Filesystem Hierarchy Standard defines where everything lives:
ext4 — The Default Linux File System
ext4 (Fourth Extended Filesystem) is the most widely used Linux file system. It evolved from ext2 → ext3 → ext4, gaining journaling, larger volume support, and better performance with each generation.
Key Features
- Maximum file size: 16 TB
- Maximum volume size: 1 EB (exabyte)
- Journaling: Crash recovery without full fsck
- Extents: Efficient storage for large files (contiguous block ranges)
- Delayed allocation: Better block placement decisions
- Backward compatible: Can mount ext3/ext2 volumes
Inode Structure
Every file and directory is represented by an inode containing metadata:
| │ ├── 1 single indirect pointer ( | block of pointers → data) |
| │ ├── 1 double indirect pointer ( | block → block of ptrs → data) |
| │ └── 1 triple indirect pointer ( | block → block → block → data) |
Important: The filename is NOT stored in the inode. It is stored in the parent directory's data blocks as a (name, inode_number) pair. This is why:
- Hard links work (multiple names → same inode)
- Renaming is instant (change directory entry, not file data)
ls -ishows inode numbers
Journaling
ext4 uses a journal to prevent file system corruption after crashes:
Without journaling
1. Start writing file metadata
2. CRASH mid-write
3. File system in inconsistent state
4. Full fsck required (can take hours on large volumes)
With journaling
1. Write intended changes to journal
2. Apply changes to actual file system
3. Mark journal entry as complete
4. CRASH at any point →
On recovery: replay complete journal entries, discard incomplete ones
Fast recovery in seconds
Journal modes:
journal: Both metadata AND data journaled (safest, slowest)ordered(default): Only metadata journaled, but data written before metadata (good balance)writeback: Only metadata journaled, data may be written in any order (fastest, riskier)
Other Linux File Systems
XFS
Developed by SGI for large files and high-throughput workloads:
- Excellent for large files (video editing, databases)
- Parallel I/O with allocation groups (each AG is independently managed)
- Cannot be shrunk (only grown) — major limitation
- Default on RHEL/CentOS since version 7
mkfs.xfs /dev/sdb1
mount /dev/sdb1 /data
xfs_growfs /data # Expand to fill partitionBtrfs (B-tree File System)
Modern copy-on-write file system with advanced features:
- Snapshots: Instant point-in-time copies (zero initial space)
- Subvolumes: Independent file system namespaces within one partition
- Built-in RAID: Software RAID 0, 1, 5, 6, 10
- Checksums: Detects silent data corruption (bit rot)
- Compression: Transparent compression (zstd, lzo, zlib)
mkfs.btrfs /dev/sdb1
# Create subvolume
btrfs subvolume create /mnt/data/@home
# Take snapshot
btrfs subvolume snapshot /mnt/data/@home /mnt/data/@home_backup
# Enable compression
mount -o compress=zstd /dev/sdb1 /mnt/dataZFS
Originally from Sun Solaris, now available on Linux (via module):
- Combined volume manager + file system
- Strong data integrity (checksums on all data and metadata)
- Copy-on-write (never overwrites data in place)
- Built-in compression, deduplication, encryption
- Snapshot and clone capabilities
# Create pool from multiple disks
zpool create mypool mirror /dev/sdb /dev/sdc
# Create dataset (like a filesystem)
zfs create mypool/data
# Snapshot
zfs snapshot mypool/data@today
# Enable compression
zfs set compression=lz4 mypool/datatmpfs
RAM-based file system for temporary data:
mount -t tmpfs -o size=2G tmpfs /tmp
# Files in /tmp stored in RAM — extremely fast, lost on rebootFile System Operations
# Create file system
mkfs.ext4 /dev/sdb1
mkfs.xfs /dev/sdb1
# Mount
mount /dev/sdb1 /mnt/data
mount -t nfs server:/share /mnt/nfs # Network mount
# Persistent mount (/etc/fstab)
/dev/sdb1 /data ext4 defaults 0 2
# Check and repair
fsck /dev/sdb1 # Check (must be unmounted!)
e2fsck -f /dev/sdb1 # Force check ext4
# View file system info
df -hT # Disk usage with filesystem types
tune2fs -l /dev/sdb1 # ext4 superblock information
stat file.txt # Inode details for a fileFile System Comparison
| Feature | ext4 | XFS | Btrfs | ZFS |
|---|---|---|---|---|
| Max file size | 16 TB | 8 EB | 16 EB | 16 EB |
| Journaling | Yes | Yes | CoW | CoW |
| Snapshots | No | No | Yes | Yes |
| Checksums | Metadata only | No | Yes | Yes |
| Compression | No | No | Yes | Yes |
| Shrink volume | Yes | No | Yes | No |
| Maturity | Very mature | Mature | Maturing | Very mature |
| Best for | General purpose | Large files | Flexible storage | Data integrity |
Key Takeaways
- Linux VFS provides a uniform interface over diverse file systems
- ext4 is the reliable default — journaling, extents, good performance for most workloads
- XFS excels for large files and high-throughput scenarios
- Btrfs and ZFS offer modern features (snapshots, checksums, compression) for advanced needs
- Inodes store metadata; directory entries store name-to-inode mappings
- Journaling prevents corruption after crashes — recovery takes seconds instead of hours
- Choose file system based on workload: general purpose (ext4), large files (XFS), advanced features (Btrfs/ZFS)
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Linux File System - ext4 and others.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Operating Systems topic.
Search Terms
operating-systems, operating systems, operating, systems, linux, and, unix, file
Related Operating Systems Topics