Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is root directory always stored in inode two?

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?

like image 421
Maverick Avatar asked Oct 07 '12 11:10

Maverick


People also ask

Is root directory an inode?

The filesystem root directory is inode 2. The meaning of particular inode numbers differs by filesystem.

What is the root inode number * 2?

Inode 1 is used to keep track of any bad blocks on the disk; it is essentially a hidden file containing the bad blocks. Those bad blocks which are recorded using e2fsck -c . Inode 2 is used by the root directory, and indicates starting of filesystem inodes.

Can two directories have the same inode?

2 files can have the same inode, but only if they are part of different partitions. Inodes are only unique on a partition level, not on the whole system.

How can you find the inode for the root directory?

To get the number of inodes of files in a directory, for example, the root directory, open a terminal window and run the following ls command, where the -l option means long listing format, -a means all files and -i mean to print the index number of each file.


1 Answers

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.

like image 155
mark4o Avatar answered Oct 17 '22 00:10

mark4o