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?

1 (1)
Article Rating (1 Votes)
Rate this article
Attachments
There are no attachments for this article.
Comments
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
Improve security with polyinstantiation
Viewed 13116 times since Fri, May 15, 2020
How to Configure ‘FirewallD’ in RHEL/CentOS 7 and Fedora 21
Viewed 10321 times since Wed, Oct 9, 2019
Creating SWAP partition using FDISK & FALLOCATE commands
Viewed 3273 times since Thu, Jan 16, 2020
zabbix linux How to solve apache error No space left on device: Cannot create SSLMutex
Viewed 2302 times since Wed, Nov 11, 2020
How to use yum-cron to automatically update RHEL/CentOS Linux
Viewed 2582 times since Wed, Oct 17, 2018
chrt command: Set / Manipulate Real Time Attributes of a Linux Process
Viewed 10898 times since Mon, Feb 17, 2020
RHCS6: Debug and test multicast traffic between two hosts
Viewed 6523 times since Sun, Jun 3, 2018
Deskshare TLS over Stunnel
Viewed 2692 times since Fri, Sep 28, 2018
Script to Offline and Remove A Disk In Linux
Viewed 1868 times since Mon, Jan 28, 2019
awk printf
Viewed 14924 times since Wed, Aug 19, 2020