Filesystem_hierarchy
Chapter 2: Linux Architecture and File System Hierarchy
Section titled “Chapter 2: Linux Architecture and File System Hierarchy”Overview
Section titled “Overview”Understanding Linux architecture and the Filesystem Hierarchy Standard (FHS) is crucial for any system administrator. This chapter covers how Linux organizes files, directories, and system resources.
2.1 Linux System Architecture
Section titled “2.1 Linux System Architecture”2.1.1 Complete Architecture Overview
Section titled “2.1.1 Complete Architecture Overview” Linux System Architecture+------------------------------------------------------------------+| || Layer 4: Applications || +-----------------------------------------------------------+ || | Web Servers | Databases | Containers | Scripts | || | nginx, Apache | MySQL, PostgreSQL | Docker, Podman | Bash | || +-----------------------------------------------------------+ || | || v || Layer 3: System Libraries || +-----------------------------------------------------------+ || | glibc | libcurl | libssl | libpthread | || +-----------------------------------------------------------+ || | || v || Layer 2: GNU Coreutils || +-----------------------------------------------------------+ || | ls, cp, mv, rm | cat, grep, sed | awk, find | chmod | || +-----------------------------------------------------------+ || | || v || Layer 1: Kernel || +-----------------------------------------------------------+ || | System Call | Process | Memory | File System | Network | || | Interface | Scheduler| Manager| | Stack | || +-----------------------------------------------------------+ || | || v || Layer 0: Hardware || +-----------------------------------------------------------+ || | CPU | RAM | Disk/NVMe | Network Card | GPU | || +-----------------------------------------------------------+ || |+------------------------------------------------------------------+2.1.2 How Processes Interact with the System
Section titled “2.1.2 How Processes Interact with the System” Process System Call Flow+------------------------------------------------------------------+| || User: Run "ls -la /home" || | || v || Shell: Execute command || | || v || Library: Load libc.so || | || v || Kernel: syscall open("/home") || | || v || Kernel: Check permissions || | || v || Hardware: Read disk sectors || | || v || Kernel: Return file handle || | || v || Library: Return data buffer || | || v || Shell: Display file listing || | || v || User: See results || |+------------------------------------------------------------------+2.2 Filesystem Hierarchy Standard (FHS)
Section titled “2.2 Filesystem Hierarchy Standard (FHS)”2.2.1 Directory Structure Overview
Section titled “2.2.1 Directory Structure Overview” Linux Directory Structure+------------------------------------------------------------------+| || / (Root) || | | | | | | | | || v v v v v v v v || +-----+-----+-----+-----+-----+-----+-----+-----+ || |bin |sbin |etc |var |usr |home |root |opt | || | | | | | | | | | || +-----+-----+-----+-----+-----+-----+-----+-----+ || | | | | | | | || | | | | | +-----+-----+ || | | | | | |local |share | || | | | | | | | | || | | | | | +------+-----+ || | | | | | | || | | | | | v || +-----+-----+-----+-----+-----+ +------+ || |tmp |proc |sys |dev |run | | lib | || | | | | | | | | || +-----+-----+-----+-----+-----+ +------+ || || Subdirectories of /var: || +-----------------------------------------------------------+ || | log/ | cache/ | lib/ | spool/ | || +-----------------------------------------------------------+ || |+------------------------------------------------------------------+2.2.2 Directory Details
Section titled “2.2.2 Directory Details”| Directory | Description | Example Files |
|---|---|---|
/bin | Essential command binaries | ls, cp, mv, rm, cat |
/sbin | Essential system binaries | fdisk, mkfs, ifconfig, reboot |
/etc | System configuration | passwd, fstab, network/, systemd/ |
/home | User home directories | /home/username/ |
/root | Root user home directory | /root/ |
/usr | User programs | /usr/bin/, /usr/lib/, /usr/share/ |
/var | Variable data | /var/log/, /var/cache/, /var/spool/ |
/tmp | Temporary files | Cleared on reboot |
/proc | Process information | /proc/cpuinfo, /proc/meminfo |
/sys | System information | /sys/kernel/, /sys/class/ |
/dev | Device files | /dev/sda, /dev/null, /dev/tty |
/opt | Optional software | /opt/application/ |
/srv | Service data | /srv/www/, /srv/ftp/ |
/run | Runtime data | /run/systemd/, /run/lock/ |
2.2.3 Arch Linux Specific Directories
Section titled “2.2.3 Arch Linux Specific Directories”# Additional Arch Linux directoriesls -la /var/cache/pacman/pkg/ # Package cachels -la /etc/pacman.d/ # Pacman configurationls -la /boot/ # Boot files (vmlinuz, initramfs)2.3 Key Directories Deep Dive
Section titled “2.3 Key Directories Deep Dive”2.3.1 /etc - Configuration Files
Section titled “2.3.1 /etc - Configuration Files” /etc Directory Contents+------------------------------------------------------------------+| || /etc || | | | | | | | | || v v v v v v v v || +-----+-----+-----+-----+-----+-----+-----+-----+ || |passwd|shadow|group |hosts |resolv|fstab|cron.d| || | | | | |.conf | | | || +-----+-----+-----+-----+-----+-----+-----+-----+ || | | | | | | || v v v v v v || +-----+-----+-----+-----+-----+-----+-----+-----+ || |systemd|network| ssh |pacman.d| nginx| apache| || | | | | | | | || +-----+-----+-----+-----+-----+-----+-----+-----+ || || Key Files: || - passwd: User accounts || - shadow: Encrypted passwords || - group: Group definitions || - hosts: DNS mappings || - resolv.conf: DNS nameservers || - fstab: Mount points || |+------------------------------------------------------------------+Important /etc Files
Section titled “Important /etc Files”# User and group configuration/etc/passwd # User accounts format: username:password:uid:gid:info:home:shell/etc/shadow # Encrypted passwords (only root can read)/etc/group # Group definitions
# Network configuration/etc/hosts # Static hostname/IP mappings/etc/resolv.conf # DNS nameservers/etc/nsswitch.conf # Name service switch config/etc/network/ # Network interfaces (Debian/Ubuntu)/etc/systemd/network/ # Network config (systemd-networkd)
# System configuration/etc/fstab # Filesystem mount table/etc/crontab # System cron jobs/etc/rc.conf # Main config file (Arch)/etc/pacman.conf # Pacman configuration/etc/modprobe.d/ # Kernel module options2.3.2 /var - Variable Data
Section titled “2.3.2 /var - Variable Data” /var Directory Structure+------------------------------------------------------------------+| || /var || | | | | | | || v v v v v v || +-----+-----+-----+-----+-----+-----+ || | log |cache| lib |spool| tmp | || +-----+-----+-----+-----+-----+-----+ || | | | || v v v || +-----+-----+ +-----+-----+ || |auth |syslog| | mail |cron | || |.log | | | | | || +-----+-----+ +-----+-----+ || | || v || +-----+-----+-----+-----+ || |nginx/|mysql/|apache/|postgres/| || | | | | | || +-----+-----+-----+-----+ || || Key Contents: || - /var/log: System and application logs || - /var/cache: Application cache data || - /var/lib: Application state information || - /var/spool: Print and mail queues || - /var/tmp: Temporary files || |+------------------------------------------------------------------+/var/log Common Logs
Section titled “/var/log Common Logs”# System logs/var/log/syslog # General system messages (Debian/Ubuntu)/var/log/messages # General system messages (RHEL/CentOS)/var/log/dmesg # Kernel ring buffer/var/log/auth.log # Authentication logs (Debian/Ubuntu)/var/log/secure # Authentication logs (RHEL/CentOS)
# Application logs/var/log/nginx/ # Nginx web server logs/var/log/apache2/ # Apache logs/var/log/mysql/ # MySQL/MariaDB logs/var/log/pacman.log # Pacman transaction logs (Arch)
# Viewing logstail -f /var/log/syslog # Follow system loggrep "error" /var/log/syslog # Search for errorsjournalctl -xe # View systemd journal2.3.3 /proc - Process Information
Section titled “2.3.3 /proc - Process Information” /proc Directory Contents+------------------------------------------------------------------+| || /proc || | | | | | | | | || v v v v v v v v || +-----+-----+-----+-----+-----+-----+-----+-----+ || |cpuinfo|meminfo|loadavg|uptime|mounts|partit|modules| || +-----+-----+-----+-----+-----+-----+-----+-----+ || | || v || +--------------------------------------------------+ || | /proc/PID/ | || | cmdline | environ | fd/ | status | maps | | || +--------------------------------------------------+ || || Key Files: || - /proc/cpuinfo: CPU information || - /proc/meminfo: Memory information || - /proc/loadavg: Load averages || - /proc/uptime: System uptime || - /proc/mounts: Mounted filesystems || - /proc/partitions: Disk partitions || - /proc/modules: Loaded kernel modules || - /proc/PID/: Process-specific information || |+------------------------------------------------------------------+pid --> pid_cwd["cwd<br/>Working directory"]pid --> pid_exe["exe<br/>Executable link"]pid --> pid_fd["fd/<br/>File descriptors"]pid --> pid_status["status<br/>Process status"]pid --> pid_maps["maps<br/>Memory maps"]#### Important /proc Files
```bash# CPU Informationcat /proc/cpuinfo # CPU model, cores, flagsgrep "model name" /proc/cpuinfo # CPU type
# Memory Informationcat /proc/meminfo # RAM and swap usagefree -h # Human-readable memory info
# System Informationcat /proc/uptime # System uptime in secondscat /proc/loadavg # Load averages (1, 5, 15 min)uname -a # Kernel version and system info
# Process Informationls /proc/ # All running processescat /proc/1/status # Init process (systemd) infols -la /proc/1/fd/ # File descriptors of PID 1
# Mounted Filesystemscat /proc/mounts # Current mountsmount # Mounted filesystems with options
# Disk Partitioningcat /proc/partitions # All partitionslsblk # Block devices (better view)2.4 Understanding Device Files
Section titled “2.4 Understanding Device Files”2.4.1 Device Types
Section titled “2.4.1 Device Types” /dev Device Types+------------------------------------------------------------------+| || /dev || | | | | || v v v v || +----------+ +----------+ +----------+ +----------+ || | Block | | Character| | Named | | Unix | || | Devices | | Devices | | Pipes | | Sockets | || +----+-----+ +----+-----+ +----+-----+ +----+-----+ || | | | | || v v | | || +----------+ +----------+ | | || | sda | | tty | | | || | nvme0n1 | | null | | | || | loop0 | | zero | | | || | | | random | | | || +----------+ +----------+ | | || v v || Block Devices: Named Pipes: Sockets: || - sda, sdb (SATA/SCSI) - /tmp/mypipe - /run/docker.sock || - nvme0n1 (NVMe) || - loop0 (Loop devices) || |+------------------------------------------------------------------+2.4.2 Common Device Files
Section titled “2.4.2 Common Device Files”# Special device files/dev/null # Discard all writes, returns EOF on read/dev/zero # Returns infinite zeros/dev/random # Blocks until enough entropy/dev/urandom # Non-blocking random (faster)/dev/full # Returns ENOSPC on write
# Disk devices/dev/sda # First SCSI/SATA disk/dev/sda1 # First partition on sda/dev/nvme0n1 # First NVMe device/dev/nvme0n1p1 # First partition on nvme0n1
# Terminal devices/dev/tty # Current terminal/dev/tty1 # First virtual terminal/dev/pts/0 # First pseudo-terminal
# Loop devices/dev/loop0 # First loop device (for ISO images)2.5 System Resources
Section titled “2.5 System Resources”2.5.1 Memory Management
Section titled “2.5.1 Memory Management” Linux Memory Layout+------------------------------------------------------------------+| || Physical RAM || +-----------------------------------------------------------+ || | | || | +-------------------------+ +----------------------+ | || | | Used Memory | | Free Memory | | || | | +-------+ +-----------+ | | | | || | | | App | | Kernel | | Available for | | || | | |Memory | | Memory | | applications | | || | | +-------+ +-----------+ | | | | || | +-------------------------+ +----------------------+ | || | | || | +-------------------------+ +----------------------+ | || | | Buffers/Cached | | | | || | | +-------+ +-----------+ | | Swap Space | | || | | |Buffer | | Page Cache| | (if used) | | || | | | | | Slab Cache| | | | | || | | +-------+ +-----------+ | +----------------------+ | || | +-------------------------+ | || +-----------------------------------------------------------+ || || Note: "Available" = Free + Buffers + Cached || |+------------------------------------------------------------------+2.5.2 Checking System Resources
Section titled “2.5.2 Checking System Resources”# Memoryfree -h # Memory and swap usagecat /proc/meminfo # Detailed memory infovmstat 1 # Memory statistics every second
# CPUtop # Real-time process viewerhtop # Enhanced top (colored)cat /proc/cpuinfo # CPU detailslscpu # CPU architecture info
# Diskdf -h # Disk space usagedu -sh /directory # Directory sizelsblk # Block devicesfdisk -l # Partition table
# Load Averageuptime # System uptime and loadcat /proc/loadavg # Load averages2.6 Arch Linux Specific Configurations
Section titled “2.6 Arch Linux Specific Configurations”2.6.1 Boot Configuration
Section titled “2.6.1 Boot Configuration”# Boot directory structure/boot/├── vmlinuz-linux # Linux kernel├── initramfs-linux.img # Initial RAM disk├── initramfs-linux-fallback.img # Fallback initramfs├── intel-ucode.img # Intel microcode├── amd-ucode.img # AMD microcode└── loader/ # Boot loader config2.6.2 Pacman Cache
Section titled “2.6.2 Pacman Cache”# Pacman cache location/var/cache/pacman/pkg/ # Downloaded packages
# Clean cachesudo pacman -Scc # Remove all cached packagessudo pacman -Sc # Remove uninstalled packages2.6.3 Systemd Journal
Section titled “2.6.3 Systemd Journal”# Systemd journal location/var/log/journal/ # Persistent journal (if configured)
# View journaljournalctl # All logsjournalctl -u nginx # Nginx service logsjournalctl -p err # Error and abovejournalctl --since "1 hour ago"journalctl -f # Follow logs2.7 Practice: Exploring the Filesystem
Section titled “2.7 Practice: Exploring the Filesystem”2.7.1 Hands-On Exercises
Section titled “2.7.1 Hands-On Exercises”# Exercise 1: Navigate the filesystemcd / # Go to rootls -la # List all filescd /etc && ls -la | head # List config directory
# Exercise 2: Find configuration filesfind /etc -name "*.conf" | head # Find config filesls /etc/systemd/system/ # Systemd services
# Exercise 3: Check system informationcat /proc/version # Kernel versionuname -r # Kernel releasecat /etc/os-release # OS information (Arch)
# Exercise 4: Check hardwarelspci # PCI deviceslsusb # USB devicescat /proc/cpuinfo | grep "model name"
# Exercise 5: Monitor resourcestop # Process monitoriostat -x 1 # I/O statisticsSummary
Section titled “Summary”In this chapter, you learned:
- ✅ Linux system architecture layers (Applications → Libraries → Coreutils → Kernel → Hardware)
- ✅ Filesystem Hierarchy Standard (FHS) - /bin, /etc, /var, /usr, /proc, /sys
- ✅ Device files in /dev and their types
- ✅ System resource monitoring commands
- ✅ Arch Linux specific directory structures
Next Chapter
Section titled “Next Chapter”Last Updated: February 2026