Why do the directories /home, /usr, /var, etc. all have the same inode number (2)?
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
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.