LX0-103 · Question #122
Creating a hard link to an ordinary file returns an error. What could be the reason for this?
The correct answer is E. The source and the target are on different filesystems.. Hard links reference inodes directly, and inode numbers are only unique within a single filesystem, so hard links cannot span different filesystems.
Question
Creating a hard link to an ordinary file returns an error. What could be the reason for this?
Options
- AThe source file is hidden.
- BThe source file is read-only.
- CThe source file is a shell script.
- DThe source file is already a hard link.
- EThe source and the target are on different filesystems.
How the community answered
(49 responses)- A6% (3)
- C4% (2)
- D2% (1)
- E88% (43)
Why each option
Hard links reference inodes directly, and inode numbers are only unique within a single filesystem, so hard links cannot span different filesystems.
Hidden files (prefixed with a dot) are valid hard link sources; the hidden attribute only affects default directory listing visibility.
Read-only permissions on the source file do not prevent hard link creation, because the operation modifies the directory entry rather than the file's data or metadata.
Shell scripts are ordinary files and can be hard-linked without any restriction.
A file that is already a hard link (link count greater than 1) can still receive additional hard links, as all directory entries pointing to the same inode are treated equally by the filesystem.
Hard links work by creating an additional directory entry pointing to the same inode as the source file, but inode numbers are local to and only meaningful within their own filesystem. When the source and target reside on different filesystems (for example, / and /home on separate partitions), the kernel cannot create a valid inode reference across that boundary and returns an 'Invalid cross-device link' error.
Concept tested: Hard link limitations across filesystem boundaries
Source: https://man7.org/linux/man-pages/man1/ln.1.html
Topics
Community Discussion
No community discussion yet for this question.