Linux System Administration

0 of 83 lessons complete (0%)

Managing Unix File Systems

inode block

You don’t have access to this lesson

Please register or sign in to access the course content.

An inode (index node) is a data structure that stores metadata about files and directories in a file system. Every file and directory has an associated inode, and this inode contains crucial information about the file, but not the file name or its content.

What Information Does an Inode Contain?

  1. File type (regular file, directory, symbolic link, etc.)
  2. Permissions (read, write, execute for owner, group, others)
  3. Owner (user ID and group ID)
  4. File size
  5. Number of hard links (how many directory entries point to the inode)
  6. Timestamps (created, modified, accessed times)
  7. Pointers to data blocks (the actual location of the file data on the disk)

The inode number is a unique identifier for each inode within a file system, and the file system uses this number to access the inode’s metadata.

How Inodes Work:

  • When you create a file, the file system assigns it an inode number.
  • The file’s directory entry contains the file name and the inode number, but the actual data of the file is stored in data blocks elsewhere on the disk.
  • The inode does not store the file’s name; that information is kept in the directory structure, which maps file names to inode numbers.

For example, when you run a command like ls -l, the system retrieves file metadata (like file size, permissions, and owner) from the inode.

Inode Commands:

  1. Check the Inode Number of a File: To display the inode number of a file:
ls -i filename

Example:

ls -i /home/nishant/file.txt
  1. View Inode Information: To display detailed inode information for a file:
stat filename

Example:

stat /home/nishant/file.txt

Output may look like:

File: '/home/nishant/file.txt'
Size: 4096        Blocks: 8          IO Block: 4096   regular file
Device: 802h/2050d    Inode: 1234567    Links: 1
Access: (0644/-rw-r--r--)  Uid: (1000/nishant)   Gid: (1000/nishant)

Inode Structure:

  • Direct Pointers: The inode contains pointers that point directly to the data blocks where the file’s content is stored.
  • Indirect Pointers: If the file is large and requires more blocks, the inode contains pointers to indirect blocks, which in turn point to additional data blocks.

Limits of Inodes:

  • Each file system has a fixed number of inodes, set when the file system is created. If all the inodes are used up, no new files can be created on the system, even if there is disk space left. You can check the inode usage with the command:
df -i