0

I have a work laptop that I will soon have to return to my employer. Having foreseen this, I ordered a second internal disk and mounted it at /home/<user> so that I can just pull it out and mount it in the next machine without having to go through the whole ritual of copying files, etc.

However, I've created a few projects with hard links -- all files are on this secondary mounted disk, so it's like ~/project-one/orig-file.txt => ~/project-two/linked-file.txt

I know that such links don't work across file systems, i.e. you can't link from the root and a mounted disk (Google gets me a lot of articles about this), but the question is, will pulling this disk and mounting it in another system break these hard links? Will potentially use the same distro and /home/<user> directory if that makes a difference. Of course, I will really find out when it comes time to swap out the disk, but it will be good to mentally prepare for what to expect.

dr_
  • 29,602
Bob
  • 3

1 Answers1

1

So, you have a hard disk, formatted with a filesystem, in which there are hard links (confined within the filesystem, of course).

If you remove this hard disk from a system and mount it in another system, it will continue working exactly as before, provided that both systems recognize correctly the filesystem. If it's the same distro, or even two different Linux distros, it's sure to be okay. As added by @Hans-Martin_Mosner, it does not even need to be mounted on the same mountpoint as the old system, as all hard links are inside the inode structure of the filesystem.

Note that hard links aren't anything obscure or bizarre -- a normal filesystem is full of them, for instance the .. in every subdirectory that links to the parent dir.

dr_
  • 29,602
  • 1
    To add, it doesn't even matter whether the disk is mounted at the same mount point in the new system - hard links will continue to work. Soft links, however, are affected by mounting the link target at a different mount point. – Hans-Martin Mosner Jun 05 '23 at 13:07
  • This is most excellent news! Thanks dr_ and @Hans-MartinMosner, – Bob Jun 05 '23 at 15:01
  • .. aren't hard links, you can not have a hard link to a directory. – Oliver Knodel Jun 05 '23 at 16:11