Modifying the inode count for an ext2/ext3/ext4 file system

Modifying the inode count for an ext2/ext3/ext4 file system

Updated  - 

If you run low or completely exhaust the available inodes (index nodes) on your ext2/ext3/ext4 file system, you will see No space left on device errors even though it appears you have plenty of free space. This specific failure is described in "No space left on device" errors when copying or creating files on ext2/ext3/ext4 file system due to insufficient available inodes.

An inode is a data structure on an ext2/ext3/ext4 file system. It provides information about a file or directory. Each file or directory uses one inode. If your disk has or will have a large number of very small or empty files and directories, you could very easily get into a situation where all the available inodes allocated on your file system get used up and no new files or directories can be created.

If your file storage use-case will require you to continuously create small or empty files, you should plan accordingly and create your file system using an appropriate inode ratio.

It is important to understand that once a file system has been created its inode ratio, which is the ratio of available inodes to total disk space, is fixed. The inode count, the maximum number of inodes that a file system can use, can only be changed by extending the file system.

If you have run out of inodes on an existing file system, you can typically address the issue by removing or archiving files that are no longer necessary. However, you may still be at risk of exhausting the available inodes in the future. In that case you may want to consider creating a new file system with a more appropriate inode ratio based on your use-case or, if using LVM (Logical Volume Management) and you have space that has not been allocated, you can extend the file system on your logical volume.

Removing or archiving files

Locate any files on the affected file system that can be safely removed or archived. You can search for empty or small files by using the -size argument of the find command along with -xdev to force find to remain on the same file system.

# find /home -xdev -type f -size 0
# find /home -xdev -type f -size -1k

Directory entries will use inodes as well. To find empty directories:

# find /home -xdev -type d -empty

You will need to analyze the results and determine which files or directories can be archived or moved. Remember, some empty files may serve as locks or include other state information for running processes and services. You should only remove files or directories once you are certain they are no longer needed and proper backups have been created.

Creating a file system with more inodes

WARNING This destroys and recreates the file system, which means that all files on the file system are lost. Be certain you have a complete backup of all files and directories on the target file system before proceeding!

The number of inodes can be specified directly by providing inode count or by specifying the inode ratio. Default values can be found and edited in /etc/mke2fs.conf.

Specify inode count on file system creation

On file system creation, -N <inode-count> can be passed as an argument to the mkfs command. For example:

# mkfs.ext3 -N <inode_count> /dev/sda10

Specify inode ratio on file system creation

On file system creation, -i <bytes-per-inode> can be passed as an argument to the mkfs command. For example:

# mkfs.ext3 -i <bytes-per-inode> /dev/sda10\

See Calculating inode ratio

Calculating inode ratio

To use <bytes-per-inodes>, you will need to calculate your ratio. Smaller values, mean more available inodes. Larger values, mean fewer available inodes. But you should not use a value smaller than the file system's block size.

To calculate <bytes-per-inodes> you can use the following formula:

<bytes-per-inode> = <block count> x <block size> / <inode count>

If you are recreating an existing file system you can get its current block count and block size along with its inode count to determine what the existing ratio is. The dumpe2fs command can be used to retrieve the necessary values:

dumpe2fs /dev/sda10 | grep -E "(Block count|Block size|Inode count)"
dumpe2fs 1.39 (29-May-2006)
Inode count:              1224000
Block count:              2443880
Block size:               4096

You can now plug the numbers from the above output into the formula to determine the current <bytes-per-inode> ration for the file system on /dev/sda10.

2443880 x 4096 / 1224000 = 8178.212810458

With rounding we can just call this 8K. If we wanted to double the available inodes we could use a ratio of 4K.

<bytes-per-inode> = <block count> x <block size> / <inode count>
      4096        =    2443880    x     4096     / <inode count>

2443880 x 4096 = 10010132480 / 4096 = 2443880

      4096        =    2443880    x     4096     /    2443880

Extend/Resize filesystem{#extend-filesystem}

When the file system is extended the number of inodes will also increase. This procedure requires that there is free space available for extending the LV (logical volume) on which the file system resides. For help with extending the LV, see How to extend a logical volume and its filesystem online in Red Hat Enterprise Linux?

0 (0)
Article Rating (No Votes)
Rate this article
There are no attachments for this article.
There are no comments for this article. Be the first to post a comment.
Full Name
Email Address
Security Code Security Code
Related Articles RSS Feed
Terminal based "The Matrix" like implementation
Viewed 579 times since Thu, Apr 18, 2019
debian Install a newer kernel in Debian 9 (stretch) stable
Viewed 532 times since Sun, Sep 23, 2018
Understanding logrotate utility part 1
Viewed 544 times since Fri, Nov 30, 2018
Easily Find Bugs In Shell Scripts With ShellCheck
Viewed 759 times since Thu, Apr 18, 2019
ZPOOL: Create a new zpool for zfs filesystems
Viewed 860 times since Sun, Jun 3, 2018
LVM: Remove an existing Volume Group
Viewed 776 times since Sat, Jun 2, 2018
Turbocharge PuTTY with 12 Powerful Add-Ons – Software for Geeks #3
Viewed 1188 times since Sun, Sep 30, 2018
LVM: Reduce an existing Logical Volume / Filesystem
Viewed 746 times since Sat, Jun 2, 2018
Open SSL Encrypt & Decrypt Files With Password Using OpenSSL
Viewed 966 times since Mon, Feb 18, 2019
What UUIDs can do for you
Viewed 544 times since Tue, Jul 17, 2018