Inode explanation (solve the problem that Linux has space but prompt disk space is insufficient) __linux

Source: Internet
Author: User
Tags parent directory disk usage

FileName-> inode-> device block

Turn from:
Http://www.ruanyifeng.com/blog/2011/12/inode.html
http://blog.s135.com/post/295/
Http://hi.baidu.com/leejun_2005/blog/item/d9aa13a53b3af6e99152ee7e.html

First, what is the inode. Understand the inode, from the file storage. The file is stored on the hard disk and the smallest storage unit of the hard disk is called a "sector" (sector). Each sector stores 512 bytes (equivalent to 0.5KB).

When the operating system reads the hard drive, it does not read one sector at a time, so it is too inefficient to read multiple sectors at once, that is, to read a "block" once in a row. This "block" consisting of multiple sectors is the smallest unit of file access. The size of the "block", the most common is 4KB, that is, eight consecutive sector to form a chunk.

File data is stored in "block", so obviously we also have to find a place to store the metadata of the file, such as the creator of the file, the date of creation of the file, the size of the file, and so on. This area of storing file meta information is called an inode, and the Chinese translation is "index node".

Second, the content of the inode contains the meta information of the file, specifically the following: * File bytes * File owner's user ID * file's group ID * file's read, write, execute permissions * file timestamp, a total of three: CTime refers to Ino   De last change of time, mtime refers to the time of the last change in the contents of the file, atime refers to the time the file was last opened. * Number of links, that is, how many filenames point to the location of the inode * file data block

You can use the Stat command to view the Inode information for a file: Stat example.txt


In short, all file information except the file name exists in the inode. As for why there is no filename, the following will be explained in detail.

Third, the size of the inode will also consume hard disk space, so the hard disk format, the operating system automatically divides the hard disk into two areas. One is the data area, which holds the file data, and the other is the Inode table, which holds the information that the inode contains. The size of each inode node, typically 128 bytes or 256 bytes. The total number of inode nodes, given when formatted, is typically set to an inode every 1KB or 2KB. Assuming that in a 1GB hard disk, each inode node size is 128 bytes, set an inode per 1KB, then the Inode table size will reach 128MB, accounting for 12.8% of the entire hard drive.

You can use the DF command to view the total number of inode and the quantity already used for each hard disk partition. Df-i view the size of each inode node, you can use the following command: sudo dumpe2fs-h/dev/hda | grep "Inode size" because each file must have an inode, it is possible that the inode has been used up, but the hard drive is not full. At this point, you cannot create a new file on your hard disk.

Iv. inode number Each inode has a number, operating system with inode number to identify different files.

It is worth repeating that the Unix/linux system does not use the filename, and the inode number is used to identify the file. For systems, filenames are just nicknames or nicknames that are easily identifiable by inode numbers. On the surface, the user opens the file by file name. In fact, the process within the system is divided into three steps: First, the system finds the inode number corresponding to the file name, and secondly, obtains the inode information through the inode number, and finally, according to the Inode information, locate the block where the file data resides and read the data.

Using the Ls-i command, you can see the inode number corresponding to the filename: ls-i example.txt

V. Directory file Unix/linux system, directory (directory) is also a kind of file. Opening the directory is actually opening the catalog file.

The structure of a catalog file is very simple, a list of a series of directory entries (dirent). Each directory entry consists of two parts: the file name of the containing file and the Inode number for the file name.

The LS command lists all the file names in the directory file: ls/etc ls-i command lists the entire directory file, which is the filename and inode number: Ls-i/etc If you want to view the details of a file, you must access the Inode node and read the information based on the inode number. The ls-l command lists the details of the file. Ls-l/etc

Six, hard links under normal circumstances, the filename and inode number is "one by one correspondence" relationship, each inode number corresponds to a filename. However, the Unix/linux system allows multiple filenames to point to the same inode number. This means that you can access the same content with different file names, and modifying the contents of the file affects all file names, but deleting a file name does not affect access to another file name. This situation is referred to as a "hard link" (hard link).

The ln command can create a hard link: ln source file target file after running the above command, the source file has the same inode number as the target file, pointing to the same inode. An inode message is called a "number of links", which records the total number of file names that point to the inode, and then increases by 1. Conversely, deleting a filename causes the "Number of links" in the Inode node to be reduced by 1. When this value is reduced to 0, indicating that no file name points to the Inode, the system reclaims the inode number and its corresponding block area.

By the way, here are the number of links to the directory file. When you create a directory, two directory entries are generated by default: "." and ".." The inode number of the former is the inode number of the current directory, which is equivalent to the "hard link" of the current directory, and the inode number is the inode number of the parent directory of the current directory, which is equivalent to the "hard link" of the parent directory. So, the total number of "hard links" for any directory is always equal to 2 plus the total number of subdirectories (including hidden directories), where 2 is the "hard link" of the parent directory and the ". Hard link" under the current directory.

Seven, soft links in addition to hard links, there is a special case. The inode number for file A and file B is different, but the content of file A is the path to file B. When you read file A, the system automatically directs the visitor to file B. Therefore, whichever file is opened, the final read is file B. At this point, file A is referred to as the "soft link" (soft link) or symbolic link (symbolic link) of file B.

This means that file a depends on file B, and if you delete file B, opening file A will cause an error: "No such file or directory." This is the biggest difference between soft links and hard links: file a points to file B's filename, not the inode number of file B, and the Inode "link number" of File B does not change.

The ln-s command can create soft links. Ln-s source file or directory destination file or directory

Viii. the special role of the inode because the inode number is separated from the filename, this mechanism leads to some phenomena peculiar to the unix/linux system. 1. Sometimes, the file name contains special characters and cannot be deleted normally.   At this point, directly delete the Inode node, you can play the role of deleting files.   2. Move or rename the file, just change the file name without affecting the inode number. 3. After opening a file, the system identifies the file with the Inode number and no longer considers the filename.       Therefore, generally speaking, the system cannot know the filename from the inode number. The 3rd makes the software update simple, can be updated without shutting down the software, do not need to restart. Because the system through the Inode number, identify the running files, not through the filename. Update, the new version of the file with the same file name, to generate an inode, will not affect the running of the file. Wait until the next time the software is run, the file name will automatically point to the new version of the file, the old version of the file's inode is recycled.

Nine practical problems in a lower-configured Linux server (memory, small hard disk) in the/data partition to create a file, the system prompts the disk space is not enough, with the df-h command to view the disk usage, found that/data partition only used 66%, there are 12G of space left,  There is no such problem. Later, Df-i looked at the/data partition's index node (inode) and found that it was full (iused=100%), causing the system to create new directories and files.

Find out why:

There are a very large number of small byte cache files in the/data/cache directory, and the block is not much occupied, but it takes up a lot of inode.

Solution:
1, delete some files in the/data/cache directory, release part of the/data partition Inode.
2, the Newcache directory in the free partition/opt is connected to/data/cache with soft connection, and the inode of/OPT partition is used to alleviate the problem that the inode of the/data partition is insufficient:
Ln-s/opt/newcache/data/cache

Finish

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.