Brother Bird's Linux private Cuisine Basics Study Book notes (8): Linux disk and File system Management (1)

Source: Internet
Author: User

Linux is the most traditional disk file system is EXT2 (of course, has now been upgraded to EXT4), this chapter mainly introduces the Linux disk File system, and this article focuses on the Linux EXT2 file system.

we all know that when a disk partition is completed, it is formatted because the file system format used by each operating system is different. In Linux, EXT2 is primarily the file system format, and by default the Windows operating system is a EXT2 file system that does not recognize Linux. Typically, a partition is a file system, but because of the use of new technologies, we can synthesize multiple partitions into a filesystem, so now we call a data file system that can be mounted .

the Linux Ext2 file system is an inode-based file system. in the Ext2 file system, the inode is used to record the attributes and permissions of the file, the block blocks record the actual contents of the file, and the file system has a Super block (Superblock) that records the overall information of the filesystem, including the total number of inode and block, usage, Information such as the amount remaining. the file system initially planned the inode and block, so the inode and block would be fixed unless reformatting (or changing the file system size with RESIZE2FS) . Moreover, the Linux Ext2 file system manages the Inode and block in blocks, and each block group has its own inode/block/superblock system. This will not be difficult to manage because of the excessive number of inode and block in the entire filesystem. The Ext2 file system structure can be used to represent:


as mentioned in the previous article, the first sector of each file system is the boot sector, and the boot sector can install the boot loader. Although there is only one master boot record (MBR) per boot device , the boot loader can be installed on each file system's boot sector, so we have the opportunity to do multiple booting.

Next is the Superblock (Super Block), although each block group may contain a super block, but the entire file system should have only one super block. What do you mean? In fact, in addition to the first block group has the Super block, the other block groups are generally not super block, even if they have, they are only the first block of the Super block in the backup, is used to do Super Block rescue.

The file system description is used to describe the block number at which each block group starts and ends, and between which block numbers each segment is located. The equivalent file system describes the information for each block group.

Indoe Bitmap (Indoe): Used to record the current file system Indoe which are already in use and which are unused.

Block bitmap: Used to record which blocks of the current file system are already in use and which ones are unused.

Inode table: Theinode is the number that is used to record the properties of the file and the block where the actual data for the file resides. each file occupies one inode, each with a fixed size of 128bytes. So we can see that the number of files each file system can create is related to the number of inode, and because each inode size is fixed, and the inode needs to record the number of blocks where the actual data of the file resides. Therefore, the size of each file is also related to Inode/block. the Inode record block number region is defined as 12 direct, 1 indirect, 1 double indirect, 1 three indirectly.

What do you mean? 12 directly referred to by the inode point to the 12 blocks directly used to record the file data, 1 indirectly refers to the Inode pointed to the block is not directly stored in the file data, instead of the block stored in the other block number, These block numbers correspond to blocks where the actual file data is stored. If it's double-indirect, these blocks are also used to record block numbers that hold real data. And so on, three indirectly refers to the third level block or to record the label.

When we assume that the size of each block is 1k, the maximum size of each file can be calculated as: 12 Direct: 12*1k =12k; 1 Indirect: Assuming four bytes to record the block number, and double indirect namely: 256* 256k, three indirectly namely is 256*256*256k. So the maximum file size that can be stored is 12k + 256k +256*256k + 256*256* 256k=16g.

block table (data block) is a block, a collection of blocks, The block size supported by the Ext2 file system is 1k,2k,4k. At the time of formatting, the block block number, when the file data is smaller than the size of a block, the block's remaining space will not be used, other files can not be put in the data. So when we file system files are small and many files, and at this point the block is selected more large (such as 4k), can result in wasted space. However, selecting block 1k is not a panacea, Sometimes the file system's poor read and write performance can occur due to the large number of blocks required to store files. Therefore, the block size selection should be referenced when formatting The main purpose of future file systems.

Once the file system has been formatted, how to view the above data, you can use the DUMPE2FS command to learn more about the file system information. The use of the DUMPE2FS command is: DUMPE2FS [-BH] Device file name, DUMPE2FS display data can be divided into two parts, the first part is the file system Superblock recorded information, such as the number and size of blocks, the number of indoe and so on. The second part is the details of each block group, such as the location of the block group, the usage of the block, and other information.

When we create a new directory, the Linux Ext2 file system allocates at least one inode with at least one block to the directory. as already mentioned, the directory is actually a list of filenames, so the content of the directory is the file name under that directory. Therefore, the permissions and attributes of the directory are recorded in the Inode allocated by Linux to the directory, and the number of blocks to which the directory is assigned is recorded. The Block records the file name in the directory and the inode number corresponding to the file name.

So when we access a file, how does the whole process work? Here take/etc/passwd as an example:

(1) Find the root directory "/" Indoe by Mount point information, the node number of the most top-level directory of all file systems is 2, for example on my system ,/home is a separate partition that can be queried through the ls-id/home command to the/home directory where the inode number is 2.

(2) through the root directory Inode recorded in the block number, find the corresponding block,block inside the root directory of all the file names, find the etc/directory where the indoe number (if you have access to the root directory permissions).

(3) in the etc/is located in the Indoe according to the appropriate permission settings to check, if passed, then read etc/block content, there is passwd file Indoe number.

(4) access to the passwd file Indoe, through the permission check, can be recorded in the inode in the block number, read out the corresponding blcok, which is stored in the block the actual data for the passwd file.

ext2 file system because the log function is not supported, So when our file system is in a data inconsistency (such as a sudden power outage that causes a sudden system outage), it needs to be when the system restarts. specifically plan out a block, The steps used to record when writing or revising a file. Therefore, when data inconsistency occurs, you can examine the log record block directly, and you can quickly identify the problem. Linux EXT3 is a file system that supports logging capabilities.

It has also been said that since the disk is much slower than memory, Linux does not immediately update the modified data in memory to disk after modifying the data in memory . instead of using asynchronous processing, the system will not periodically write the modified memory data (at which time the data in memory is set to dirty) to disk, can also be manually forced to write to the disk through the Sync command, when the system shuts down normally, The shutdown command actively calls the Sync command to write the modified data back to the disk, and if it is not properly shut down, the system may take a lot of time to test the disk if the data is not written back to the disk, and may even cause file system corruption.

In addition to supporting Linux standard file system EXT2, Linux also supports very many file systems and can view Linux supported file systems in the following ways:

Ls-l/lib/modules/$ (uname-r)/kernel/fs

You can view the file systems that have been loaded into memory in the following ways:

Cat/proc/filesystems

Although Linux supports very many file systems, for our users, it is not necessary to know what the filesystem on each partition is, and Linux passes the VFS (virtual file system) to manage all file systems.


This chapter is a summary of Linux commands:

Dumpe2fs.




Brother Bird's Linux private Cuisine Basics Study Book notes (8): Linux disk and File system Management (1)

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.