Brother Bird's Linux private Cuisine Basics Third Edition reading notes three Linux disk and file system management

Source: Internet
Author: User
Tags disk usage

I. Understanding the EXT2 file System:    A, the composition of the hard disk: rotating small motor + storage disk + read/write picker     B, some concepts of disk            & nbsp sector is the smallest physical storage unit, each sector is 512b            The sector is composed of a circle, that is, the magnetic column is the smallest split unit         & nbsp   The first sector is the most important, a, main boot area and partition table, wherein MBR occupies 446B, while partition table occupies 64b   c, inode block superblock Three of the meaning of the data             inode: Storing file attributes, permissions, one file occupying an inode, and recording the block number of the data in the secondary archive             BLOCK: The actual data stored, if the file is too large, will occupy a number of block            Superblock: Record The overall information of the entire file, including inode/ Block total, amount of usage, and file system format and related information         Effects: When a file system needs an a file, as long as the inode number is found, you know what block numbers you need to read in order , take it out (disk up to a lap)         There is also a file system fat (which is used before WIN 98). Good slag OH), it is so, first no inode,block read the data at the beginning, and then at the end of the next block number, and then loop, a-B  b-c c-d, it is likely because the data is scattered, the disk need to turn several laps to read the full data, Window System does not have a disk collation, is to be scattered data, to concentrate, improve read performance. Generally speaking, EXT2 systems do not need to be organized because they have indexes.     D, block inode plan when the file system begins to format, unless reformatted, otherwise will not change, if the actual Linux, if the only use of Inode/block/superblock in the file system up to hundreds of GB, all the inode with block one level together, very unwise, the number is too large, Not easy to manage, so need to like the Army management, a regiment has a lot of battalion, a battalion has a lot of even .... have their own contact system, but eventually to the head of the company to report the most correct information     E, each chunk (block group) six main content description:       ·block        1, DataBlock is the place where the archive content data is placed, each block size is fixed (when the file system is formatted),        2, Only one file per block can be placed in the data         3, if the size of the file is larger than the size of each block, will certainly occupy a number of block        4, , if the file size is smaller than the size of each block, the remaining block capacity will no longer be used, and disk space will be wasted        ·inode        1, Each inode size is fixed to 128b        2, each file occupies only one inode         3, Therefore, the file system can establish the number of files and the total inode related         4, the system read the file needs to find the inode first, and analyze the recorded permissions to meet, and then start to block the actual read block content         Savvy developer:        Inode contains 12 direct points, 1 indirect points, 1 double indirect points, and 1 three indirect points. The indirect point refers to the block used to store block point         Let's calculate, assuming block is 1 K, and inode size is fixed 128B, recording a blocK need 4B, then, an inode can record the maximum number of files             12 direct points: 12* 1k          &N Bsp 1 Indirect points 1k/4b * 1K = 256* 1K First             1 dual Indirect 1k/4b*1k/4b * 1K = 256* * 1K You should find the pattern. &n BSP, two             One three indirect 256*256*256*1k = 16G, three levels          I have to say, 66 666       ·superblock        : The total number of blocks and inode, unused and used Inode/block Block and Inode size;                              System mount time, last write data time, last Test disk (fsck) time, and other file system related information;                    & nbsp         A valid bit value, if this filesystem is mounted, the valid bit is 0 and if not mounted, the size of 1        Superblock is 102 4 B, each block group may contain superblock in fact, in addition to the first block group, there will be tons of Superblock cookbook, followed by         Block group does not necessarily have Superblock, and if the ton has SUPerblock then the superblock is mainly as the first block group within the Superblock prepare backup, so import line Superblock rescue it!         Filesystem description        This section can describe each block group's start and end block numbers, as well as descriptions of each segment (Superblock, Bitmap, Inodemap, data block) between each block, this section can be used DUMPE2FS to observe         block bitmap (block table)         records which blocks are empty, when new documents are used, when deleting files, block bitmap will mark the corresponding block, indicating that it has been released         Inode Bitmap (inode table)         like above, record unused inode        Deeper: Create a directory in the EXT2 system, The system allocates at least one inode and one block, records the number of blocks allocated to the inode and the attributes and permissions of the directory, and records the names of the documents in the directory and the inode numbers of those documents in the block, in summary, the inode does not record the document name, The document name is in the block assigned to the directory, so! Add, delete files in directory and W permissions are related, because the files in the directory are written in block and need to modify permissions. Read access to the directory is also the reason to be able to read the contents of the Inode, and block, to know the contents of the document Inode, and then read the contents of the document         F, DF: List The overall disk usage of the file system;              DU: Assessing the disk usage of the filesystem (bands used in the estimate catalog)         G,     LI Nux Read process:/etc/etc/pasSWD the read flow for this file is (assumed to be the general user of Vbird): 1. /inode:    Find the system root/inode, according to the inode permissions, you can read the Inode points to the directory block, etc directory inode number 2, etc inode:    Find the inode of etc according to the Authority, Judge Vbird this account can have RX permissions, read the inode pointing to the directory block, check passwd inode number 3,/etc/passwd    found passwd inode number, According to the permissions inside, judge can read, then according to the Inode described in the block number, then read the data out of the Linux write process:     1, first determine whether the user in this directory has W rights     2, to the Inode Bitmap find a clean inode number assignment and write the permissions/properties of the new file to,    3, go to block bitmap  find block to start writing and write, and regardless of the update inode, I write block number     4. After writing the data, update the INODE and block data to the Inode Bitmap,block bitmap, and update the contents of the superblock H, about two links, one: Entity link, another, shortcut, like Windows     Entity Link: ln Two files point to the same inode number the biggest benefit: security, a place to delete the operation, the other place also pointed to it, so the actual change of the document through the file system can also be retrieved ( Each document requires Inode records to point to, if no inode point, it is equal to Heihu! Equals dead, no one would find you!), cannot link directory, too complex, not currently supported, only supports files Oh     Shortcut link (symbolic link): Ln-s  symbolic link is under construction A separate file, and this file will let the data read to the name of the file that he links to, that is, his block inside, the file name is stored! Transfer Station, you can understand it     There is a special cow, if you create a new directory, such as mkdir/tmp/test, this directory will contain/tmp/test/tmp/test/. /tmp/test/.   Last one: In fact, it is also the directory, pointing to the previous level of the directory, so the above layer/tmp/link will increase by 1, while/tmp/test and/tmp/test/. Point to the same directory so the new directory default link number is 2! 666666    H, disk and directory capacity          1, DF: List The overall disk usage of the file system         2, du: Evaluation file Disk usage of the system (commonly used in the index of the catalog)         3, delete disk partition slots:fdisk        4, disk format:mkfs    & nbsp   5, disk check: fsck, badblocks        6, disk mount and uninstall:mount        7, disk parameter revision: Mknod         8, using solid split slots to build swap    I, the final focus review         1, basically Linux's Orthodox file system is Ext2. The information in this filesystem is mainly:                Superblock: Record The overall information of this filesystem, including the total amount of inode/block, Usage, remaining amount, and file system format and related information etc.;                Inode: Record the attributes of a file, a file occupies an inode, A colleague records the block number of the data for this file; of which 12 points directly to an indirect pointing to a double indirect pointing to a triple-pin point                 BLOCK: The actual record The contents of the file, if the file is too large, will occupy multiple block    2, ext2 filesystem data access as a cableIntroduction File Systems     3, the reason for defragmentation is that the block of document writing is too discrete, and the read performance of the file becomes very poor. This can be done by defragmenting the blocks that belong to the same file.     4, ext2 file system is mainly: Boot Sector,superblock,inode bitmap.block bitmap,inode Table,data block and other six parts     5, data block is used to place the file content data place, in the Ext2 file system supported block size has 1 K 2K 4K three kind of     6, Inode Records File attributes/permissions and other important items are: each inode size fixed to 128B; Each document occupies only one inode; therefore, the number of files the file system can establish is related to the number of Inode;    7, The block of the file records the actual data of the file, the directory block is recorded in the directory underground file name and its inode number;    8, log file system will be more than a record area, at any time to record the main activities of the file system, can speed up the system recovery time;     9, the Linux file system for increased performance, will let the main memory as a large number of disks to tell the cache;    10, the entity link is just one more file name to the inode Number link only;    11, The symbolic link is the shortcut feature of Windows. Put in the file name     12, the use of the disk must go through: Split, format and mount, respectively, the instruction is: Fdisk,mkfs,mount Three instructions     13, boot automatically mount can refer to/etc/fstab settings , you must use MOUNT-A to test the syntax correctly.

Bird Brother's Linux Private Cuisine Foundation Third edition reading notes three Linux disk and file system management

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.