Ceph entry to proficiency - Linux disk management (block and inode)

1 Detailed explanation of hard disk block and inode

1.1 Sector (sector) and Block (block)

1) The minimum storage unit of the hard disk: sector (sector), each sector stores 512 bytes; the operating system will read multiple sectors continuously at one time, that is, reading multiple sectors at one time is called a block ( piece)

2) The smallest unit of file access: block (block), which is composed of multiple sectors; the common block size is 1KB, 2KB, 4KB, and the common setting in Linux is 4KB, that is, 8 consecutive sectors form a block ;The block of /boot partition is generally 1KB

3) How to check the block:

ext3 and ext4 formatted filesystems:

       dumpe2fs /dev/sda1 | grep "Block size"

       tune2fs -l /dev/sda1 | grep "Block size"

       stat /boot/ | grep "IO Block"

   xfs formatted file system:

       xfs_info /dev/sda1

 

stat /boot/ | grep "IO Block"

4) Each block can only store one file. If the size of the file is larger than the block, more blocks will be applied; if the size of the file is smaller than the block, it will still occupy a block, and the remaining space will be wasted

Example: There are 10,000 files, the size is 10B, and the block is 4KB

Theoretical occupied space size: 10000 * 10B=97.656MB

Actual occupied space size: 10000 * 4KB = 40GB

1.2 Detailed explanation of hard disk block and inode

1.2.1   superblock、inode 与 block

The storage of file data by the operating system includes 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 amount of inodes and blocks, used size, remaining size, file system format and related information, etc.

2) inode: record the attributes and permissions of the file, and record the block number where the data of the file is located

3) block: store the content of the file

1.2.2 inodes and blocks

Each inode and block has a number, and each file will occupy an inode, and the inode contains the block number of the file data; if you can find the inode of the file, you can find the block number of the data placed in the file, so as to read the file content

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

2) How to check inode:

ext3 and ext4 formatted filesystems:

dumpe2fs /dev/sda1 | grep "Inode size"

tune2fs -l /dev/sda1 | grep "Inode size"

 

   xfs formatted file system:

 

2 hard links

Hard link: Multiple file names in the Linux system can point to the same inode, which means that you can use different file names to access the same content, and modifying the file content will affect all file names; but deleting a file name will not affect other A filename access.

Hard links cannot be linked across partitions. They can only be effective for files and not for directories. The linked files do not take up extra space in the system.

Command: ln test1.txt test2.txt #test1.txt is the source file, test2 is the target file

 

3 Soft links (symbolic links)

The Inode number of the soft link file is different, and it can be linked across partitions. It supports directories and also supports file links; whether the source file is deleted or the system is restarted, the soft link still exists, but the file content will be lost. Once a new source file with the same name is created, the soft link Linked files back to normal

Instruction: ln –s test1.txt test2.txt

 

Guess you like

Origin blog.csdn.net/wxb880114/article/details/131963686