30

I cannot update Ubuntu because I have 99% inode usage. What is the easiest way for me to alleviate this problem?

Thanks for your help.

4

4 Answers 4

27

The number of inodes is set at the time the partition is formatted. Normally the number of inodes created is sufficient for almost any purpose; however, if you have a great number of very small files then you can use up the inodes before the disk is full.

You need to find the many thousands of small files you have on the system that are using up inodes and either delete them, or move them to a partition that has been specifically set up with a very large number of inodes available. It is not possible to change the number of inodes available on a partition after it has been formatted.

The script written by paxdiablo on stackoverflow might be handy way to check for excessive small file use that you may not be aware of. Here it is again:

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

Put this script in the text file ~/bin/count_em and then issue the command

chmod +x ~/bin/count_em

to make it executable. If you had to make the directory ~/bin then it won't be in the executable path yet, so just log out and back in again.

To run the program you just type

count_em

and it will list the numbers of all files in the current directory and subdirectories by directory, with the highest count last. Very handy!

5
  • THIS LINE > chmode +x ~/bin/count_em is actually > chmod +x ~/bin/count_em
    – user169677
    Jun 23, 2013 at 20:15
  • 1
    is it necessary to delete all of those user-created files, or will moving them into tar archive do the trick?
    – amc
    Jun 23, 2013 at 20:18
  • Archiving them is a great way to deal with it, it doesn't delete users data but makes them aware that their behaviour isn't satisfactory as they wont be able to use the files as they were previously. Chances are though that the huge number of files is generated by something no one is using and they could be safely deleted, but that is a risk.
    – LovesTha
    Jul 23, 2014 at 0:06
  • A good single line alternative to your script might be sudo du -a -d 1 --inodes . | sort -nr | head -20 Aug 22, 2017 at 20:15
  • 1
    Of course, this doesn't work if you're completely out of inodes since it creates temporary files :(
    – Molomby
    May 9, 2019 at 1:10
12

You can also display a sorted list of directories by number of inodes, using this command: du --inodes -d 3 / | sort -n | tail

From there, you can determine which directories to delete

3
  • 2
    unrecognized option '--inodes' on Ubuntu 14.04, fyi
    – Molomby
    May 9, 2019 at 1:11
  • 2
    Why are you using ubundu 14.04 in 2019? I see it has coreutils 8.21 from Feb 2013, the --inodes option was added Jul 2013 lmao
    – ZN13
    Jun 4, 2019 at 14:05
  • df --inodes instead of du --inodes.
    – Rick James
    Jun 22, 2021 at 15:50
3

When you've run out of inodes, you have two options:

  1. Either remove some files from the disk (typically small files).
  2. Reformat the affected drive, allowing for more inodes.

Option 1 are discussed in other answers here, but no answers address option 2 - which I will do here.

For this example, let's say the affected disk is /dev/sda1.

To give a certain number of inodes when formatting, you can use the command mke2fs with either the -i option or the -N option. From the manpage:

-i bytes-per-inode
      Specify  the  bytes/inode ratio.  mke2fs creates an inode for every bytes-per-inode
      bytes of space on the disk.  The larger the bytes-per-inode ratio, the fewer inodes
      will  be  created.  This value generally shouldn't be smaller than the blocksize of
      the file system, since in that case more inodes would be  made  than  can  ever  be
      used.   Be  warned  that  it  is not possible to change this ratio on a file system
      after it is created, so be careful deciding the correct value for  this  parameter.
      Note  that  resizing  a  file  system changes the number of inodes to maintain this
      ratio.

-N number-of-inodes
      Overrides  the  default calculation of the number of inodes that should be reserved
      for the file system (which is based on the number of blocks and the bytes-per-inode
      ratio).  This allows the user to specify the number of desired inodes directly.

So to format the device using the default number of inodes (16384 bytes / inode), use the normal command: (for a 1 TB disk, this will create roughly 60 million inodes)

sudo mke2fs -t ext4 /dev/sda1

To create the partition with the double amount of inodes than previously, use this command: (note that the bytes/inode value must then be half - for a 1 TB disk, this will create roughly 120 million inodes)

sudo mke2fs -i 8192 -t ext4 /dev/sda1

And finally, to set the specific amount of inodes manually, use this command: (to create a filesystem with 200 million inodes)

sudo mke2fs -N 200000000 -t ext4 /dev/sda1
0
2

I found that the inode usage was coming from /root/.local, and deleted that folder.

1
  • 2
    Nothing much should be using /root/.local and it's only there for compatibility reasons. You need to find out what was writing many tiny files to this directory. Dec 22, 2012 at 4:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .