Depth understanding of inode disk file systems (rpm) disk inode-depth understanding of file systems (rpm)

Depth understanding of inode disk file systems (rpm)

First, what inode that?

Understanding inode, file storage from the start.
Files are stored on the hard disk, hard disk smallest unit of memory called a "sector" (Sector). Storage 512 bytes per sector (corresponding to 0.5KB).

 

Operating system reads the hard disk, it does not read a sector, so that efficiency is too low, but a plurality of disposable continuous reading of sectors, i.e., a one-time read "block" (block). This "block" composed of a plurality of sectors, is a minimum unit of file access. Size "chunks", the most common is 4KB, namely eight consecutive sector to form a block.

 

File data is stored in the "block", then it is clear that we must find a place to store meta-information file, such as the creator of the file, the file creation date, file size, and so on. This meta-information file storage area is called the inode, Chinese translation of "inode."

 

 
Two, inode content
inode contains meta-information file, specifically, have the following:
  * Number of bytes in the file
  * User ID file owner
  * Group ID documents
  * File read, write, and execute permissions
  * Timestamp file, there are three: ctime means the inode creation time, mtime refers to the contents of the file was last modified time, atime refers to the time the file was last accessed.
  * The number of links that point to the number of file names inode
  * The location of the file data block

 

Stat command can be used to view a file's inode information:
stat example.txt

 

 
In short, all the file information in addition to the file name, there is among the inode. As for why no file name, there will be explained in detail below.

 

Three, inode size
inode will consume disk space, so the hard disk formatting, the operating system automatically hard disk into two regions. A data area storing the file data; the other is a region inode (inode Table), the information stored inode contains.
Each of the inode size, typically 128 bytes or 256 bytes. The total number of the inode is, for a given when formatting, usually per 1KB 2KB or sets a per inode. Assuming a 1GB hard disk, the size of each of the inode is 128 bytes, sets a 1KB each inode, the inode table size that will reach 128MB, accounting for 12.8% of the entire hard drive.

 

Check each hard disk partition and the total number of inode number already in use, you can use the df command.
df -i
 
See each of the inode size, you can use the following commands:
sudo dumpe2fs -h /dev/hda | grep "Inode size"
 
Because each file must have an inode, so it can happen inode has been used up, but not yet a hard disk is full situation. At this time, you can not create new files on your hard disk.

 

Four, inode number
Each has an inode number and operating system used to identify different inode number of files.

 

It is worth repeating again, internal Unix / Linux system does not use file names, using inode number to identify the file. For a system, the file name just inode number for easy identification of another name or nickname. On the surface, the user through the file name to open the file. In fact, internal systems of the process is divided into three steps: First, the system finds the inode number corresponding to the file name; secondly, by inode number, get inode information; and finally, according to the inode information, find the file data block where the read data.
 

Use ls -i command, you can see the inode number corresponding to the file name:

ls -i example.txt

 

 
Fifth, the catalog file
Unix / Linux systems, the directory (directory) is a file. Open Directory, in fact, open the file directory.

 

Directory file structure is very simple, it is a list of a series of directory entries (dirent) of. Each directory entry consists of two parts: a file contains a file name, file name and inode number of the corresponding.

 

ls command lists only the file names of all files in the directory:
ls /etc
 
ls -i command lists the entire directory file, the file name and inode number:
ls -i /etc
 
If you want to view the details of the file, it must be based on inode number, the inode access, read the information. ls -l command lists the details of the file.
ls -l /etc

 

 
Sixth, hard links
In general, the file name and inode number is "one to one" relationship, each inode number corresponds to a file name. However, Unix / Linux systems allow multiple file names point to the same inode number. This means, you can use a different file name to access the same content; the file content changes will affect all file names; however, deleting a file name, does not affect access another file name. This situation is called a "hard link" (hard link).
 

ln command to create a hard link:

ln source destination file
 
After running above command, the same inode number of the source file and the target file, point to the same inode. inode information in a listing called "number of links" record points total of the inode file name, then it will increase 1. Conversely, deleting a file name, it could make the "number of links" inode nodes minus 1. When this value reaches zero, indicating that no file name pointing to the inode, the inode number of the system will be recovered, and its corresponding block area.

 

By the way here, "number of links" directory files. When you create a directory, the default directory will generate two keys: and "..". "." The former inode number is the inode number of the current directory, equivalent to the current directory "hard link"; the latter is the inode number inode number of the parent directory of the current directory, equivalent to a "hard link" to the parent directory. Therefore, the "hard link" to any directory of the total number, it always equals 2 plus the total number of subdirectories (including hidden directory), where 2 is. "Hard under its parent directory" hard link "and the current directory link".

 

