Coder Perfect

How do I get Inode Usage for Free?

Problem

I have a disk drive with a 100% inode utilization rate (using df -i command). However, even after eliminating a large number of files, the use remains at 100%.

So, what’s the proper procedure?

How can a disk drive with a lower disk space consumption have a greater Inode utilization than a disk drive with a higher disk space usage?

Is it possible that compressing a large number of files will minimize the amount of inode space used?

Asked by neversaint

Solution #1

If you’re really unlucky, you’ll have used up all of the inodes and won’t be able to build the script. df -ih can be used to verify this.

Then the following bash command might be useful:

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

Yes, it will take some time, but you will be able to find the directory with the most files.

Answered by simon

Solution #2

Even if the disk isn’t extremely full, it’s easy for a disk to have a big number of inodes utilised.

Because an inode is assigned to each file, if you have a large number of files, each of which is 1 byte in size, you’ll run out of inodes much before you run out of disk space.

If the files have many hard links, it’s also likely that deleting them won’t reduce the inode count. Inodes, as previously said, belong to the file, not the directory entry. If a file is connected to two directory entries, deleting one of them will not release the inode.

You can also delete a directory entry, however the inode will not be released if the file is still open due to an ongoing process.

My first piece of advice is to delete all of the files you can, then reboot the computer to check that no programs are still open that are holding the files open.

If you try that and still have a problem, please contact us.

By the way, this script may be useful if you’re seeking for directories with a lot of files:

#!/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_$$

Answered by paxdiablo

Solution #3

My predicament was that I had run out of inodes and had purged nearly all I could.

$ df -i
Filesystem     Inodes  IUsed  IFree IUse% Mounted on
/dev/sda1      942080 507361     11  100% /

I’m using Ubuntu 12.04LTS and couldn’t get rid of the old linux kernels, which took up about 400,000 inodes, because apt was malfunctioning due to a missing package. And because I ran out of inodes, I couldn’t install the new package, thus I was trapped.

I ended up deleting a few old linux kernels by hand to free up about 10,000 inodes

$ sudo rm -rf /usr/src/linux-headers-3.2.0-2*

This was sufficient to allow me to install the missing package and correct my apt configuration.

$ sudo apt-get install linux-headers-3.2.0-76-generic-pae

then use apt to remove the rest of the old linux kernels

$ sudo apt-get autoremove

Things have greatly improved since then.

$ df -i
Filesystem     Inodes  IUsed  IFree IUse% Mounted on
/dev/sda1      942080 507361 434719   54% /

Answered by LNamba

Solution #4

My solution:

Check to see whether this is an inodes issue with:

df -ih

Look for root folders with a lot of inodes:

for i in /*; do echo $i; find $i |wc -l; done

Attempt to locate certain folders:

for i in /src/*; do echo $i; find $i |wc -l; done

If you’re dealing with linux headers, try removing the oldest with:

sudo apt-get autoremove linux-headers-3.13.0-24

Personally, I transferred them to a mounted folder (since the previous command didn’t work for me) and installed the most recent version with:

sudo apt-get autoremove -f

This was the solution to my problem.

Answered by dardarlt

Solution #5

I experienced the identical issue and was able to resolve it by eliminating the php sessions directory.

rm -rf /var/lib/php/sessions/

If you’re using an older PHP version, it can be in /var/lib/php5.

Recreate it with the permissions listed below.

mkdir /var/lib/php/sessions/ && chmod 1733 /var/lib/php/sessions/

On Debian, the default permissions for a directory were drwx-wx-wt (1733)

Answered by Anyone_ph

Post is based on https://stackoverflow.com/questions/653096/how-to-free-inode-usage