17

If I run a command like this one:

find / -inum 12582925

Is there a chance that this will list two files on separate mounted filesystems (from separate partitions) that happen to have been assigned the same number? Is the inode number unique on a single filesystem, or across all mounted filesystems?

marked as duplicate by Jeff Schaller, schily, Thomas, Isaac, G-Man Aug 26 '18 at 18:48

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

39

An inode number is only unique on a single file system. One example you’ll run into quickly is the root inode on ext2/3/4 file systems, which is 2:

$ ls -id / /home
2 /    2 /home

If you run (assuming GNU find)

find / -printf "%i %p\n" | sort -n | less

on a system with multiple file systems you’ll see many, many duplicate inode numbers (although you need to take the output with a pinch of salt since it will also include hard links).

When you’re looking for a file by inode number, you can use find’s -xdev option to limit its search to the file system containing the start path, if you have a single start path:

find / -xdev -inum 12582925

will only find files with inode number 12582925 on the root file system. (-xdev also works with multiple start paths, but then its usefulness is reduced in this particular case.)

It's the combination of inode number and device number (st_dev and st_ino in the stat structure, %D %i in GNU find's -printf) that identifies a file uniquely (on a given system). If two directory entries have the same inode and dev number, they refer to the same file (though possibly through two different mounts of a same file system for bind mounts).

Some find implementations also have a -samefile predicate that will find files with the same device and inode number. Most [/test implementations also have a -ef operator to check that two files paths refer to the same file (after symlink resolution though).

4

Yes, the same inode number may appear at a different filesystem. If you want to specify the exact, you not only need the inode number (st_ino) but also the device where the inode resides (st_dev, itself formed by dev_major —the general class of device— and dev_minor —the specific instance—).

The couple (st_dev, st_ino) will identify a specific file (at least if you don't unmount the filesystem where this inode resides).

As stated on inode(7):

Device where inode resides

Each inode (as well as the associated file) resides in a filesystem that is hosted on a device. That device is identified by the combination of its major ID (which identifies the general class of device) and minor ID (which identifies a specific instance in the general class).

Inode number

Each file in a filesystem has a unique inode number. Inode numbers are guaranteed to be unique only within a filesystem (i.e., the same inode numbers may be used by different filesystems, which is the reason that hard links may not cross filesystem boundaries).

  • If inodes weren't only unique to the filesystem, you couldn't safely move filesystems from one computer to another (which you can do, by physically moving a drive from one machine to another, or -- in VMware -- detaching a LUN from one VM and attaching it to another). – RonJohn Aug 24 '18 at 19:07

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