Linux ext2 File System learning

Source: Internet
Author: User

Linux ext2 File System understanding

    1. Hard Drive Composition:

The hard disk is composed of several circular hard disk slices. The amount of data that can be accommodated in a hard disk is divided into Flixbox and multiple disks. The data read of the hard drive depends on the head on the robotic arm and has multiple heads on the robotic arm. The mechanical arm does not move the hard disk the path that rotates a week is the track. Because there is more than one hard disk on a hard disk overlapping placement, so when the hard disk rotation on the different hard disk to draw a number of identical tracks, these same tracks formed a cylinder. A cylinder is the smallest unit of a partition. Draws a straight line from a circle and divides the track into sectors, which are the smallest units of data storage, with a sector size of approximately 512 bytes.

Disk capacity = Cylinder * HEAD * sector * 512 bytes

2. Partition:

The first thing to do before you use a piece of hard disk is partitioning. The primary purpose of the partition is to tell the operating system which cylinder from which the hard drive is available. A hard disk can be divided into zones, such as C, D, E, and F under Windows. So where do these partitioning information be stored? The MBR (Master boot Recorder) main boot area is stored on the No. 0 track of the hard disk, and the partition information is stored in the MBR. Because of this, the MBR is the first area to read when the computer starts.

Because the size of the MBR is limited, only four partition information can be stored, which is the reason why the primary and extended partitions can have up to four. You can partition the hard disk using 3p+e or other methods.

    1. File system

After partitioning the hard disk, to format the partition, EXT2 is the Linux standard file system format. As mentioned above, the sector is the basic unit of data storage, but the sector capacity is too small, if the sector as the basic storage unit of the file, it will result in multiple access to the hard disk, resulting in system performance degradation. One of the primary tasks for formatting partitions is to determine the size of the smallest data storage unit----block. A block is composed of multiple sectors, that is, block capacity = sector capacity * 2 ^n, that is, when the partition is formatted, the storage of the file will be in the smallest block, such as a block size of 1k, So if I want to store 0.1k of files, I need to allocate a block to this file, although there is a 0.9k of capacity wasted, such as to store a 9.5k file, you need to allocate 10 blocks to this file. In the Linux ext2 file system, blocks are used only to store file content data, so where do the files have a lot of attribute information stored? The Ext2 file system presents the INODE data structure, which uses this data structure to store the relevant properties of the file, such as access rights, owners, and groups that are also used to store block pointer information for the corresponding file contents. (The inode is also stored with one or more blocks) after the block and inode data structures are presented, the following problems are still present in the formatted partition:

1) How is partition information stored? such as partition size, start and end cylinders, creation time, and so on.

2) How is the inode information organized?

After the partition is formatted with the ext2 format, the blocks and inode in the partition are numbered. Also, 0~x (x will vary by partition) is planned into a large block, called Superblock, which stores some information about the partition in Superblock, such as number of blocks, number of inode, partition creation time, etc., and several similar Group x: (Block X ~ y) (where x, y represents a numeric number) cell, what does this information store? In the ext2 file system, all blocks and Inode are formed into block groups, each block group contains multiple blocks and inode, which means that blocks and Inode are managed as block groups. The information contained in the Block group is:

Group 0: (Blocks 0-32767) [itable_zeroed]

1.Checksum 0xb986, unused inodes 49

2.Primary superblock at 0,

3.Group descriptors at 1-2

4.Reserved GDT blocks at 3-1024

5.Block Bitmap at 1025 (+1025), Inode bitmap at 1041 (+1041)

6. Inode table at 1057-1568 (+1057)

7.22987 free blocks, inodes, 480 directories, unused inodes

8.Free blocks:9392, 9436, 9444, 9496, 9567-9571, 9790-32767

9.Free inodes:8144-8192

    1. Primary superblock: block for storing partition information
    2. Group descriptors: Blocks that store block group information
    3. Reserved GDT blocks: Reserved blocks
    4. Block Bitmap Inode bitmap: Indicates whether blocks and Inode are available, each representing a block or inode, 1 indicates there is data, and 0 means no storage data is empty
    5. Inode Table: Represents the block where all the inode contained by the block group
    6. Free block, Inode: number of idle blocks and inode
    7. Free BLOCK: block in which blocks are available
    8. Free Inode: The block where the idle inode resides

When you create a file:

    1. Based on the Inode bitmap/block bitmap information, the unused inode and block are found, and the attributes and data of the file are separately credited to the Inode and the block.
    2. Inform Superblock, Inode Bitmap, block bitmap, etc. of the inode and block number you just used to update the information.

How does the Linux system read the contents of a file in the end?

Directory: When creating a directory on a Linux ext2 file system, Ext2 assigns an inode and at least one block to the directory. Where the Inode records the relevant properties of the directory and points to the allocated block, and the Block records the correlation of related files in this directory.

Files: When a file is created under the Ext2 file system, the system allocates at least one inode and a block corresponding to the file size, and the inode itself does not record the file name, it only records the files related attributes, and the file name is recorded in the block area of the folder to which it belongs. The file name and Inode related connections are recorded in the block area of the folder. Therefore, when reading a file content under the Ext2 file system, Linux will first be the root directory/the inode where the upper-level directory of the file is located, the block to which the directory belongs is obtained by the Inode, the inode of the file is found in the block, and the corresponding block of the file is obtained through the inode of the file. For example, read the/etc/crontab file:

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.