Skip to content

Linux File Systems

This chapter covers Linux file systems - types, characteristics, and how to choose the right one for your needs.


File system knowledge is critical for DevOps and SRE engineers. Proper file system selection, monitoring, and management directly impacts application performance, data reliability, and system uptime. Understanding file systems helps you make informed decisions about storage, backup strategies, and capacity planning.

┌─────────────────────────────────────────────────────────────────────────────┐
│ FILE SYSTEMS IN DEVOPS │
├─────────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ OPERATIONAL IMPACT │ │
│ │ │ │
│ │ • Application Performance - FS choice affects I/O throughput │ │
│ │ • Data Reliability - Journaling prevents corruption │ │
│ │ • Capacity Planning - Monitor usage to prevent disk exhaustion │ │
│ │ • Backup Strategy - Understanding FS structure for restores │ │
│ │ • Incident Response - Disk issues cause most production outages │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────────────────┘ │
│ │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ DEVOPS TASKS │ │
│ │ │ │
│ │ • Select appropriate filesystem for workloads │ │
│ │ • Configure monitoring alerts for disk usage │ │
│ │ • Implement proper backup and recovery procedures │ │
│ │ • Set up disk quotas for multi-user environments │ │
│ │ • Configure encryption for sensitive data │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────────────────┘ │
│ │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ COMMON INCIDENTS │ │
│ │ │ │
│ │ • Disk full - Application crashes, log failures │ │
│ │ • Filesystem corruption - Service downtime │ │
│ │ • Inode exhaustion - Even with free disk space │ │
│ │ • Permission issues - Application access denied │ │
│ │ • NFS mount hangs - Network storage problems │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────────┘

Linux supports numerous file systems, each with different characteristics and use cases.

+------------------------------------------------------------------+
| Linux File System Types |
+------------------------------------------------------------------+
File Systems
|
+---------------------+---------------------+
| | |
v v v
+----------+ +----------+ +----------+
| Native | | Journaling| | Network |
| Linux FS | | FS | | FS |
+----------+ +----------+ +----------+
| | |
v v v
+----------+ +----------+ +----------+
| ext2 | | ext3 | | NFS |
| ext4 | | ext4 | | CIFS/SMB|
| btrfs | | xfs | | sshfs |
| xfs | | jfs | | |
| jfs | | reiserfs | | |
+----------+ +----------+ +----------+
File SystemTypeJournalMax File SizeMax Volume
ext2NativeNo2TB4TB
ext3NativeYes2TB4TB
ext4NativeYes16TB1EB
xfsNativeYes8EB8EB
btrfsNativeYes16EB16EB
jfsNativeYes8PB8PB
reiserfsNativeYes8TB16TB
File SystemProtocolUse Case
NFSTCP/UDPUnix/Linux file sharing
CIFS/SMBSMBWindows file sharing
sshfsSSHSecure remote mounting
+------------------------------------------------------------------+
| Btrfs Features |
+------------------------------------------------------------------+
+-------------+
| Btrfs |
| (Modern) |
+-------------+
|
+---------------------+---------------------+
| | |
v v v
+----------+ +----------+ +----------+
| Snapshots| | Copy on | | Data |
| & Clones | | Write | | Compression |
+----------+ +----------+ +----------+
| | |
+---------------------+---------------------+
|
+---------------------+---------------------+
| | |
v v v
+----------+ +----------+ +----------+
| RAID | | Online | | Subvolumes |
| Support | | FS Check| | & Quotas |
+----------+ +----------+ +----------+
+------------------------------------------------------------------+
| Feature | Description |
+----------------------+---------------------------------------------+
| Snapshots | Point-in-time copies of filesystem |
| Copy-on-Write | Efficient cloning, no data duplication |
| Compression | Transparent zstd/zlib compression |
| RAID Support | Native RAID 0,1,5,6,10 support |
| Online FS Check | fsck while mounted (scrub) |
| Subvolumes | Separate mountable filesystem trees |
| Quotas | Group-based quota support |
| Deduplication | Block-level deduplication (optional) |
| Encryption | Native fs-level encryption (experimental) |
+----------------------+--------------------------------------------+
+------------------------------------------------------------------+
| File System Selection Guide |
+------------------------------------------------------------------+
Workload Type Recommended FS Reason
+----------------------+ +-------------+ +-------------------+
| General purpose | | ext4 | | Widely supported |
+----------------------+ +-------------+ +-------------------+
| Large files/db | | xfs | | High performance |
+----------------------+ +-------------+ +-------------------+
| Modern features | | btrfs | | Snapshots, etc |
+----------------------+ +-------------+ +-------------------+
| Network sharing | | nfs | | Standard protocol |
+----------------------+ +-------------+ +-------------------+
| Windows sharing | | cifs/smb | | Native to Windows |
+----------------------+ +-------------+ +-------------------+
  • ext4: Best for general purpose use, widely supported
  • xfs: Excellent for large files and high-performance workloads
  • btrfs: Modern features like snapshots, compression, deduplication
  • xfs: Ideal for databases and large file storage
  • NFS: Network file sharing in enterprise environments

