Increasing the number of inodes

If you are keeping huge number of small files in your disks, this may one day cause running out of available inodes because of which even though you might have sufficient disk space, file system cannot create new files. Lets see how it works in my 1GB disk partition.

The parameter “-i” allows us to play with the number of inodes we can have in a partition. It is called “bytes-per-inode”. The bigger it is less number of inodes you will have. I have set a relatively big size “163840” bytes per inode and the result is I have 6768 inodes. What this means indeed is I can’t create more than 6768 files. (even a bit less than this)

root@deb2:/mnt# mkfs.ext3 -i 163840 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
6768 inodes, 265064 blocks
13253 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=272629760
9 block groups
32768 blocks per group, 32768 fragments per group
752 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376

Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 34 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

If you don’t believe me, lets do a test. I will mount this partition and create this number of files;

root@deb2:/mnt# mount /dev/sdb1 /mnt/sdb1
root@deb2:~# cd /mnt/sdb1

root@deb2:/mnt/sdb1# for i in {1..6768}; do touch $i ; done
touch: cannot touch `6758': No space left on device
touch: cannot touch `6759': No space left on device
touch: cannot touch `6760': No space left on device
touch: cannot touch `6761': No space left on device
touch: cannot touch `6762': No space left on device
touch: cannot touch `6763': No space left on device
touch: cannot touch `6764': No space left on device
touch: cannot touch `6765': No space left on device
touch: cannot touch `6766': No space left on device
touch: cannot touch `6767': No space left on device
touch: cannot touch `6768': No space left on device

As you can see, when we can only create 6757 files and 6758. file isn’t allowed. It says no space left!! which is incorrect indeed lets have a look;

root@deb2:/mnt/sdb1# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda1               330215    121232    191934  39% /
tmpfs                   228892         0    228892   0% /lib/init/rw
udev                    224444       188    224256   1% /dev
tmpfs                   228892         0    228892   0% /dev/shm
/dev/sda9              6137152    143404   5681992   3% /home
/dev/sda8               376807     10291    347060   3% /tmp
/dev/sda5              5826760    677712   4853064  13% /usr
/dev/sda6              2791904    220568   2429512   9% /var
/dev/sdb1              1058452     34240    971200   4% /mnt/sdb1

Only %4 of the disk space is in USE, the problem is more clear once you see the inode usage;

root@deb2:/mnt/sdb1# df -i
Filesystem            Inodes   IUsed   IFree IUse% Mounted on
/dev/sda1              85344    5658   79686    7% /
tmpfs                  57223       5   57218    1% /lib/init/rw
udev                   56111     698   55413    2% /dev
tmpfs                  57223       1   57222    1% /dev/shm
/dev/sda9             390144      15  390129    1% /home
/dev/sda8              97536      13   97523    1% /tmp
/dev/sda5             370208   37444  332764   11% /usr
/dev/sda6             177408    6692  170716    4% /var
/dev/sdb1               6768    6768       0  100% /mnt/sdb1

Here it is. Inode usage is %100 there is no inode left. If you set a smaller bytes-per-inode ratio, you can have more inodes. It is also worth to mention the file containing these default values with which you can play and set default values;

root@deb2:/mnt/sdb1# head /etc/mke2fs.conf
[defaults]
base_features = sparse_super,filetype,resize_inode,dir_index,ext_attr
blocksize = 4096
inode_size = 256
inode_ratio = 16384

About: rtoodtoo

Worked for more than 10 years as a Network/Support Engineer and also interested in Python, Linux, Security and SD-WAN, currently living in the Netherlands and works as a Network Support Engineer. // JNCIE-SEC #223 / RHCE / PCNSE


One thought on “Increasing the number of inodes”

You have a feedback?

This site uses Akismet to reduce spam. Learn how your comment data is processed.