Galle, LK--:--5/6 sites live

Linux Filesystem Hierarchy & Inodes ('Everything is a File')

පිටුව 03: Linux Filesystem ගස, Inodes සහ Hard Links vs Soft Links

Linux හි 'හැමදේම File එකක්' කියන්නේ ඇයි? /etc, /var, /proc, /sys ව්‍යුහය, Inodes ක්‍රියාත්මක වන හැටි සහ Inode Exhaustion ප්‍රශ්නය විසඳමු.

4 Sept 20264 min readSelf Guide · Stage 10#Filesystem#Inodes#SRE Labs

Lab 03 of 20 · Filesystem & Inodes · 5 hands-on activities · bilingual (English + සිංහල)

පිටුව 03: Linux Filesystem ගස, Inodes සහ Hard Links vs Soft Links

Linux හි 'හැමදේම File එකක්' කියන්නේ ඇයි? /etc, /var, /proc, /sys ව්‍යුහය, Inodes ක්‍රියාත්මක වන හැටි සහ Inode Exhaustion ප්‍රශ්නය විසඳමු.

💡 සරල සිංහලෙන්: Inode කියන්නේ පුස්තකාලයක Index Card එකක් වගේ

පුස්තකාලයක උදාහරණය:

  • Inode (Index Card): පුස්තකාලයේ පොතක් තියෙන රාක්කය, පිටු ගණන, පොත ගෙනාපු දවස සහ අයිතිකරු ලියලා තියෙන කාඩ්පත.
  • File Name (පොතේ නම): පොතේ නම තියෙන්නේ Directory එකේ ලයිස්තුවේ. ඒ නම Inode අංකයට යොමු කරලා තියෙනවා.
  • Hard Link: එකම Inode කාඩ් එකට තවත් අලුත් නමක් ලියනවා වගේ. Original නම මැකුවත් අනෙක් නමෙන් Inode එක සහ දත්ත එහෙමම තියෙනවා!
  • Soft Link (Shortcut): "අර පොත තියෙන්නේ අර රාක්කයේ" කියලා ලියපු කුඩා කොළ කෑල්ලක් වගේ. Original පොත අයින් කළොත් මේ Link එක කැඩෙනවා (Broken symlink).
  • Inode ඉවර වීම (Inode Exhaustion): පුස්තකාලයේ ඉඩ තිබුණත්, අලුත් පොත් ලියාපදිංචි කරන Index Cards ඉවර වුණොත් අලුතින් කිසිම පොතක් ගන්න බෑ! ඒකයි df -i ගහලා Inodes ඉතුරුද කියලා බලන්නේ.

Architectural Foundation & Systems Diagram

In Unix and Linux, a core design philosophy is: "Everything is a file". Hardware devices, processes, network sockets, and directories are all represented as file abstractions in the Virtual File System (VFS).

  • 🌳 Root Filesystem Hierarchy — • /bin, /usr/bin: Essential executables.
    • /etc: System configuration files.
    • /var/log: Dynamic runtime logs.
    • /proc & /sys: Virtual in-memory kernel telemetry!

  • 📑 What is an Inode? — An Inode (Index Node) is a data structure on disk storing file metadata: size, owner, permissions, timestamps, and disk block pointers. Crucially, the file's name is NOT stored in the inode!

  • 🔗 Hard Links vs Soft Links — A Hard Link points to the exact same Inode number on disk. A Soft/Symbolic Link (Symlink) is a special shortcut file containing the pathname string of another target file.

Step-by-step practical lab

Step 01: Print Current Working Directory Path

සිංහලෙන් — අපි Terminal එකේ මේ මොහොතේ ඉන්න directory එකේ සම්පූර්ණ path එක පරීක්ෂා කරමු.

Print the absolute pathname of the current working directory to confirm your exact filesystem location.

ExampleShell
pwd
  • pwd : Print Working Directory: Root (/) සිට සම්පූර්ණ absolute path එක පෙන්වයි.

Expected output

Output
/home/sre-engineer

SRE Tip: Always run pwd before executing destructive commands like rm -rf * to avoid accidentally deleting system files.

Step 02: List Directory Files with Permissions & Inodes

සිංහලෙන් — Files වල සම්පූර්ණ විස්තර, permissions සහ hidden files බලාගනිමු.

List directory contents in long format, showing file permissions, owner, group, size in bytes, modification timestamp, and hidden dotfiles.

ExampleShell
ls -la
  • -l : Long listing format: Permissions, hard links, owner, group, size පෙන්වයි.
  • -a : All: තිතෙන් (.) ආරම්භ වන සැඟවුණු hidden files (.bashrc, .profile) ද පෙන්වයි.

Expected output

Output
drwxr-xr-x 6 sre-engineer devops  4096 Sep 16 12:40 .
drwxr-xr-x 3 root         root    4096 Sep 16 09:12 ..
-rw-r--r-- 1 sre-engineer devops  1420 Sep 16 11:15 Dockerfile

SRE Tip: The first character indicates file type: - means regular file, d means directory, l means symbolic link.

Step 03: Filter Configuration Lines Using Regular Expressions

සිංහලෙන් — Files තුළ ඇති වැදගත් දත්ත සොයාගැනීමට Grep command එක භාවිත කරමු.

Search text files or stream inputs for matching string patterns and display matching lines.

ExampleShell
grep -i 'listen' configs/nginx.conf
  • -i : Ignore case: Capital/simple අකුරු භේදයකින් තොරව සෙවීම සිදු කරයි.

Expected output

Output
    listen 80 default_server;
    listen [::]:80 default_server;

SRE Tip: Combine with invert match grep -v '^#' to strip out commented lines when reading large configuration files.

Hands-on practice activities

Work through these yourself — tick them off as you go.

  • Activity 11: Print Working Directory Location (Drill) — Print the absolute pathname of the current working directory to confirm your exact filesystem location.
  • Activity 12: Inspect Inode Metadata Numbers (Drill) — Use the -i flag with ls to print the unique numeric filesystem Inode index assigned to /etc/hosts.
  • Activity 13: Audit Filesystem Inode Capacity (Drill) — Verify Inode usage percentages across all mounted partitions to catch runaway inode exhaustion before outages occur.
  • Activity 14: Understand /proc Virtual Filesystem (Checkpoint) — /proc does NOT exist on your hard drive! It is generated dynamically by the Linux kernel in RAM to expose runtime statistics.
  • Activity 15: File Name Location Quiz (Quiz) — Is the filename of a file stored inside its inode data structure? Answer: No, it is stored in directory entries mapping to the inode.

Keep going: ← Lab 02 · Lab 04 → · Track your progress in the Self Guide

ExerciseKnowledge check

What component stores file metadata (size, owner, permissions, block pointers) in a Linux filesystem? / Linux වල file එකක metadata තබාගන්නේ කුමකින්ද?

Finished this one?

Part of Self Guide · Stage 10: SRE Labs I — the machine underneath. Progress is saved in this browser.

Guide