2

How is it that symbolic links can be used to link across different filesystems? And why is that hard links cannot be used across different filesystems?

1
  • 10 years later it happened to notice that @JdeBP edited this question and added the following toxic justification: "Translated to English.". Editor meant to say: "Adjusting syntax to something he understands"
    – ddmichael
    Oct 1, 2023 at 10:25

2 Answers 2

3

Basically, a symlink is itself a file that contains the path of the file to which it is linking. There's a special bit set in the attributes that causes the operating system to treat the symlink as a link - it reads the path in the file and then follows it to the linked file. All of this is transparent to the user.

Because the symlink is just a file that's interpreted by the OS, it can point to a file or directory on any filesystem, even if the target filesystem does not, itself, support the creation of symlinks.

A hard link, on the other hand, works at a lower level. Hard links and files are essentially the same thing - an entry in the filesystem's directory, consisting of the filename and its inode number. The inode is like a map that describes where on the hard disk the different parts of the file can be found.

When you create a hard link to an existing file, you are creating a new entry in the filesystem's directory that points to the same inode as the existing file. Because of this, the hard link must be on the same filesystem as the existing file.

This is a good article that explains the differences.

1

Hard links are an entry in the file allocation table that points to the same platter, sector and block as the original file. After creating a hard link... you can remove the original filename, and the file is not deleted. Because this is an actual entry in the file-allocation-table to the physical location of the file, it is not possible to have it point to another disk.

Symbolic links are a special kind of file, which is understood as a pointer to another filename. If the target file is deleted... the symbolic link still exists, but no longer has a target at the other end. With that in mind, because it only references a filename... you can point to anything. Even other filesystems.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .