1824359 Members
3240 Online
109669 Solutions
New Discussion юеВ

why inode 2 for root

 
Vijaya Kumar_3
Respected Contributor

why inode 2 for root

Hi

I was just wondering someone gimme an answer for this question..
I referred many unix flavors and the inode for / is always 2.
$ ls -id
2 .
$ pwd
/
$
I need an answer for this? I also notice some other directories under root are having inode 2...any reasons...
Thanks in advance
Vijay
Known is a drop, unknown is ocean - visit me at http://vijay.theunixplace.com
6 REPLIES 6
doug mielke
Respected Contributor

Re: why inode 2 for root

the other '2's under / should be mount points. Inode numbers are not duplicated in a specific filesystem.

Joris Denayer
Respected Contributor

Re: why inode 2 for root

Vijay,

The inode number givven to the top directory of your filesystem is entirly file-system dependent.
Anyway, each filesystem on your system as a top-directory and will have this inodenumber for it's topdirectory.

Why do you see multiple 2's ?
Well, these are the directories on which other filesystems are mounted. The inode of the topdirectory of the mounted filesystem is mapped over the inode of the mount-point.

As a test, you could simply umount such a filesystem, if not in use of course. And you will see that it's inode number is not longer 2, but something else.
Mount the filesystem again on it's mountpoint, and the mountpoint directory's inode is again 2.

There exist also good books about the in's and out's of the UNIX OS, where this is explained in extenso.

Joris

To err is human, but to really faul things up requires a computer
curt larson_1
Honored Contributor

Re: why inode 2 for root

the inode for the mount point for every file system will be 2, i.e. /. The same as for /var, /usr, /opt, etc. if they are seperate file systems. Why? I'm not sure, other then, the mount point is always the first entry in the file system, except for the superblock info.
A. Clay Stephenson
Acclaimed Contributor

Re: why inode 2 for root

I suppose the real question is why not 1? Inode 1 is used for the bad blocks list. Inode 2 is always the root inode for any filesystem. Depending upon the OS and filesystem type other low-number inodes are used for other purposes.
If it ain't broke, I can fix that.
Kevin Wright
Honored Contributor

Re: why inode 2 for root

You'll have to ask the engineers at AT&T ro Berkeley I suppose. It's just convention as to why they chose the number 2.
PVR
Valued Contributor

Re: why inode 2 for root

All file system's root directory will be using inode 2.

reason might be.....

Accessing a file in Unix start by searching it's entry in the directory. Each directory's inode or it's datablock contains all it's member filenames and their inode. So it has to be a permanent inode.

I don't know where inode 1 is used!!!??

Don't give up. Try till success...