Introduction to Linux File Systems

Understanding Linux file system hierarchy, common file systems (ext4, XFS, Btrfs), mounting, permissions, and disk management fundamentals.

2022-07-27 · 6 min read · 1105 words · difficulty: Intermediate

#Linux#File Systems#ext4#XFS#Btrfs#Mounting#Permissions#Disk ManagementLinuxSystem AdministrationStorage

Table of contents

This article is part of a series.


Linux File System Hierarchy (FHS)

/ (root)
├── /bin          → Essential user binaries (ls, cp, mv)
├── /boot         → Kernel, initramfs, GRUB
├── /dev          → Device files (sda, tty, null)
├── /etc          → System configuration files
├── /home         → User home directories
├── /lib          → Shared libraries for /bin, /sbin
├── /media        → Mount points for removable media
├── /mnt          → Temporary mount points
├── /opt          → Optional/add-on software
├── /proc         → Virtual filesystem (kernel info)
├── /root         → Root user home directory
├── /run          → Runtime variable data
├── /sbin         → System binaries (fsck, reboot, ip)
├── /srv          → Data for services (web, ftp)
├── /sys          → Virtual filesystem (kernel devices)
├── /tmp          → Temporary files (cleared on reboot)
├── /usr          → User programs (read-only, shareable)
│   ├── /usr/bin      → Non-essential binaries
│   ├── /usr/lib      → Libraries for /usr/bin
│   ├── /usr/local    → Locally compiled software
│   └── /usr/share    → Architecture-independent data
└── /var          → Variable data (logs, spool, cache)
    ├── /var/log      → System logs
    ├── /var/spool    → Print/mail queues
    └── /var/cache    → Application caches

Common Linux File Systems

ext4 (Fourth Extended): Default for Most Distros

FeatureDetails
Max file size16 TB
Max volume size1 EB
JournalingYes (metadata + optional data)
Backward compatibleext2, ext3
DefragmentationOnline (e4defrag)
Best forGeneral purpose, SSDs, HDDs
# Create ext4
mkfs.ext4 /dev/sdX1

# Check/repair
fsck.ext4 -f /dev/sdX1

# Tune
tune2fs -l /dev/sdX1

XFS: High Performance, Large Files

FeatureDetails
Max file size8 EB
Max volume size8 EB
JournalingYes (metadata only)
Parallel I/OExcellent
Online growYes (xfs_growfs)
Online shrink❌ Not supported
Best forLarge storage, media, databases, RHEL default
# Create XFS
mkfs.xfs /dev/sdX1

# Grow (online, mounted)
xfs_growfs /mount/point

# Check
xfs_repair /dev/sdX1

Btrfs: Modern, Feature-Rich

FeatureDetails
Max file size16 EB
Max volume size16 EB
Copy-on-WriteYes
SnapshotsNative, instant
Compressionzstd, lzo, zlib
RAIDNative (0,1,10,5,6)
Self-healingChecksums + redundant copies
Best forAdvanced users, snapshots, Fedora default
# Create Btrfs
mkfs.btrfs /dev/sdX1

# Snapshot (instant)
btrfs subvolume snapshot /source /snapshots/backup-$(date +%F)

# Compress
mount -o compress=zstd /dev/sdX1 /mnt

Other File Systems

FSUse Case
FAT32USB drives, cross-platform (max 4GB file)
exFATLarge USB/SD cards, cross-platform
NTFSWindows dual-boot (read/write via ntfs-3g)
ZFSEnterprise, data integrity (separate kernel module)
JFSLegacy, low CPU overhead
ReiserFSLegacy, small files

Disk & Partition Management

View Disks

lsblk          # Tree view
lsblk -f       # With filesystem info
fdisk -l       # Partition tables
parted -l      # GPT/MBR details

Partitioning (fdisk/parted)

# MBR (legacy BIOS)
fdisk /dev/sdX

# GPT (UEFI)
parted /dev/sdX mklabel gpt
parted /dev/sdX mkpart primary ext4 1MiB 100%

Common Partition Schemes

SchemeBoot ModePartitions
MBRLegacy BIOSUp to 4 primary (or 3 primary + extended)
GPTUEFI128+ partitions, >2TB disks

Typical Linux Layout (GPT/UEFI):

PartitionSizeMountType
EFI System512 MiB/boot/efiFAT32
Root50-100 GiB/ext4/XFS/Btrfs
HomeRemaining/homeext4/XFS/Btrfs
Swap2-16 GiBswaplinux-swap

Mounting File Systems

Temporary Mount

mount /dev/sdX1 /mnt
mount -t ext4 /dev/sdX1 /mnt
mount -o ro /dev/sdX1 /mnt    # Read-only

Permanent Mount (/etc/fstab)

