Quick question about inodes and links

Hey everyone. Long time no see. I’m currently self-studying for the RHCSA and I want to double make sure my understanding of inodes and links is correct.

Basically, are all computer files(in user space) just containers of inodes that point to the actual data in the computer?

Let’s say I have a video file in /home/myname called “myvideo.mp4”. With my current understanding, “myvideo.mp4” is just a cover that points (stores an inode) to the actual data of the video somewhere in the computer.

If I make a soft link to “myvideo.mp4” called “soft”, then soft simply points to the file location of “myvideo.mp4” aka /home/myname/myvideo.mp4.

If I make a hard link to “myvideo.mp4” called “hard”, then hard points (stores the inode) to the actual data of “myvideo.mp4” somewhere on my system.

Is this understanding correct?

And if so, how exactly does a soft link connect to the original file? Does it just store the file path to “myvideo.mp4”, aka /home/myname/myvideo.mp4, or does it store another inode that points to “myvideo.mp4”, but not the actual data of “myvideo.mp4”?

This man page has all the answers you need.

https://man7.org/linux/man-pages/man7/symlink.7.html

A hard link doesn’t store the inode (the data structure) directly. It contains the inode number instead. An inode number is an index in an inode table. The inode (the actual data structure containing the file’s metadata) is stored in that table. An inode number is just a piece of information that allows the system to access an inode from the inode table. The fact that hard links store inode numbers is the reason why creating hard links across filesystems isn’t allowed—to prevent inode number clashes since the same inode number on one filesystem might already be in use on another filesystem. If it were allowed, it would lead to ambiguities that the system would not be able to resolve. For example, if hard link X refers to inode number 123456, and both filesystem A and filesystem B have an entry for 123456 in their inode tables, which inode should be read?

A soft/symbolink link does not reference an inode. It is a special file containing a string that is the pathname of the file it points to. Since a symbolic link is itself a file, it also has its own inode number, but this inode number has nothing to do with the file it points to. The opposite is true for hard links. Two hard links reference the same inode number.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.