3

As far as I know, hard links will not break when a file is deleted. Because the file will remain to exist.

But what happens when you mount a file system to /mnt for example, create a hard link to a file on that volume, unmount the volume, and then try to open the hard link?

5

You cannot create hardlinks across mount boundaries. You'll get something like:

ln: failed to create hard link ‘X’ => ‘Y’: Invalid cross-device link
0

Yes, hard links will not break when a file is deleted. Because the file will remain to exist.

But a hard link to a file on a different file system is not possible, in a fundamental way.

Practically, that means you can not create hard links to files on different file systems, and get an error when trying.

Now, why is it not possible?

A hard link is what you normally call a file. When there is a file system mounted in /mnt, and you see /mnt/example.txt, you see the name of the hard link example.txt on the file system in /mnt, that points to the data of thee file. A file system contains file data and file names to access parts of the data. There is a reference from the name to the data. This reference is a hard link.

Creating a hard link means to create a reference to the same file data with a new name.

So a hard link is a central part of a file system, referencing the data. That means that a hard link to a different file system is not possible - because it is a different file system.

In principle, there could be a file system that spans more than one partition, and enlarges when adding /mnt to it. Then a hard link to a different partition, but in the same file system could be created, and would break when the partition with the data is unmounted.

With this reasons, it's not only that a hard link to a different file system can not be created, but that it can not even exist by definition.strong text

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.