+------------------------------------------------------------------+
| Creating File Systems |
+------------------------------------------------------------------+
Physical Disk Format Mount
+----------+ +----------+ +----------+
| /dev/sdb1|---------->| mkfs.ext4|---------->| /mnt/data|
+----------+ +----------+ +----------+
Commands:
+----------------------------------------------------------+
| mkfs.ext4 /dev/sdb1 - Create ext4 FS |
| mkfs.xfs /dev/sdb1 - Create xfs FS |
| mkfs.btrfs /dev/sdb1 - Create btrfs FS |
| mkfs.ext4 -L "data" /dev/sdb1 - With label |
+----------------------------------------------------------+
Terminal window
# Create ext4 file system
mkfs.ext4 /dev/sdb1
# Create xfs file system
mkfs.xfs /dev/sdb1
# Create btrfs file system
mkfs.btrfs /dev/sdb1
# With specific options
mkfs.ext4 -L "data" -m 0 /dev/sdb1
Terminal window
# Check ext file system (read-only recommended)
fsck.ext4 /dev/sdb1
# Check xfs file system
xfs_repair /dev/sdb1
# Check btrfs file system
btrfs check /dev/sdb1
+------------------------------------------------------------------+
| Mount Process |
+------------------------------------------------------------------+
Device Mount Point File System
+--------+ +----------+ +----------+
|/dev/sdb1| -------->| /mnt/data| -------->| ext4 |
+--------+ +----------+ +----------+
Options: rw, ro, noexec, nosuid, nodev, sync, async
Terminal window
# Mount temporarily
mount /dev/sdb1 /mnt/data
# Mount with specific options
mount -o rw,noexec,nosuid /dev/sdb1 /mnt/data
# View mount options
mount | grep /dev/sdb1
# Unmount
umount /mnt/data
# <file system> <mount point> <type> <options> <dump> <pass>
/dev/sdb1 /mnt/data ext4 defaults 0 2
LABEL=data /mnt/data ext4 defaults 0 2
UUID=xxxxxxxx-xxxx-xxxx /mnt/data ext4 defaults 0 2
+----------------------------------------------------------+
| Options: |
| defaults = rw, suid, dev, exec, auto, nouser, async |
| noauto = Don't mount at boot |
| user = Allow user to mount |
| noexec = No executables allowed |
| nosuid = Ignore suid/sgid bits |
+----------------------------------------------------------+

+------------------------------------------------------------------+
| Setting Up Quotas |
+------------------------------------------------------------------+
Step 1: Enable in /etc/fstab
+----------------------------------------------------------+
| /dev/sdb1 /mnt/data ext4 defaults,usrquota,grpquota |
+----------------------------------------------------------+
Step 2: Remount
+----------------------------------------------------------+
| mount -o remount /mnt/data |
+----------------------------------------------------------+
Step 3: Create quota files
+----------------------------------------------------------+
| quotacheck -cug /mnt/data |
+----------------------------------------------------------+
Step 4: Enable quotas
+----------------------------------------------------------+
| quotaon /mnt/data |
+----------------------------------------------------------+
Terminal window
# Install quota tools
apt-get install quota
yum install quota
# Enable quotas in /etc/fstab
/dev/sdb1 /mnt/data ext4 defaults,usrquota,grpquota 0 2
# Remount filesystem
mount -o remount /mnt/data
# Create quota files
quotacheck -cug /mnt/data
# Enable quotas
quotaon /mnt/data
Terminal window
# Set user quota
edquota -u username
# Set group quota
edquota -g groupname
# View user quota
quota -u username
# Check quota usage
repquota -a

+------------------------------------------------------------------+
| Disk Usage Analysis |
+------------------------------------------------------------------+
du -sh /home = Show total size of /home
du -h /home = Show all directories with sizes
du -h /home | sort -rh = Sort by size (largest first)
du -shc /home/* = Show each item + total
Example Output:
+----------------------------------------------------------+
| 4.0G /home/user/documents |
| 2.1G /home/user/downloads |
| 1.5G /home/user/images |
| 512M /home/user/videos |
+----------------------------------------------------------+
Terminal window
# Directory size summary
du -sh /home
# All directories with sizes
du -h /home
# Sorted by size
du -h /home | sort -rh
# Total disk usage
du -shc /home/*
Terminal window
# Human readable
df -h
# File system type
df -Th
# Inode information
df -i

+------------------------------------------------------------------+
| LVM Architecture |
+------------------------------------------------------------------+
Physical Disks Physical Volumes Volume Groups
+----------+ +------------+ +--------------+
| /dev/sdb | -------->| pvcreate | ------>| vgcreate |
| /dev/sdc | | /dev/sdb1 | | vg_data |
+----------+ +------------+ +--------------+
| |
v v
+------------+ +--------------+
| pvs | | lvs |
| pvdisplay | | lvcreate |
+------------+ +--------------+
|
v
+--------------+
| /dev/mapper/ |
| vg_data- |
| lv_data |
+--------------+
Terminal window
# Physical Volume
pvcreate /dev/sdb1
pvdisplay /dev/sdb1
pvs
# Volume Group
vgcreate vg_data /dev/sdb1
vgdisplay vg_data
vgs
# Logical Volume
lvcreate -L 10G -n lv_data vg_data
lvdisplay /dev/vg_data/lv_data
lvs
+------------------------------------------------------------------+
| LVM Operations |
+------------------------------------------------------------------+
Extend Volume Group Extend Logical Volume
+-------------------+ +-----------------------+
| vgextend vg_data | | lvextend -L +5G |
| /dev/sdc1 | | /dev/vg_data/lv_data|
+-------------------+ +-----------------------+
|
v
+-----------------------+
| resize2fs |
| /dev/vg_data/lv_data|
+-----------------------+
Create Snapshot Remove Snapshot
+-------------------+ +-------------------+
| lvcreate -L 1G | | lvremove |
| -s -n snap | | /dev/vg_data/snap|
| /dev/vg_data/lv | +-------------------+
+-------------------+
Terminal window
# Extend Volume Group
vgextend vg_data /dev/sdc1
# Extend Logical Volume
lvextend -L +5G /dev/vg_data/lv_data
resize2fs /dev/vg_data/lv_data
# Reduce Logical Volume
umount /mnt/data
e2fsck -f /dev/vg_data/lv_data
resize2fs /dev/vg_data/lv_data 5G
lvreduce -L 5G /dev/vg_data/lv_data
mount /mnt/data
# Create snapshot
lvcreate -L 1G -s -n snap_data /dev/vg_data/lv_data

+------------------------------------------------------------------+
| LUKS Encryption Flow |
+------------------------------------------------------------------+
Encrypted Opened Mounted
Container Container Filesystem
+----------+ +----------+ +----------+
| /dev/sdb1|-------->| luksOpen|-------->| /dev/ |
| (encrypted) | cryptsetup| | mapper |
+----------+ +----------+ +----------+
|
v
+----------+
| Keyslot |
| (pasword)|
+----------+
Terminal window
# Create encrypted container
cryptsetup luksFormat /dev/sdb1
# Open encrypted container
cryptsetup luksOpen /dev/sdb1 encrypted_data
# Create file system
mkfs.ext4 /dev/mapper/encrypted_data
# Mount
mount /dev/mapper/encrypted_data /mnt/data
# Close
umount /mnt/data
cryptsetup luksClose encrypted_data

+------------------------------------------------------------------+
| Troubleshooting Guide |
+------------------------------------------------------------------+
Problem Diagnosis Solution
+------------------+ +------------------+ +----------------+
| Filesystem Full | | df -h | | du -sh /* |
+------------------+ +------------------+ +----------------+
+------------------+ +------------------+ +----------------+
| Inode Exhaustion| | df -i | | Find & delete |
+------------------+ +------------------+ +----------------+
+------------------+ +------------------+ +----------------+
| Corrupted FS | | fsck.ext4 | | Backup & format|
+------------------+ +------------------+ +----------------+
+------------------+ +------------------+ +----------------+
| Mount Fails | | dmesg | tail | | Check device |
+------------------+ +------------------+ +----------------+
  1. Filesystem Full

    Terminal window
    df -h # Check usage
    du -sh /* # Find large directories
  2. Inode Exhaustion

    Terminal window
    df -i # Check inode usage
    find / -type f | wc -l # Count files
  3. Corrupted Filesystem

    Terminal window
    # Always unmount first
    umount /dev/sdb1
    # Check and repair
    fsck.ext4 -fy /dev/sdb1
  4. Mount Failures

    Terminal window
    # Check device
    fdisk -l
    # Check filesystem
    file -s /dev/sdb1
    # Check mount options
    dmesg | tail

+------------------------------------------------------------------+
| Best Practices Checklist |
+------------------------------------------------------------------+
[ ] Always backup before formatting
[ ] Use appropriate file system for workload
[ ] Monitor disk usage regularly
[ ] Enable and configure quotas in multi-user environments
[ ] Use LVM for flexibility in storage management
[ ] Implement encryption for sensitive data
[ ] Schedule regular filesystem checks
[ ] Keep spare disk space available (10-20%)
Monitoring Commands:
+----------------------------------------------------------+
| df -h | Disk space usage |
| du -sh | Directory size |
| df -i | Inode usage |
| smartctl | Disk health |
+----------------------------------------------------------+
  1. Always backup before formatting
  2. Use appropriate file system for workload
  3. Monitor disk usage regularly
  4. Enable and configure quotas in multi-user environments
  5. Use LVM for flexibility in storage management
  6. Implement encryption for sensitive data
  7. Schedule regular filesystem checks
  8. Keep spare disk space available (10-20%)

WRONG:

Terminal window
# Using non-journaling filesystem
mkfs.ext2 /dev/sdb1
mount /dev/sdb1 /data

CORRECT:

Terminal window
# Use ext4 or xfs for production
mkfs.ext4 /dev/sdb1
# OR
mkfs.xfs /dev/sdb1

Why: ext2 has no journaling - power failures cause filesystem corruption and long fsck times.


WRONG:

Terminal window
# Only checking disk space
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 100G 50G 50G 50% /
# Missing inode check - can be exhausted even with free space!
df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda1 6553600 6553600 0 100% /

CORRECT:

Terminal window
# Always check both
df -h
df -i
# For finding inode-heavy directories
find / -xdev -printf '%h\n' | sort | uniq -c | sort -k1 -nr | head -20

Why: Inode exhaustion prevents new file creation even with free disk space.


WRONG:

Terminal window
# Reducing LV while mounted (dangerous!)
lvreduce -L -10G /dev/vg00/lv_data
# Not extending filesystem after LV extension
lvextend -L +10G /dev/vg00/lv_data
# Filesystem still shows old size!

CORRECT:

Terminal window
# Extend filesystem AFTER extending LV
ext4fs /dev/vg00/lv_data
resize2fs /dev/vg00/lv_data
# For xfs
xfs_growfs /mount/point

Why: Must extend filesystem to use new LV space; never reduce mounted filesystems.


WRONG:

Terminal window
# Using default mount options for all filesystems
mount /dev/sdb1 /data

CORRECT:

Terminal window
# Optimized mount options for data
mount -o defaults,noatime,nodiratime,barrier=1 /dev/sdb1 /data
# For database workloads
mount -o defaults,noatime,nodiratime,barrier=1,data=journal /dev/sdb1 /data

Why: Default options aren’t optimal; noatime improves performance significantly.


WRONG:

Terminal window
# No quota enforcement - users can fill disk
mount /dev/sdb1 /home

CORRECT:

Terminal window
# Enable quotas in /etc/fstab
/dev/sdb1 /home ext4 defaults,usrquota,grpquota 0 2
# Initialize quota files
quotacheck -cum /home
# Set quotas
edquota username

Why: Without quotas, one user can fill filesystem and cause outage for everyone.


┌─────────────────────────────────────────────────────────────────────────────┐
│ FILESYSTEM INTERVIEW QUESTIONS │
├─────────────────────────────────────────────────────────────────────────────┤
│ │
│ Q1: What is the difference between ext3, ext4, and xfs? │
│ │
│ A1: │
│ - ext3: Journaling filesystem, max 16TB, backward compatible with ext2 │
│ - ext4: Extended from ext3, supports 1EB, delayed allocation, extents │
│ - xfs: High-performance, scalable, excellent for large files, online defrag│
│ │
│ ─────────────────────────────────────────────────────────────────────────── │
│ │
│ Q2: What is journaling in filesystems? │
│ │
│ A2: │
│ - Journal records metadata changes before writing to disk │
│ - Prevents corruption on power failure │
│ - Quick recovery (seconds vs minutes/hours for fsck) │
│ - Three modes: journal, ordered, writeback │
│ │
│ ─────────────────────────────────────────────────────────────────────────── │
│ │
│ Q3: How do you resize an LVM logical volume? │
│ │
│ A3: │
│ 1. Extend LV: lvextend -L +10G /dev/vg/lv │
│ 2. Extend filesystem: resize2fs /dev/vg/lv (ext4) │
│ OR xfs_growfs /mount/point (xfs) │
│ For reduction: umount -> fsck -> lvreduce -> resize2fs -> mount │
│ │
│ ─────────────────────────────────────────────────────────────────────────── │
│ │
│ Q4: What causes inode exhaustion? │
│ │
│ A4: │
│ - Many small files (log files, cache, sessions) │
│ - Not related to disk space │
│ - Check with: df -i │
│ - Solution: clean up files or increase inode limit │
│ │
│ ─────────────────────────────────────────────────────────────────────────── │
│ │
│ Q5: How do you recover from a filesystem corruption? │
│ │
│ A5: │
│ 1. Unmount filesystem │
│ 2. Run fsck -y /dev/sdX │
│ 3. Check logs for cause │
│ 4. Restore from backup if needed │
│ 5. Consider switching to journaling filesystem │
│ │
│ ─────────────────────────────────────────────────────────────────────────── │
│ │
│ Q6: What are extents in filesystems? │
│ │
│ A6: │
│ - Contiguous blocks of storage │
│ - Reduces metadata overhead │
│ - Improves performance for large files │
│ - Supported in ext4 and xfs │
│ │
│ ─────────────────────────────────────────────────────────────────────────── │
│ │
│ Q7: How does noatime improve performance? │
│ │
│ A7: │
│ - Disables access time updates on read │
│ - Significantly reduces I/O operations │
│ - Use nodiratime for directories │
│ - Recommended: defaults,noatime,nodiratime │
│ │
│ ─────────────────────────────────────────────────────────────────────────── │
│ │
│ Q8: What is the difference between hard links and symbolic links? │
│ │
│ A8: │
│ - Hard link: same inode, cannot cross filesystem, cannot link dirs │
│ - Symbolic link: separate file, pointer to path, can cross filesystem │
│ - Deleting original: hard link works, symlink breaks │
│ │
│ ─────────────────────────────────────────────────────────────────────────── │
│ │
│ Q9: How do you monitor filesystem health? │
│ │
│ A9: │
│ - smartctl -a /dev/sdX for S.M.A.R.T. status │
│ - tune2fs -l /dev/sdX for filesystem info │
│ - dumpe2fs for superblock details │
│ - Monitor with: nagios, zabbix, prometheus node exporter │
│ │
│ ─────────────────────────────────────────────────────────────────────────── │
│ │
│ Q10: What is a filesystem's journal? │
│ │
│ A10: │
│ - Special area recording pending changes │
│ - Commits changes to main filesystem after journal write │
│ - Enables fast recovery on crash │
│ - Three modes: journal (all data), ordered (metadata only), writeback │
│ │
└─────────────────────────────────────────────────────────────────────────────┘

+------------------------------------------------------------------+
| Quick Reference |
+------------------------------------------------------------------+
File System Commands:
+----------------------------------------------------------+
| mkfs.ext4 /dev/sdb1 | Create ext4 FS |
| fsck.ext4 /dev/sdb1 | Check/repair ext4 |
| mount /dev/sdb1 /mnt/data | Mount filesystem |
| umount /mnt/data | Unmount |
| df -h | Show disk usage |
| du -sh /dir | Directory size |
+----------------------------------------------------------+
LVM Commands:
+----------------------------------------------------------+
| pvcreate /dev/sdb1 | Create PV |
| vgcreate vg_name /dev/sdb1| Create VG |
| lvcreate -L 10G -n lv_name | Create LV |
| lvextend -L +5G /dev/vg/lv | Extend LV |
+----------------------------------------------------------+
Quota Commands:
+----------------------------------------------------------+
| edquota -u user | Edit user quota |
| quota -u user | View user quota |
| repquota -a | Report all quotas |
+----------------------------------------------------------+