I worked through hard versus symbolic links by inspecting inodes and link counts with ls -i and stat. Symlinks enabled atomic configuration swaps (the current-release pointer pattern) while hard links shared data without duplication.

Objective & Context

Links are how Linux references the same data from multiple paths. This lab clarifies that hard links share an inode (same data, multiple names) while symlinks are pointers to a path, then applies symlinks for zero-downtime config and release switching.

Environment & Prerequisites

  • Linux shell with coreutils.
  • A filesystem supporting hard links (same filesystem only).
  • Sample files to link.

Step-by-Step Execution

1. Compare inodes of a hard link

ln file.txt hard.txt && ls -li file.txt hard.txt

2. Create a symlink and inspect it

ln -s /srv/releases/v2 /srv/current && stat /srv/current

3. Atomic release switch

ln -sfn /srv/releases/v3 /srv/current
524301 -rw-r--r-- 2 taki taki file.txt
524301 -rw-r--r-- 2 taki taki hard.txt   # same inode, count 2

Validation & Testing

Delete the original name of a hard-linked file and confirm the data survives via the other name; repoint a symlink and confirm consumers see the new target atomically. Pass criteria: hard links share an inode and survive original deletion; symlink swap is instantaneous.

Advanced: Troubleshooting
  • Cross-filesystem hard link fails: hard links cannot span filesystems; use a symlink.
  • Dangling symlink: the target moved or was deleted; recreate or repoint.
  • Non-atomic swap: use ln -sfn to replace a symlink in one step.

Key Results

  • Demonstrated shared-inode behaviour of hard links with link counts.
  • Implemented zero-downtime release switching with atomic symlink swaps.
  • Distinguished symlink path-pointers from inode-sharing hard links.
  • Avoided data duplication for shared references via hard links.