Linux self-study journey-basic commands (Ext4 file system)

Linux self-study journey-basic commands (Ext4 file system)


Preface

1. In the previous section, we talked about the head, tail, and ln commands of file operation commands, and by the way, we talked about hard links and soft links, and I talked about Inode and Block in the previous section.

2. In this section, we will not talk about commands for the time being. Let's first talk about the Ext4 file system under Linux, its working principle, and Inode and Block to temporarily understand what these two are.


Tip: The following is the content of this article

1. Ext4 file system?

Remember our hard disk, do we need to partition the disk when we first get it, and then after the partition is finished, should we format it? What is the function of formatting? Is it written to the file system? The "Ext" file system is used in all versions below Centos7.x, while the Ext4 file system is used in our Centos6.6.
So it can be understood that what is formatted and written in our Centos6.6 is the Ext4 file system.
(The specific comparison or benefits of various Linux file systems, we have to wait for us to learn a little deeper before we understand better)

2. How does the Ext4 file system work?

First of all, our Ext4 file system will divide the partition into two areas, a small part is used to save Inode, most of which is used to save Block , as shown in the figure, although the drawing is a bit silly, it can probably be regarded as the format of the Ext4 file system
Insert picture description here

1.Inode

The default size of Inode is 128 bytes, and Inode is mainly used to store {

1. File permissions (I will talk about permissions in a few sections)
2. File owner
3. File's belonging group
4. File size
5. File (last) access time, data modification time, status modification time
6. Block Number
(each file corresponds to an Inode)
}

2.Block

(Found through Inode)

The actual data of the file is stored in our block, each block has its own Inode, and the size of each block is 4KB by default in our Ext4 .
(For example, when we want to store a 10KB data, we know that a block size is 4KB, so if we want to store this 10KB data, we must use 3 blocks, then at this time, we find 3 The block is 12KB, and our data is only 10KB. At this time, the remaining 2KB can’t actually store the data. That is to say, the next time you store the data, the new block will be selected first instead of the unused one. The block continues to be used.) ------Then mention here that if the block stores the data, it is not necessarily stored sequentially, that is, your 10KB data may not be stored together in a row of consecutive blocks. When possible It is scattered, one in the first, one in the fourth is possible.


to sum up

Then we can summarize {

1. We know that each file has its own corresponding Inode. Only through Inode can the Block be found, and the actual data can be known only when the Block is known.

2. Then there is another point, that is, the file name that I did not mention before. Our file names are all stored in the Block under the current directory (that is, for example, your current directory is under /tmp/, and then you There is a file called se.txt in the directory, then the file name of your file is saved in the Block of your tmp directory)

3. So if we want to find a file in a certain directory, we can know the Inode of the file I'm looking for through the corresponding file name in the Block of your directory, and then we can find us through this known Inode Block of the desired file.
}

Guess you like

Origin blog.csdn.net/qq313088385/article/details/112701336