Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Free Inode Usage?

I have a disk drive where the inode usage is 100% (using df -i command). However after deleting files substantially, the usage remains 100%.

What's the correct way to do it then?

How is it possible that a disk drive with less disk space usage can have higher Inode usage than disk drive with higher disk space usage?

Is it possible if I zip lot of files would that reduce the used inode count?

like image 613
neversaint Avatar asked Mar 17 '09 05:03

neversaint


People also ask

How do you fix high inode usage?

Deleting unnecessary files and folders Your website can slowly accumulate old or unnecessary files over time, which can ultimately increase your inode usage. To fix this, you will want to locate folders with high innode usage, and then remove any unnecessary files.

What happens when inodes are full?

If all inodes in a file system are exhausted, the kernel can not create new files even when there is available space on the disk. In this short article, we will show you how to increase the number of inodes in a file system in Linux.

How do you check if inodes are full in Linux?

You can easily check inode usage using df -i command, as shown below. It will list inode usage of all disk partitions on your Linux system. In the above output, the column IUse% indicates the inode usage in Linux. If you use Ext2/Ext3/Ext4 filesystem, you can also use tune2fs utility tool.


2 Answers

If you are very unlucky you have used about 100% of all inodes and can't create the scipt. You can check this with df -ih.

Then this bash command may help you:

sudo find . -xdev -type f | cut -d "/" -f 2 | sort | uniq -c | sort -n 

And yes, this will take time, but you can locate the directory with the most files.

like image 107
simon Avatar answered Sep 26 '22 02:09

simon


It's quite easy for a disk to have a large number of inodes used even if the disk is not very full.

An inode is allocated to a file so, if you have gazillions of files, all 1 byte each, you'll run out of inodes long before you run out of disk.

It's also possible that deleting files will not reduce the inode count if the files have multiple hard links. As I said, inodes belong to the file, not the directory entry. If a file has two directory entries linked to it, deleting one will not free the inode.

Additionally, you can delete a directory entry but, if a running process still has the file open, the inode won't be freed.

My initial advice would be to delete all the files you can, then reboot the box to ensure no processes are left holding the files open.

If you do that and you still have a problem, let us know.

By the way, if you're looking for the directories that contain lots of files, this script may help:

#!/bin/bash # count_em - count files in all subdirectories under current directory. echo 'echo $(ls -a "$1" | wc -l) $1' >/tmp/count_em_$$ chmod 700 /tmp/count_em_$$ find . -mount -type d -print0 | xargs -0 -n1 /tmp/count_em_$$ | sort -n rm -f /tmp/count_em_$$ 
like image 38
paxdiablo Avatar answered Sep 27 '22 02:09

paxdiablo