Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is Linux inode?

2025-04-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "what is Linux inode". In daily operation, I believe many people have doubts about what Linux inode is. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts about "what is Linux inode?" Next, please follow the editor to study!

Inode content inode contains a lot of file meta-information, but does not contain file names, such as: number of bytes, owner UserID, group GroupID, read and write execution permissions, timestamps, and so on.

The file name is stored in the directory, but the Linux system does not use the file name, but uses the inode number to identify the file. For the system, the file name is just an alias for the inode number to be easily identified.

Stat View inode Information

[root@localhost ~] # mkdir test [root@localhost ~] # echo "this is test file" > test.txt [root@localhost ~] # stat test.txt File: 'test.txt' Size: 18 Blocks: 8 IO Block: 4096 regular file Device: fd00h/64768d Inode: 33574994 Links: 1 Access: (0644 regular file Device) Uid: (0 / root) Gid: ( 05.920240744 + 0800 Modify: 2019-08-28 19Modify: 05.920240744 + 0800 Change: 05.920240744 + 0800 Change:-three main time attributes:

Ctime:change time is the last time a file or directory (attribute) is changed, such as executing a command such as chmod,chown. Atime:access time is the last time a file or directory is accessed. Mtime:modify time is the last time a file or directory (content) was modified.

File View File Typ

[root@localhost ~] # file test test: directory [root@localhost ~] # file test.txt test.txt: on the surface, the user opens the file through the file name. In fact, the system divides this process into three steps:

1. The system finds the inode number corresponding to this file name; 2. Obtain inode information through inode number; 3. According to the inode information, find the block where the file data is located, and read the data.

In fact, according to the inode information, the system also depends on whether the user has access rights, points to the corresponding data block, and returns permission rejection if not.

Ls-I can view the file I node number directly, or you can view the file inode information through stat to see the I node number.

[root@localhost] # ls-I 33574991 anaconda-ks.cfg 2086 test 33574994 test.txtinode size inode also consumes hard disk space, so when formatting, the operating system automatically divides the hard disk into two areas. One is the data area, which stores the file data, and the other is the inode area, which stores the information contained in the inode. The size of each inode is typically 128byte or 256byte. In general, you don't need to focus on the size of a single inode, but rather on the total number of inode. The total number of inode is determined when formatted.

Df-I view the total number of inode and usage of hard disk partitions

[root@localhost] # df-i Filesystem Inodes IUsed IFree IUse% Mounted on / dev/mapper/centos-root 8910848 26029 8884819 1 / devtmpfs 230602 384 230218 1 / devtmpfs 233378 1 233377 1 / dev/shm tmpfs 233378 487 232891 1 / run tmpfs 233378 16 233362 1 % / sys/fs/cgroup / dev/sda1 524288 328 523960 1 per cent / boot tmpfs 233378 1 233377 1 per cent / run/user/0 unique phenomenon due to separation of inode numbers from file names This leads to the following unique phenomena in some Unix/Linux systems.

1. The file name contains special characters and may not be deleted properly. Delete inode directly at this time, which can delete files.

Find. / *-inum node number-delete2. Move the file or rename the file, just change the file name, do not affect the inode number; 3. After opening a file, the system recognizes the file by the inode number, regardless of the file name.

This situation makes it easy to update the software without shutting down the software without restarting it. Because the system identifies the running file by the inode number, not by the file name. During the update, the new version of the file generates a new inode with the same file name, which does not affect the running file. The next time you run the software, the file name automatically points to the new version of the file, and the inode of the old version is recycled.

Inode exhaustion failure because the total number of inode of hard disk partitions has been fixed after formatting, and each file must have an inode, so it is possible to run out of inode nodes, but there is still a lot of hard disk space left, but new files cannot be created. At the same time, this is also a way to attack, so some common file systems have to do disk limits to prevent affecting the normal operation of the system.

As for repair, it's simple to find out which files that take up a lot of I nodes are deleted.

Demo:

1. First prepare a relatively small hard disk partition / dev/sdb1 and format the mount, which is mounted to the / data directory.

[root@localhost] # df-hT / data/ Filesystem Type Size Used Avail Use% Mounted on / dev/sdb1 xfs 29M 1.8m 27m 6% / data2. You can create files normally by testing first.

[root@localhost ~] # touch / data/test {1. 5} .txt [root@localhost ~] # ls / data/ test1.txt test2.txt test3.txt test4.txt test5.txt3. View the usage of the I node.

[root@localhost] # df-I / data/ Filesystem Inodes IUsed IFree IUse% Mounted on / dev/sdb1 16384 8 16376 / data4. Write a test program to create a large number of empty files to exhaust the number of I nodes in this partition.

[root@localhost] # vim killinode.sh #! / bin/bash iTunes 1 while [$I-le 16376] do touch / data/file$i let iTunes + done5. Run the test program, and then check the I node occupancy and disk partition space usage.

[root@localhost] # sh killinode.sh [root@localhost] # df-I / data/ Filesystem Inodes IUsed IFree IUse% Mounted on / dev/sdb1 16384 16384 / data [root@localhost] # df-hT / data/ Filesystem Type Size Used Avail Use% Mounted on / dev/sdb1 xfs 29M 11M 19m 36 / data6. Although there is still a lot of space left, the I node is exhausted and cannot be created to create a new file, which is the I node exhaustion failure.

[root@localhost ~] # touch / data/newfile.txt touch: cannot touch'/ data/newfile.txt': No space left on device hard link and soft link hard link A new file name generated by a file system's inode link, rather than a new file, called a hard link.

In general, each inode number corresponds to a file name, but Linux allows multiple file names to point to the same inode number. It means that the same content can be accessed using different file names.

After the ln source file destination runs the command, the source file and destination file have the same inode number and both point to the same inode. The number of links in the inode message now increases by 1.

When a file has multiple hard links, changes to the contents of the file will affect all file names, but deleting one file name does not affect the access of another file name. Deleting a file name will only subtract 1 from the number of links in the inode.

It is important to note that you cannot make hard links to directories.

Create a new directory through the mkdir command, the number of hard links should be 2, because the common directory itself is 1 hard link, and the hidden directory under the directory. (dot) is another hard link to that directory, which is also a number of connections.

Soft links are files that are similar to Windows's shortcut function and can be quickly connected to the target file or directory, called soft links.

Ln-s source file or directory target file or directory soft link is to create a separate file, and this file will let the data read to point to the file name of the file to which it is connected. For example, the inode numbers of file An and file B are different, but the content of file An is the path of file B. When you read file A, the system automatically directs visitors to file B. At this point, file An is called the soft link soft link or symbolic link symbolic link of file B.

This means that file A depends on file B. if file B is deleted, file A will report an error when it is opened. This is the biggest difference between soft links and hard links: file A points to the file name of file B, not the inode number of file B, and the number of inode links of file B will not change.

At this point, the study of "what is Linux inode" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report