6

I'm learning about Linux filesystems, with these sources:

http://linuxgazette.net/issue21/ext2.html
http://homepage.smc.edu/morgan_david/cs40/analyze-ext2.htm 

But I have one question about the root directory: why is its inode number always two? Why not one, or another number?

xy2
  • 6,040
  • 3
  • 14
  • 34
Maverick
  • 575
  • 1
  • 11
  • 27
  • 1
    There is no hard and fast rule.Inode number assignment is filesystem specific.See http://stackoverflow.com/questions/2099121/why-do-inode-numbers-start-from-1-and-not-0 – itisravi Oct 07 '12 at 12:59

1 Answers1

19

The first inode number is 1. 0 is used as a NULL value, to indicate that there is no inode. Inode 1 is used to keep track of any bad blocks on the disk; it is essentially a hidden file containing the bad blocks, so that they will not be used by another file. The bad blocks can be recorded using e2fsck -c. The filesystem root directory is inode 2.

The meaning of particular inode numbers differs by filesystem. For ext4 you can find more information on the Ext4 Wiki Ext4 Disk Layout page; in particular see the "Special inodes" table.

mark4o
  • 58,919
  • 18
  • 87
  • 102