Skip to content

Filesystems

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


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%)

+------------------------------------------------------------------+
| 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 |
+----------------------------------------------------------+