what is an inode?
In Unix/*nix every file has a data structure known as i-nodes (index nodes). Each i-node stores all the information regarding a file like
- File type
- File mode or permission
- Number of links
- User ID
- Group ID
- File size
- Time stamp
- File deletion time
A file name is just a reference to the i-node. This is the reason why we can sometimes recover data even though a file is deleted. Each i-node has a number associated with it known as the i-node number. The i-node number is unique in a file system. To find the i-node number of a file, type
Example:
Sample Output
ls -i filename
Example:
ls -i /etc/passwd
2100534 /etc/passwd
You can also find the i-node number with the stat commandSo we now know i-node contains the data regarding a file. But data needs to be stored somewhere. Like any data i-node saves these information in disk drives. A space is reserved for i-nodes to save these information during the time of OS installation or during the creation of a file system. The system decides the i-node size based on an algorithm. But it is possible to change the i-node size based on your requirement. So how will we find the space reserved for i-nodes in a filesystem ? For that we use the df -i command. Given below is an example of df -i command in human-readable format and its corresponding output.
df -i
Sample Output:
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda3 33783808 104571 33679237 1% /
/dev/sdb1 71696384 102549 71593835 1% /home
/dev/sda1 26104 40 26064 1% /boot
tmpfs 893197 1 893196 1% /dev/shm
/dev/sda3 33783808 104571 33679237 1% /
/dev/sdb1 71696384 102549 71593835 1% /home
/dev/sda1 26104 40 26064 1% /boot
tmpfs 893197 1 893196 1% /dev/shm
In the above output the first column (File System) represents different filesystems mounted in the OS. The second column (Inodes) shows the total space allocated for the i-node to the respective file systems. The third column(IUsed) shows i-node space utilized out of the total space allocated. Fourth column(IFree) represents the free space left out of the total space allocated for the i-node in the file system. Fifth column (IUse %) is the percentage i-node space utilized and Sixth column (Mounted on) is the location where the file system is mounted. i.e if we take the case of /dev/sda, it has a total 33783808 bytes (32.22 MB) i-node space allocated. Out of this 33783808 bytes, only 104571 bytes (102.12 KB) of i-node space is utilized and there is a free space of 33679237 bytes (32.12 MB). Which means percentage utilization of i-node space is 1% and the file system /dev/sda3 is mounted in the location /
Suppose the total available size of /dev/sda3 file system is 125 GB. Out of the 125 GB only a small portion (33MB) is allocated for i-nodes and the rest of the space is used for data storage. So what will happen if IUse% becomes 100? or what if the entire space allocated for i-node is completely utilized? The answer is, You can no longer add new files to the file system even though there are free space left on the filesystem. This is a very rare case because the said situation occurs when there are too many files in the filesystem with small file size.
At the beginning of this post I said the i-node number of a file is unique in a file system. But the i-node number varies across different file system I will explain this with an example.
From the df -i output above you can see there are two different file systems /dev/sda3 and /dev/sdb1 mounted under the locations / and /home respectively. Consider that a file, index.html is present in /home/calypso directory. In the first step of the above screenshot we are checking the i-node number of /home/calypso/index.html file, which is 3670174. In the second step we are moving the file index.html from/home/calypso to another directory /home/foo of the same file system. In the third step you can see even though the file is moved from /home/calypso to /home/foo, there is no change in the i-node number. In the fourth step index.html is moved from /home/calypso to another directory /root. /root belongs to the file system /dev/sdb1. So the file is now shifted from /dev/sda3 to /dev/sdb1. In the fourth step if you check the i-node number of index.html file it has changed from 3670174 to 1441798. The i-node number 3670174 in /dev/sda3 will be either free or allocated to some other files. This concept has certain significance and will be discussed later while explaining about links in the next post.
What I have tried to say through this post is just some basic stuff about i-nodes. Hope you have got an idea about i-node. Thank you for reading through this post and I will be back soon with new topics.
Comments
Post a Comment