Skip to content

Filesystem_hierarchy

Chapter 2: Linux Architecture and File System Hierarchy

Section titled “Chapter 2: Linux Architecture and File System Hierarchy”

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.


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

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/ | |
| +-----------------------------------------------------------+ |
| |
+------------------------------------------------------------------+
DirectoryDescriptionExample Files
/binEssential command binariesls, cp, mv, rm, cat
/sbinEssential system binariesfdisk, mkfs, ifconfig, reboot
/etcSystem configurationpasswd, fstab, network/, systemd/
/homeUser home directories/home/username/
/rootRoot user home directory/root/
/usrUser programs/usr/bin/, /usr/lib/, /usr/share/
/varVariable data/var/log/, /var/cache/, /var/spool/
/tmpTemporary filesCleared on reboot
/procProcess information/proc/cpuinfo, /proc/meminfo
/sysSystem information/sys/kernel/, /sys/class/
/devDevice files/dev/sda, /dev/null, /dev/tty
/optOptional software/opt/application/
/srvService data/srv/www/, /srv/ftp/
/runRuntime data/run/systemd/, /run/lock/
Terminal window
# Additional Arch Linux directories
ls -la /var/cache/pacman/pkg/ # Package cache
ls -la /etc/pacman.d/ # Pacman configuration
ls -la /boot/ # Boot files (vmlinuz, initramfs)

/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 |
| |
+------------------------------------------------------------------+
Terminal window
# 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 options
/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 |
| |
+------------------------------------------------------------------+
Terminal window
# 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 logs
tail -f /var/log/syslog # Follow system log
grep "error" /var/log/syslog # Search for errors
journalctl -xe # View systemd journal
/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 Information
cat /proc/cpuinfo # CPU model, cores, flags
grep "model name" /proc/cpuinfo # CPU type
# Memory Information
cat /proc/meminfo # RAM and swap usage
free -h # Human-readable memory info
# System Information
cat /proc/uptime # System uptime in seconds
cat /proc/loadavg # Load averages (1, 5, 15 min)
uname -a # Kernel version and system info
# Process Information
ls /proc/ # All running processes
cat /proc/1/status # Init process (systemd) info
ls -la /proc/1/fd/ # File descriptors of PID 1
# Mounted Filesystems
cat /proc/mounts # Current mounts
mount # Mounted filesystems with options
# Disk Partitioning
cat /proc/partitions # All partitions
lsblk # Block devices (better view)

/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) |
| |
+------------------------------------------------------------------+
Terminal window
# 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)

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 |
| |
+------------------------------------------------------------------+
Terminal window
# Memory
free -h # Memory and swap usage
cat /proc/meminfo # Detailed memory info
vmstat 1 # Memory statistics every second
# CPU
top # Real-time process viewer
htop # Enhanced top (colored)
cat /proc/cpuinfo # CPU details
lscpu # CPU architecture info
# Disk
df -h # Disk space usage
du -sh /directory # Directory size
lsblk # Block devices
fdisk -l # Partition table
# Load Average
uptime # System uptime and load
cat /proc/loadavg # Load averages

Terminal window
# 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 config
Terminal window
# Pacman cache location
/var/cache/pacman/pkg/ # Downloaded packages
# Clean cache
sudo pacman -Scc # Remove all cached packages
sudo pacman -Sc # Remove uninstalled packages
Terminal window
# Systemd journal location
/var/log/journal/ # Persistent journal (if configured)
# View journal
journalctl # All logs
journalctl -u nginx # Nginx service logs
journalctl -p err # Error and above
journalctl --since "1 hour ago"
journalctl -f # Follow logs

Terminal window
# Exercise 1: Navigate the filesystem
cd / # Go to root
ls -la # List all files
cd /etc && ls -la | head # List config directory
# Exercise 2: Find configuration files
find /etc -name "*.conf" | head # Find config files
ls /etc/systemd/system/ # Systemd services
# Exercise 3: Check system information
cat /proc/version # Kernel version
uname -r # Kernel release
cat /etc/os-release # OS information (Arch)
# Exercise 4: Check hardware
lspci # PCI devices
lsusb # USB devices
cat /proc/cpuinfo | grep "model name"
# Exercise 5: Monitor resources
top # Process monitor
iostat -x 1 # I/O statistics

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

Chapter 3: Linux Boot Process


Last Updated: February 2026