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
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
Logrotate Example for Custom Logs
Viewed 2334 times since Sun, Jan 12, 2020
Linux An introduction to swap space on Linux systems
Viewed 2167 times since Thu, Jan 23, 2020
rabbitmq Troubleshooting TLS-enabled Connections
Viewed 2081 times since Sun, Dec 6, 2020
Watchdog script to keep an application running
Viewed 17876 times since Tue, Jul 31, 2018
How To Create a Linux Swap File
Viewed 2179 times since Fri, Jun 8, 2018
RHEL: Reinstalling Boot Loader on the Master Boot Record (MBR)
Viewed 3049 times since Sun, May 27, 2018
systemctl Use systemd to Start a Linux Service at Boot
Viewed 5427 times since Mon, Dec 7, 2020
Fedora 32: Simple Local File-Sharing with Samba CIFS Linux
Viewed 8466 times since Sun, Dec 6, 2020
How To Run Multiple SSH Command On Remote Machine And Exit Safely
Viewed 3913 times since Tue, Aug 6, 2019
LVM: Mount LVM Partition(s) in Rescue Mode
Viewed 4468 times since Sat, Jun 2, 2018