101-500 practice question 8 of 30

Creating a hard link to an ordinary file returns an error. What could be the reason for this?

Full set: 246 questions
Answer options
A: The source file is hidden.
B: The source file is read-only.
C: The source file is a shell script.
D: The source file is already a hard link.
E: The source and the target are on different filesystems. Correct answer
Correct Answer:
E. The source and the target are on different filesystems.
Explanation

A hard link is an additional directory entry that points to the same inode as the original file. Inodes are data structures that store information about files and are unique only within a single filesystem. Because an inode number from one filesystem has no meaning on another, a hard link cannot be created across different filesystems. Attempting to do so results in an "Invalid cross-device link" error.

Why Incorrect

A: Hidden files (names starting with a dot) are functionally regular files and can be hard-linked without issue. B: File permissions do not affect the ability to create a hard link, as this operation only modifies directory data. C: A shell script is a regular text file and can be hard-linked just like any other ordinary file. D: A file can have many hard links. Creating an additional hard link to a file that already has one is a valid operation.

References

1. The ln(2) system call man page (from The Linux man-pages project): "EXDEV: oldpath and newpath are not on the same mounted filesystem. (Linux permits a filesystem to be mounted at multiple points, but link() does not work across different mount points, even if the same filesystem is mounted on both.)"

2. Red Hat Enterprise Linux 8 Documentation, "Configuring and managing storage devices", Section 9.1.3. "Understanding hard links": "A hard link cannot span across file systems."

3. Arpaci-Dusseau, R. H., & Arpaci-Dusseau, A. C. (2018). Operating Systems: Three Easy Pieces. Arpaci-Dusseau Books. Chapter 40, "Files and Directories", Section 40.3, page 7: "Hard links are generally not allowed to span file systems".

Scroll to Top