Why do the directories /home, /usr, /var, etc. all have the same inode number (2)?

I find that under my root directory, there are some directories that have the same inode number:

$ ls -aid */ .*/

2 home/ 2 tmp/ 2 usr/ 2 var/ 2 ./ 2 ../ 1 sys/ 1 proc/

I only know that the directories’ names are kept in the parent directory, and their data is kept in the inode of the directories themselves.

I’m confused here.

This is what I think when I trace the pathname /home/user1.

  • First I get into the inode 2 which is the root directory which contains the directory lists.
  • Then I find the name home paired with inode 2.
  • So I go back to the disk to find inode 2?
  • And I get the name user1 here?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

They’re on different devices.

If we look at the output of stat, we can also see the device the file is on:

# stat / | grep Inode
Device: 801h/2049d      Inode: 2           Links: 24
# stat /opt | grep Inode
Device: 803h/2051d      Inode: 2           Links: 5

So those two are on separate devices/filesystems. Inode numbers are only unique within a filesystem so there is nothing unusual here. On ext2/3/4 inode 2 is also always the root directory, so we know they are the roots of their respective filesystems.

The combination of device number + inode is likely to be unique over the whole system. (There are filesystems that don’t have inodes in the traditional sense, but I think they still have to fake some sort of a unique identifier in their place anyway.)

The device numbers there appear to be the same as those shown on the device nodes, so /dev/sda1 holds the filesystem where / is on:

# ls -l /dev/sda1
brw-rw---- 1 root disk 8, 1 Sep 21 10:45 /dev/sda1

Method 2

The inode number of any given file is unique to the filesystem, but not necessarily unique to all filesystems mounted on a given host. When you have multiple filesystems, you will see duplicate inode numbers between filesystems, this is normal.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x