Solutions to the problem of inode index node full in Linux system

Time:2020-4-3

Today, a website of login server found that no session was generated after login. According to the past experience, it is generally because the space is full that session file generation fails.

Copy code

The code is as follows:

df -h
Copy code

The code is as follows:

Filesystem Size Used Avail Use% Mounted on
/dev/mapper/dev01-root 75G 58G 14G 82% /
udev 2.0G 4.0K 2.0G 1% /dev
tmpfs 396M 292K 396M 1% /run
none 5.0M 0 5.0M 0% /run/lock
none 2.0G 4.0K 2.0G 1% /run/shm
/dev/sda1 228M 149M 68M 69% /boot

The remaining space is 14g, which can exclude the situation that the space is full. Another reason for the file generation failure is that the inode of the file index node is full.

Copy code

The code is as follows:

df -i
Copy code

The code is as follows:

Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/mapper/dev01-root 4964352 4964352 0 100% /
udev 503779 440 503339 1% /dev
tmpfs 506183 353 505830 1% /run
none 506183 5 506178 1% /run/lock
none 506183 2 506181 1% /run/shm
/dev/sda1 124496 255 124241 1% /boot

Inodes accounts for 100%, which is really the problem.

Solution: delete useless temporary files and release inode.
It is found that there are many session temporary files in the / tmp directory.

Copy code

The code is as follows:

ls -lt /tmp | wc -l
4011517

Enter the / tmp directory and execute the find – exec command

Copy code

The code is as follows:

sudo find /tmp -type f -exec rm {} \;

If RM * is used, there may be an argument list too long error due to too many files. In addition to the temporary files of / tmp, 0-byte files will also occupy inode and should also be released.
Traverse to find the 0 byte file and delete it.

Copy code

The code is as follows:

sudo find /home -type f -size 0 -exec rm {} \;

After deletion, the usage of inode is reduced to 19%, and it can be used normally.

Copy code

The code is as follows:

df -i
Copy code

The code is as follows:

Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/mapper/dev01-root 4964352 940835 4023517 19% /
udev 503779 440 503339 1% /dev
tmpfs 506183 353 505830 1% /run
none 506183 5 506178 1% /run/lock
none 506183 2 506181 1% /run/shm
/dev/sda1 124496 255 124241 1% /boot

PS: what is inode
In Linux, file lookup is not by file name. In fact, inode is used to find and locate files. We can visualize inode as a pointer FIP. When the file is stored on disk, the file will surely be stored on a disk location. Imagine that since the file data is stored on disk, if we know the address of the file data, when we want to read and write the file, do we use this address to find the file directly?
  
Yes, under Linux, inode can be regarded as an address pointing to the file storage area on the disk. It’s just that we can’t use this address directly, but indirectly through the filename. In fact, inode contains not only the address of the file data store, but also a lot of information, such as data size, and so on. But inode does not save the file name. The filename is saved in a directory entry. Each directory entry contains the file name and inode.

We can look at the relationship among directory items, inode, and file data through a graph.
201633115915009.jpg (640×483)

As you can see from the above figure, the directory entry contains the file name and inode.