# <device>    <mount>    <type>    <options>           <dump> <pass>
UUID=xxxx     /          ext4      defaults,noatime    0      1
UUID=yyyy     /home      ext4      defaults,noatime    0      2
UUID=zzzz     /boot/efi  vfat      umask=0077          0      1
UUID=swap     none       swap      sw                  0      0
OptionMeaning
defaultsrw, suid, dev, exec, auto, nouser, async
noatimeDon’t update access time (performance)
discardSSD TRIM (or use fstrim timer)
noexecPrevent execution
nosuidIgnore suid/sgid bits

Auto-mount systemd

# /etc/systemd/system/mnt-data.mount
[Unit]
Description=Data Drive

[Mount]
What=/dev/disk/by-uuid/xxxx
Where=/mnt/data
Type=ext4
Options=defaults,noatime

[Install]
WantedBy=multi-user.target

File Permissions & Ownership

Permission Bits

ls -l
# -rw-r--r--  1 user group  1024 Jan 1 12:00 file.txt
#  ^  ^  ^  ^
#  |  |  |  └─ Others: read
#  |  |  └──── Group: read
#  |  └──────── Owner: read, write
#  └─────────── Type: - (file), d (dir), l (link)

Numeric (Octal) Permissions

ValuePermissionBinary
7rwx111
6rw-110
5r-x101
4r–100
3-wx011
2-w-010
1–x001
0—000

Common Combinations

PermissionFilesDirectories
755rwxr-xr-xrwxr-xr-x
644rw-r–r–-
700rwx——rwx——
600rw——--

Changing Permissions

chmod 755 file.sh           # Numeric
chmod u+x file.sh           # Symbolic (user + execute)
chmod g-w,o-r file.txt      # Remove group write, other read
chmod -R 755 /dir           # Recursive

chown user:group file       # Change owner:group
chown -R user:group /dir    # Recursive
chown :group file           # Change group only

Special Bits

BitSymbolNumericEffect
SUIDs in user exec4000Run as file owner
SGIDs in group exec2000Run as file group; new files inherit group
Stickyt in other exec1000Only owner can delete (e.g., /tmp)
chmod 4755 /usr/bin/passwd    # SUID
chmod 2775 /shared/dir        # SGID
chmod 1777 /tmp               # Sticky

Disk Usage & Monitoring

df -h              # Disk free space (human)
df -i              # Inode usage
du -sh /path       # Directory size
du -sh * | sort -hr # Sort by size
ncdu /             # Interactive (install ncdu)

lsblk -f           # Filesystem details
blkid              # UUID, TYPE, LABEL
findmnt            # Mount tree

File System Maintenance

Check & Repair

# ext4
fsck.ext4 -f /dev/sdX1
e2fsck -y /dev/sdX1

# XFS (unmounted!)
xfs_repair /dev/sdX1

# Btrfs
btrfs check /dev/sdX1
btrfs scrub start /mount  # Background checksum verification

Defragmentation

# ext4 (online)
e4defrag /mount/point

# XFS (online)
xfs_fsr /mount/point

# Btrfs (online)
btrfs filesystem defragment -r /mount/point

SSD Optimization

# Enable discard (TRIM) in fstab
UUID=xxxx  /  ext4  defaults,noatime,discard  0 1

# Or use fstrim timer (preferred)
systemctl enable fstrim.timer
systemctl start fstrim.timer

# Manual trim
fstrim -v /

LVM (Logical Volume Manager)

# Physical Volume
pvcreate /dev/sdX1

# Volume Group
vgcreate vg0 /dev/sdX1

# Logical Volume
lvcreate -L 20G -n root vg0
lvcreate -L 100%FREE -n home vg0

# Format & Mount
mkfs.ext4 /dev/vg0/root
mount /dev/vg0/root /mnt

# Resize (grow)
lvextend -L +10G /dev/vg0/root
resize2fs /dev/vg0/root  # ext4
xfs_growfs /mnt          # XFS

RAID (mdadm)

# Create RAID 1 (mirror)
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdX1 /dev/sdY1

# Create RAID 5 (3+ disks)
mdadm --create /dev/md0 --level=5 --raid-devices=3 /dev/sdX1 /dev/sdY1 /dev/sdZ1

# Monitor
cat /proc/mdstat
mdadm --detail /dev/md0

# Add spare
mdadm --add /dev/md0 /dev/sdZ1

Quick Reference

TaskCommand
List diskslsblk -f
Check disk healthsmartctl -a /dev/sdX
Benchmarkhdparm -Tt /dev/sdX
Wipe diskwipefs -a /dev/sdX
Secure eraseshred -v /dev/sdX
Find large filesfind / -size +100M -type f


MU
Madhusudan Upadhyay

ICT Support Executive · 11+ yrs · M365 · Intune · Windows Server & AD · Kathmandu. Work with me →

📬 New posts via RSS · /uses