Linux Disk Management (block and Inode)

Source: Internet
Author: User

1 HDD Block and inode details 1.1 Sector (sector) and block (block)

1) Minimum storage unit of the hard disk: sector (sector), each sector is stored 512 bytes; the operating system reads multiple sectors at once, that is, one-time reads multiple sectors called a block

2) Minimum file access unit: block (blocks), composed of multiple sectors, block size is commonly 1KB, 2KB, 4KB, in Linux is commonly set to 4KB, that is, 8 consecutive sectors of a BLOCK;/BOOT partition block is generally 1KB

3) to view block methods:

Ext3 and EXT4 format file system:

dumpe2fs/dev/sda1 | grep "Block Size"

Tune2fs-l/dev/sda1 | grep "Block Size"

stat/boot/| grep "IO Block"

XFS Format File system:

Xfs_info/dev/sda1

stat/boot/| grep "IO Block"

4) Each block can only hold one file, if the file size is larger than block, will apply for more blocks, if the file size is smaller than block, will still occupy a block, the remaining space will be wasted

Example: There are 10,000 files with a size of 10b,block of 4KB

Theoretically occupying space: 10000 * 10B=97.656MB

Amount of space actually occupied: 10000 * 4KB = 40GB

1.2 HDD block and inode details 1.2.1 Superblock, inode and block

Operating system for file data storage consists of two parts: 1 file content, 2 permissions and file attributes

In the hard disk partition, there is also a super block (Superblock)

1) Superblock: Record The overall information of the file system, including the total number of inode and block, usage size, remaining size, file system format and related information, etc.

2) Inode: Log The file's attributes, permissions, and record the block number of the file's data

3) Block: Store the contents of the file

1.2.2 Inode and block

Each inode and block is numbered, and each file occupies a block number where the file data is placed in a inode,inode, and the inode of the file can be found to find the block number of the data placed in the file, thus reading the contents of the file

1) You can specify the default Inode and block size when formatting;-B Specify the default block value,-i specifies the default inode value, for example: Mkfs.ext4–b 4096–i 256/dev/sdb

2) How to view the Inode:

Ext3 and EXT4 format file system:

dumpe2fs/dev/sda1 | grep "Inode Size"

Tune2fs-l/dev/sda1 | grep "Inode Size"

XFS Format File system:

2 Hard Links

Hard Link: Linux system multiple file names can point to the same inode, which means that the same content can be accessed with different file names, and that modifying the contents of the file affects all file names, but deleting a file name does not affect access to another file name.

Hard links can not be linked across partitions, only to the file, the directory is invalid, the linked file does not occupy the system extra space

Command: LN test1.txt test2.txt #test1. txt as the source file, test2 as the destination file

3 Soft links (Symbolic links)

The inode number of the soft link file is different, can cross the partition link, supports the directory also supports the file link, either deletes the source file or restarts the system, the soft link also exists, but the file content is lost, once the new source has the same name file, the soft link file restores the normal

Command: Ln–s test1.txt test2.txt

Linux Disk Management (block and Inode)

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.