Inodes basically store information about files and folders, such as (user and group) ownership, access mode (read, write, execute permissions) and file type. On many types of file systems the number of inodes available is fixed at file system creation, limiting the maximum number of files the file system can hold. The inode number indexes a table of inodes in a known location on the device; from the inode number, the kernel can access the contents of the inode, including the location of the file allowing access to the file. A file’s inode number can be found using the ls -i command. The ls -l command displays some of the inode contents for each file. Stat will show a more complete listing of file attributes, including the inode number, number of blocks it occupies and block size.
[[email protected]] ~ >> stat .bashrc
Size: 325 Blocks: 8 IO Block: 4096 regular file
Device: ca03h/51715d Inode: 293879 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2011-01-06 09:39:35.000000000 -0500
Modify: 2010-07-28 13:51:44.000000000 -0400
Change: 2010-08-27 16:16:18.000000000 -0400
File names and directory implications:
* Inodes do not contain file names, only file metadata.
* Unix directories are lists of “link” structures, each of which contains one filename and one inode number.
* The kernel must search a directory looking for a particular filename and then convert the filename to the correct corresponding inode number.
* The kernel’s in-memory representation of this data is called struct inode in Linux.
We can find the inode usage (Number of files) owned by each user/directory, especially useful in VPS. Each VPS will have inode limits (the maximum number of files that can be created in that VPS)
For example If the inode usage is 100 % then we needs to find out which user/directory has owned the maximum number of files.
[[email protected]]# df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/vzfs 800000 800000 0 100% /
simfs 800000 800000 0 100% /tmp
simfs 800000 800000 0 100% /var/tmp
Run the following commands
[[email protected] ~]# repquota -a | sort -nk6 | head
Block limits File limits
*** Report for user quotas on device /dev/vzfs
Block grace time: 00:00; Inode grace time: 00:00
User used soft hard grace used soft hard grace
test1 +- 25816 25600 25600 none 663 0 0
test2 – 4 0 0 1 0 0
mail – 4 0 0 1 0 0
In my case the user mailnull (the system user used by exim to store queued emails) owned maximum number of files as there were around 30000 emails in the mail queue. From the command output shown below the mailnull user has the inode usage of 89971.
[[email protected] ~]# repquota -a | sort -nk6 | tail
test10 – 375660 4096000 4096000 23463 0 0
test11 – 482460 1024000 1024000 28043 0 0
test12 – 652580 1024000 1024000 29378 0 0
test13 – 286200 4096000 4096000 33996 0 0
test14 – 591400 819200 819200 39027 0 0
test15 — 1528680 0 0 39027 0 0
test16 — 1941748 8192000 8192000 46401 0 0
test17 – 626240 0 0 58163 0 0
mailnull — 1236324 0 0 89971 0 0
root — 3563516 0 0 128345 0 0
[[email protected] ~]#exim -bpc
After mailnull the next user who has owned maximum number of files is test17 (58163). Now need to find out which directory contains maximum number of files.
[[email protected] ~]# cd /home/test17
[[email protected] /home/test17]# for d in *; do echo -n “$d: “; find $d -type f | wc -l; done ( This script will display
the directory/file and count the number of files inside that directory )
Here again public_html directory contains the maximum number of files.
[[email protected] /home/test17]#cd public_html
[[email protected] /home/test17/public_html]# for d in *; do echo -n “$d: “; find $d -type f | wc -l; done | sort -nk2 | tail -5
Finally the directory x7 contains the maximum number of files (inodes). Similarly by using this method we can find out which user/directory owns the maximum number of files in any linux server. This command might be helpful to you in finding the folder using a great part of the inodes. It outputs the top 5 file system objects utilizing the most inodes in the current folder:
for i in `ls -1A`; do echo "`find $i | sort -u | wc -l` $i"; done | sort -rn | head -5
To reduce the number of inodes your account uses, you should:
1) remove all files/folders you don’t need;
2) check the number of cache files you have; applications such as Joomla can generate a lot of cache files; you should regularly check your cache folder and reduce the number of cached files you keep;
3) if you have Default Address (catch-all) enabled, make sure you check the mailbox regularly and delete all mails you don’t need;
4) check your cPanel’s main email account regularly; the mails for it are kept in:
where username is your cPanel username. You can manually delete the messages in these folders using cPanel’s File Manager or your favorite FTP client;
5) you should also check your email accounts regularly and delete any spam messages from them;
6) if you have email accounts you don’t need or use, it would be best to remove them;
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 thinking would be to delete all the files you can, then reboot the box to ensure no processes are left holding the files open. Lastly, you may be able to .tar.gz certain necessary but unused files or folder to temporarily reduce inode usage.
One final thing to remember, if you are seeing a variance in the du and df command outputs on the server, the du command totals up the space of files that exist within the physical sector size (4096 bytes) of the blocks in the file system, while df shows all of the (4096 bytes) blocks available in the file system.
This is because the maximum number of inodes (and hence the maximum number of files and directories) is set when the file system is created. If V is the volume size in bytes, then the default number of inodes is given by V/213 (or the number of blocks, whichever is less), and the minimum by V/223. The default was deemed sufficient for most applications. The max number of subdirectories in one directory is fixed to 32000.
There are several ways to specify more inodes at filesystem creation time:
mke2fs -i 4096
mke2fs -N 4000000
mke2fs -T news
If your average filesize is much less than 4kB, you could also use smaller disk blocks to store them more compactly:
mke2fs -b 2048 -i 2048
Note: that with so many small files in such a large disk, you may have performance problems if there are lots of files in a single directory.