Seven, soft links
In addition to hard links, there is a special case. inode number of files A and B, although not the same, but the content is the path file A file B. When reading the file A, the system will automatically direct visitors file B. Therefore, no matter what a file is opened, the final reading is a file B. In this case, the file A is called a "soft button" file B (soft link) or "symbolic link (symbolic link).

 

This means that the file A depends on B file exists, if you delete a file B, open the file A'll get an error: "No such file or directory". This is the biggest difference between soft and hard links links: A document to a file B file name, file inode number is not B's, B's file inode "number of links" will not change.

 

ln -s command to create a soft link.
ln -s source text file or directory target file or directory

 

 
Eight, inode special role
Since the inode number and file name separated, this mechanism has led to some Unix / Linux system-specific phenomenon.
  1. Sometimes, the file name contains special characters, it can not be deleted properly. In this case, delete the inode, it can play the role of deleted files.
  2. Move the file or rename the file, just change the file name, does not affect the inode number.
  3. Open a file in the future, the system to inode number to identify the file, the file name will not be considered. Therefore, generally speaking, the system does not know the file name from the inode number.
      The third point enables easy software update can be updated without shutting down the software without restarting. Because the system through the file inode number to identify the running, not the file name. Update, the new version of the file with the same file name, create a new inode, it will not affect the file operation. Wait until the next time you run the software, the file name will automatically point to the new file, inode legacy files were recovered.

 

Nine practical problems

When you create a configuration file lower Linux server (memory, hard drive is relatively small) of the / data partition, the system prompts insufficient disk space, use the command df -h checked the disk usage, find / data partition using only 66%, as well as 12G of free space, and normally would not be such a problem. Later, with df -i checked the inode / data partition (inode), has been found with a full (IUsed = 100%), the system can not create new directories and files. 

 

 

Find out the reasons:

  Very much / data / cache directory in the presence of a small number of bytes of cache files, taking up much of the Block, but take up a lot of inode. 

 

Solution:
  1, delete some files / data / cache directory, releasing a portion of the inode / data partition.
  2, with a soft connection free partition / opt directory in newcache connection to / data / cache, use / opt inode partitions to alleviate the shortage of the / data partition inode question:
  LN -s / opt / newcache / data / Cache 

 

Transfer: https://www.cnblogs.com/thinksasa/archive/2013/04/10/3013445.html

First, what inode that?

Understanding inode, file storage from the start.
Files are stored on the hard disk, hard disk smallest unit of memory called a "sector" (Sector). Storage 512 bytes per sector (corresponding to 0.5KB).

 

Operating system reads the hard disk, it does not read a sector, so that efficiency is too low, but a plurality of disposable continuous reading of sectors, i.e., a one-time read "block" (block). This "block" composed of a plurality of sectors, is a minimum unit of file access. Size "chunks", the most common is 4KB, namely eight consecutive sector to form a block.

 

File data is stored in the "block", then it is clear that we must find a place to store meta-information file, such as the creator of the file, the file creation date, file size, and so on. This meta-information file storage area is called the inode, Chinese translation of "inode."

 

 
Two, inode content
inode contains meta-information file, specifically, have the following:
  * Number of bytes in the file
  * User ID file owner
  * Group ID documents
  * File read, write, and execute permissions
  * Timestamp file, there are three: ctime means the inode creation time, mtime refers to the contents of the file was last modified time, atime refers to the time the file was last accessed.
  * The number of links that point to the number of file names inode
  * The location of the file data block

 

Stat command can be used to view a file's inode information:
stat example.txt

 

 
In short, all the file information in addition to the file name, there is among the inode. As for why no file name, there will be explained in detail below.

 

Three, inode size
inode will consume disk space, so the hard disk formatting, the operating system automatically hard disk into two regions. A data area storing the file data; the other is a region inode (inode Table), the information stored inode contains.
Each of the inode size, typically 128 bytes or 256 bytes. The total number of the inode is, for a given when formatting, usually per 1KB 2KB or sets a per inode. Assuming a 1GB hard disk, the size of each of the inode is 128 bytes, sets a 1KB each inode, the inode table size that will reach 128MB, accounting for 12.8% of the entire hard drive.

 

Check each hard disk partition and the total number of inode number already in use, you can use the df command.
df -i
 
See each of the inode size, you can use the following commands:
sudo dumpe2fs -h /dev/hda | grep "Inode size"
 
Because each file must have an inode, so it can happen inode has been used up, but not yet a hard disk is full situation. At this time, you can not create new files on your hard disk.

 

Four, inode number
Each has an inode number and operating system used to identify different inode number of files.

 

