Can two files on two separate filesystems share the same inode number? [duplicate]

Can two files on two separate filesystems share the same inode number? [duplicate]



This question already has an answer here:



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?



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.




2 Answers
2



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


find / -printf "%i %pn" | 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


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.)


-xdev



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).


st_dev


st_ino


stat


%D %i


find


-printf



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).


find


-samefile


[


test


-ef



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 at 19:07

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

How do I collapse sections of code in Visual Studio Code for Windows?

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