A Hardlink Can't Cross Mounts, So Downloads and Media Libraries Must Share One Mount

In progress Linux Kubernetes

A hardlink is a second name for the same file: one more directory entry pointing at the same inode, not a copy. Both names share the data blocks; the blocks are freed only when the last name is removed. That is why a media stack can keep a file seeding in downloads/ and show it in movies/ while storing it once.

link() only works when both names are on the same mount. Across two mounts, it fails with EXDEV, and Linux applies this even when the same filesystem is mounted twice. A mv between two mounts has the same limit: it can't rename, so it copies and then deletes.

In containers, every volume is its own mount. If one app gets /downloads and another /movies as two separate volumes, even of the same NFS export, an import can't link or rename: the app falls back to a full copy, which doubles the space used and takes minutes instead of milliseconds.

Give Every App the Same Single Mount

  • One share (one dataset) holding both trees, for example /data/torrents, /data/usenet and /data/media.
  • Mounted once per container, at the same path in every app (/data), so the paths the download client reports are valid in the importer too.
  • Subfolders are chosen inside the app's settings, not as extra volume mounts.

The importer (Sonarr, Radarr) only hardlinks a download that has to stay where it is: a torrent that is still seeding. A Usenet download, or a torrent that has finished seeding, is moved into the library instead. On one mount that move is a rename: instant, no extra space, and no copy left behind, so the imported file has link count 1 and its download folder is empty. That is the expected result, not a failed hardlink. The single mount still matters for Usenet: across two mounts the move becomes a copy followed by a delete.

To prove a Usenet-only stack could hardlink (for the day a torrent client runs), link a dummy file across the two trees as the apps' user and check both names show the same inode with link count 2.

A hardlinked file has a link count above 1 (ls -l second column, stat -c %h), and both names show the same inode number (ls -i). To count across a library:

find /data/media -type f -size +100M -links +1 | wc -l   # hardlinked
find /data/media -type f -size +100M -links 1 | wc -l    # standalone copies

du counts a hardlinked file once per run, under the first path it meets, so du -sh downloads movies makes the libraries look nearly empty.

References

Review cards