EXT2 file system for Linux systems

Source: Internet
Author: User

Here's what you're introducing Ext2 file system

The Ext2 file system uses an Inode-based file system.

The file system starts with the inode and block planning, and unless reformatted, the inode and block will no longer change, but when the inode and block are too numerous, it is not easy to manage. As a result, the Ext2 is essentially differentiated into blocks (block group) when formatted, and each block group has its own/inode/block/superblock system. Ext2 after formatting

In the overall planning, there is a boot sector (boot sector) at the front of the file system, which can install the boot loader. You can therefore install different boot programs to the front of individual file systems without overwriting the entire hard disk's unique MBR (master boot partition). Each pulp is described below:

1. Data block: Used to place the contents of the file. The block size supported in the Ext2 file system is 1kb,2kb and 4KB three, fixed when the block size is formatted, and each block is numbered to facilitate inode recording.

However, due to the difference in block size, the file system can support the maximum disk capacity and the maximum single file capacity is not the same, block size and longevity of the Ext2 file system is limited by the following

Block size 1KB 2KB 4KB
Maximum Single file limit 16GB 256GB 2TB
Maximum file system capacity 2TB 8TB 16TB

Limit:

1), in principle, block size and quantity can not be changed after formatting

2), a maximum of one file per block can be placed in the data

3), on, if the file is larger than the block size, then a file will occupy more than block number

4), on, if the file is less than block, then the remaining space of the block can no longer be used (disk space will be wasted)

2. inodetable (inode table): The contents of the inode mainly records the attributes of the file and what number of blocks the actual data is placed in, basically, the Inode records the file data at least the following:

1), the access mode of the file

2), the owner and group of the file

3), the size of the file

4), the time when the file was created or changed state

5), last read time

6), Last modified time

7), define the file characteristics of the flag

8), pointing to the true content of the file

9), each inode size is fixed at 128bytes

10), each file will only occupy one inode

11), the number of files the file system can create is related to the number of inode

12), the system to read the file needs to find the inode, and analyze the Inode record the permissions and the user is consistent, if compliant to begin to actually read the contents of block

Inode/block relationship to File size:

Inode to record a lot of data, but only 128bytes, and Inode record a block number to spend 4bytes, if a file has 400MB and each block is 4KB, then at least 100,000 block number of records, Inode, there's so much to record.

The information? For this reason, we're smart. The Inode record block number area is defined as 12 direct, one indirect, one double indirect with a three indirect record area.

The leftmost part of the graph is the inode itself (128bytes), which has 12 controls directly pointing to the block number, and these 12 records can be taken directly to the block number, which is the direct address. As for the so-called indirect is to take a block to record the block number record area, if the file is too large, it will use the indirect block to record the number, that is, indirect addressing. Similarly, if the file continues to grow, it will use double indirection.

So how many blocks can the inode specify? This is illustrated by a smaller block of 1KB. The following scenarios can be specified:

1), 12 direct point: 12*1k=12k, because it is direct pointing, so a total of 12 records can be recorded

2), Indirect: 256*1k

Each block number of records will take 4bytes, so the size of 1K can record 256 records

3), double indirect: 256*256*1k=256^2k

4), three indirect: 256*256*256*1k=256^3k

Total: Direct, indirect, double indirect, three indirect plus total, get 12+256+256^2+ 256^3=16gb, at this time we know when the file system will block format to 1K size, can accommodate the largest file for 16GB, compare the results of file system line indicators can be found to be consistent. However, this method cannot be used in the calculation of block size of 2K and 4K. Because blocks larger than 2K will receive limitations on the file system itself

3, Superblock (Super block)

Superblock is a place to record information about the entire file system, without superblock, there is no such file system, the main information it records are:

1), Block and Inode total

2), unused and used Inode/block quantity

3), block and inode size

4), File system mount time, the last time the data was written, the last time the disk was checked, and other information about the file system

5), a validbit value, if this file system has been mounted, then valid bit is 0, if not mounted, then the valid bit is 1

Superblock is very important because the basic information of our filesystem is written here. In addition, each block group may contain superblock. But we also say that a file system should have only one superblock. In fact, in addition to the first blockgroup will contain Superblock, the subsequent block group does not necessarily contain superblock, if it contains a superblock is also as the first superblock backup.

4. File system Description (filesystem description): This section can describe the block number of each block group starting and ending, as well as the number of blocks between each block.

5, block Bitmap (blocks): If you want to add files will always use block. Which block do you want to use to record it? Of course, choose "Empty block" to record the data of the new file. So how do you know which block is empty? It's going to pass.

Block bitmap, from the block bitmap to know which blocks are empty, so our system can quickly find the space available to process the files. Similarly, if some files are deleted, then the block numbers that were originally occupied will have to be released, and the flag corresponding to the block number in the block bitmap is changed to "unused". This is the function of Blockmap.

6. Inode Bitmap (inode table): This is similar to the block bitmap function, except that the block bitmap record is used with unused block numbers, Inode bitmap records used with unused inode numbers.

Viewing the file system

Just talked about the parts of the data are related to block number, each section and Superblock information can use DUMPE2FD This command to query, using DUMPE2FS can query to a lot of information.

Relationship to the directory tree

How do directories and files record data in the Ext2 file system? Basically, you can say that.

1, Directory: When we create a new directory in the Linux ext2 file system, ext2 allocates an inode with at least one block to the directory. Where the Inode records the permissions and attributes of the directory, and can record the assigned block number. The block is the inode number data that is recorded in this directory and the file name is occupied by the filename. That is, the block pulp that the directory occupies is logged as follows:

1), if you want to actually view the files in the root directory occupied by the inode number, you can do the following:

2. Files: When we create a new generic file in Ext2 under Linux, Ext2 assigns an inode with the number of blocks relative to the file size to the file

3, directory tree read: Because the file name is recorded in the directory of the block, so when we want to read a file, it is necessary to go through the directory Inode and block, and then to find the inode number of the file to be read, the final will be taken to the correct file block content. Because the directory tree is read from the root directory, so the system through the information can be mounted to find the inode number of the mount point, you can get the inode content of the root directory, and according to the inode to read the root directory within the block file name data, and then read down to the correct file name.

3. File system size and disk read performance

When a file system planning is very large, because the data above the disk frequently changes, so the file system above the files usually cannot be written together, that is, the block number is not high continuous, but instead of filling in the data into the block is not used, if the block written is very loose, Then there will be a discrete problem with the file data occurring.

EXT2 file system for Linux systems

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.