Home  >  Article  >  Operation and Maintenance  >  What is i node in linux

What is i node in linux

WBOY
WBOYOriginal
2022-06-28 17:23:194879browse

In Linux, the i-node is a 64-byte long table; the i-node contains information about a file, including the file size, file owner, file access permission method, and whether the file is ordinary Files, directory files, special files, etc., the most important item in the i-node is the disk address table.

What is i node in linux

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

i node in Linux

i node is a 64-byte long table that contains information about a file, including file size, file owner, and file access permissions method, and whether the file is an ordinary file, a directory file, or a special file, etc.

The Linux file system is the heart of the Linux system, providing hierarchical directories and files. The file system divides the disk space into groups of 1024 bytes, called blocks (there are also blocks of 512 bytes, such as SCOXENIX). Numbered from 0 to the maximum number of blocks for the entire disk.

All blocks can be divided into four parts. Block 0 is called the boot block, which is not used by the file system; Block 1 is called the private block. The private block contains a lot of information, including the disk size and other information about all blocks. Two portions of size. Starting from block 2 is the i-node table, which contains i-nodes. The number of blocks in the table is variable, which will be discussed later. After the i-node table is a free storage block (data storage block), which can be used to store file content.

The logical structure and physical structure of a file are very different. The logical structure is the file that the user sees after typing the cat command. The user can get a character stream representing the file content. The physical structure is how the file is actually stored on disk. Users think that their files are frontier character streams, but in fact the files may not be stored on the disk in a frontier manner. Files longer than one block are usually stored scattered on the disk. However, when a user accesses a file, the Linux file system will take out each block in the correct order and provide the user with the logical structure of the file.

Of course, there must be a table somewhere in the Linux system that tells the file system how to convert the physical structure into a logical structure. This involves the i node.

The i node is a 64-byte long table that contains information about a file, including file size, file owner, file access permission method, and whether the file is an ordinary file or a directory file. Or special files, etc.. The most important item in the i-node is the disk address table.

There are 13 block numbers in this table. The first 10 block numbers are the storage addresses of the first 10 blocks of the file. These 10 block numbers can give the logical structure of a file that is at most 10 blocks long. The file will obtain the corresponding blocks in the order in which the block numbers appear in the disk address table. What happens when the file is longer than 10 blocks? The 11th item in the disk address table gives a block number. The block pointed to by this block number contains 256 block numbers. So far, this method satisfies files longer than 266 blocks. (272384 bytes). If the file is larger than 266 blocks, item 12 of the disk address table gives a block number. The block pointed to by this block number contains 256 block numbers. Each of these 256 block numbers points to a block, and the block contains 256 block numbers, these block numbers are used to retrieve the contents of the file. The index addressing method of item 13 in the disk address is similar to item 12, except that there is one more level of indirect index.

In this way, in the Linux system, the maximum length of the file is 16842762 blocks, that is, 17246988288 bytes. Fortunately, the Linux system has added a more practical limit to the maximum length of the file (generally 1 to 2M bytes) , so that the user does not accidentally create a file that uses up all the blocks of the entire disk area.

inode

When it comes to inode, we have to first introduce the overall structure of the hard disk. The hard disk contains multiple hard disk platters. The hard disk platters are round. Each hard disk platter has a magnetic head (Head) that can read and write. When this head is fixed and the hard disk platter rotates once, the track it follows is a track. (Track). The set of the same track numbers of all platters in the hard disk is called a cylinder. Each track is divided into many areas, and each area is called a sector. A sector is the smallest storage physical quantity of a hard disk. The storage capacity of a sector is approximately 512 bytes (approximately 0.5K).

After knowing the general structure of the hard disk, let’s talk about how to partition the hard disk. The smallest unit for hard disk partitioning is the magnetic column. After partitioning, it is naturally formatted. When formatting in Linux, you must consider Block and inode. Block is easy to understand. It is the smallest unit that the disk can record. It is composed of several sectors, so the size is usually n*512Bytes, such as 4K.

So what is inode? Block is the area that records the contents of the file, and inode records the attributes of the file and the information in which Block it is placed. Therefore, each file will occupy an inode. When the Linux system wants to find a file, it will first search the inode table to find the file's attributes and data storage location, and then search for the Block where the data is stored and retrieve the data. The number of inodes has been set at the beginning. The setting method is usually "hard disk size/one capacity". It is better for this capacity to be larger than the Block. For example, if the Block is set to 4K just now, then the capacity can be set to about 8K. . Therefore, if a 1GB hard disk is divided into 8K inodes, there will be 131072 inodes. The size of an inode is 128Byte. In this way, we can clearly know that after a partition is formatted as a file system, it will basically have two large blocks: the inode table and the data area, and one is used to record the attribute information of the file. The Block block stored with the file is used to record the contents of the file.

After creating a file, an inode and a block will be created at the same time. The inode stores the attribute information of the file, but does not include the file name, and stores the pointer to the address of the block where the corresponding data is located; block To store file data, each block can store at most one file. When a block cannot be stored, the next block will be occupied.

The file name, file attributes, and file content of a file in Linux are stored separately: the file name is stored in the directory entry (i.e. dentry), and the file attributes are stored in the inode. Under normal circumstances, each inode occupies 128Bity disk space, file content is stored in data blocks.

You can use mkfs.ext3 -b to set the block size. Each block can store up to one file, so generally the block size setting should be based on the application settings of our server. If this server It is mostly used to store many small files, so you can set the block size smaller so as not to waste space. However, when large data is stored, you need to set the block size larger, which can reduce the impact on the data. The number of disk block reads can also reduce the recording burden of inodes.

The larger the block, the fewer inodes, which are suitable for file systems that store large files; the smaller the block, the more inodes, which are suitable for file systems that store many but small files.

When the system is running, the inode and block will synchronize the memory and the disk after modification. The content we list using ls -li is the temporary storage in the memory, so sometimes the system shuts down abnormally. Causes block and inode out of synchronization problems.

Recommended learning: Linux video tutorial

The above is the detailed content of What is i node in linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn