Using up all the the free Inodes

Today my mind was stucked with a question. How the Linux system will behave when all the number of free inodes in a  file system has been filled up , and there are no free inodes ?.

For this I first tried to identify the number of free inodes in my system. One option for me is to use the tune2fs command to view the superblock information which will have the entry for the number of free inodes. This is a snippet of tune2fs -l from my system .

$ sudo tune2fs -l /dev/sda6
tune2fs 1.41.10 (10-Feb-2009)
Filesystem volume name:  
Last mounted on:          /home
Filesystem UUID:          f7abadee-5b6a-4c30-b117-ba097e4c6123
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
Filesystem flags:         signed_directory_hash
Default mount options:    user_xattr acl
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              640848
Block count:              2560000
Reserved block count:     128000
Free blocks:              1486042
Free inodes:              638545


The information that tune2fs provides regarding the number of free inodes is not the current information. This information was collected when the file system was mounted last, so I have to look for other commands to identify the current number of used/free inodes .  After some googling , I could find out that df has the -i option which gives the number of current free/used inodes number .

$ df -i /home/
Filesystem            Inodes   IUsed   IFree    IUse% Mounted on
/dev/sda6             640848   15004  625844    3%  /home

Now next aim is to use all the free inodes . A simple bash script will help us to fill up the number of free inodes . The scripts looks like this:

$for i in {1..625844} ; do echo $i ; touch test$i ; done

Phew, after executing the script I can see the number of free inodes are getting decreased . It had taken around 30 minutes in my dual core desktop to use up all the free inodes. The result is that it created a lots of test files in my home directory but that should not be an issue as these are empty files and I will clear them after I am done with my task.

df -i shows that the all the inodes has been used up and there are no free inodes .

$ df -i /home/
Filesystem            Inodes   IUsed   IFree IUse% Mounted on
/dev/sda6             640848  640848       0  100% /home

Now, let us try a create file and see how the system behaves since all the inodes has been used up .

$ touch great
touch: cannot touch `great': No space left on device

The errors says that no disk space is left . This is quite surprising as df is telling that free space is available .

$ df -h /home/
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda6             9.7G  6.0G  3.2G  66% /home

The issue here is that there are no free inodes rather than free disk space. The error is confusion , should have reported that no free inodes left. May be if any kernel guru accidently goes through my article , can comment regarding this behavior. 

Last I rebooted the host to check whether tune2fs reports the number of free inodes as zero .

$ sudo tune2fs -l /dev/sda6
[sudo] password for man:
tune2fs 1.41.10 (10-Feb-2009)
Filesystem volume name:  
Last mounted on:          /home
Filesystem UUID:          f7abadee-5b6a-4c30-b117-ba097e4c6123
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
Filesystem flags:         signed_directory_hash
Default mount options:    user_xattr acl
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              640848
Block count:              2560000
Reserved block count:     128000
Free blocks:              957962
Free inodes:              0

So , the reporting for tune2fs is as expected after the reboot . There are no free inodes . 

So , I am done with what I am trying to achieve . Able  to identify the behavior of a Linux system 
when  all the free inodes has been used up.


P.S  : I tried to delete those empty test files that I created but while removing seeing some error .

Will write another post how I deleted those files.


$ rm -f  test* 
-bash: /bin/rm: Argument list too long
 rm: missing operand
Try `rm --help' for more information.
 

Comments