It is worth repeating again, internal Unix / Linux system does not use file names, using inode number to identify the file. For a system, the file name just inode number for easy identification of another name or nickname. On the surface, the user through the file name to open the file. In fact, internal systems of the process is divided into three steps: First, the system finds the inode number corresponding to the file name; secondly, by inode number, get inode information; and finally, according to the inode information, find the file data block where the read data.
 

Use ls -i command, you can see the inode number corresponding to the file name:

ls -i example.txt

 

 
Fifth, the catalog file
Unix / Linux systems, the directory (directory) is a file. Open Directory, in fact, open the file directory.

 

Directory file structure is very simple, it is a list of a series of directory entries (dirent) of. Each directory entry consists of two parts: a file contains a file name, file name and inode number of the corresponding.

 

ls command lists only the file names of all files in the directory:
ls /etc
 
ls -i command lists the entire directory file, the file name and inode number:
ls -i /etc
 
If you want to view the details of the file, it must be based on inode number, the inode access, read the information. ls -l command lists the details of the file.
ls -l /etc

 

 
Sixth, hard links
In general, the file name and inode number is "one to one" relationship, each inode number corresponds to a file name. However, Unix / Linux systems allow multiple file names point to the same inode number. This means, you can use a different file name to access the same content; the file content changes will affect all file names; however, deleting a file name, does not affect access another file name. This situation is called a "hard link" (hard link).
 

ln command to create a hard link:

ln source destination file
 
After running above command, the same inode number of the source file and the target file, point to the same inode. inode information in a listing called "number of links" record points total of the inode file name, then it will increase 1. Conversely, deleting a file name, it could make the "number of links" inode nodes minus 1. When this value reaches zero, indicating that no file name pointing to the inode, the inode number of the system will be recovered, and its corresponding block area.

 

By the way here, "number of links" directory files. When you create a directory, the default directory will generate two keys: and "..". "." The former inode number is the inode number of the current directory, equivalent to the current directory "hard link"; the latter is the inode number inode number of the parent directory of the current directory, equivalent to a "hard link" to the parent directory. Therefore, the "hard link" to any directory of the total number, it always equals 2 plus the total number of subdirectories (including hidden directory), where 2 is. "Hard under its parent directory" hard link "and the current directory link".

 

Seven, soft links
In addition to hard links, there is a special case. inode number of files A and B, although not the same, but the content is the path file A file B. When reading the file A, the system will automatically direct visitors file B. Therefore, no matter what a file is opened, the final reading is a file B. In this case, the file A is called a "soft button" file B (soft link) or "symbolic link (symbolic link).

 

This means that the file A depends on B file exists, if you delete a file B, open the file A'll get an error: "No such file or directory". This is the biggest difference between soft and hard links links: A document to a file B file name, file inode number is not B's, B's file inode "number of links" will not change.

 

ln -s command to create a soft link.
ln -s source text file or directory target file or directory

 

 
Eight, inode special role
Since the inode number and file name separated, this mechanism has led to some Unix / Linux system-specific phenomenon.
  1. Sometimes, the file name contains special characters, it can not be deleted properly. In this case, delete the inode, it can play the role of deleted files.
  2. Move the file or rename the file, just change the file name, does not affect the inode number.
  3. Open a file in the future, the system to inode number to identify the file, the file name will not be considered. Therefore, generally speaking, the system does not know the file name from the inode number.
      The third point enables easy software update can be updated without shutting down the software without restarting. Because the system through the file inode number to identify the running, not the file name. Update, the new version of the file with the same file name, create a new inode, it will not affect the file operation. Wait until the next time you run the software, the file name will automatically point to the new file, inode legacy files were recovered.

 

Nine practical problems

When you create a configuration file lower Linux server (memory, hard drive is relatively small) of the / data partition, the system prompts insufficient disk space, use the command df -h checked the disk usage, find / data partition using only 66%, as well as 12G of free space, and normally would not be such a problem. Later, with df -i checked the inode / data partition (inode), has been found with a full (IUsed = 100%), the system can not create new directories and files. 

 

 

Find out the reasons:

  Very much / data / cache directory in the presence of a small number of bytes of cache files, taking up much of the Block, but take up a lot of inode. 

 

Solution:
  1, delete some files / data / cache directory, releasing a portion of the inode / data partition.
  2, with a soft connection free partition / opt directory in newcache connection to / data / cache, use / opt inode partitions to alleviate the shortage of the / data partition inode question:
  LN -s / opt / newcache / data / Cache 

 

Transfer: https://www.cnblogs.com/thinksasa/archive/2013/04/10/3013445.html

Guess you like

Origin www.cnblogs.com/davidshen/p/11078140.html