1. Inode and Block overview
After the partition of each Linux storage device or storage device is formatted (EXT3,EXT4, etc.), there are usually two parts: the Inode, and the other part is the block. Block is used to store the actual data, and the inode is used to store the data of the attribute information, including the size of the file, the owner, the user group, read and Write permissions, file type, modification time, but also to the file entity pointer function (inode node to block the corresponding relationship), etc. But it does not contain a file name. The file name is usually stored in the block of the directory in which it resides.
In addition to logging file attribute information, the inode will also index each file, so there are inode values, and the first column of output information can be seen with the Ls-li command as the index value of each file:
[[email protected] ~]# ls -litotal 64 26 -rw-r--r--. 1 root root 585 Feb 20 23:29 70-PERSISTENT-NET.RULES147011 -RW-------. 1 root root 1206 oct 17 13:46 anaconda-ks.cfg151004 -rw-r--r-- 1 root root 137 oct 17 14:02 ifcfg-eth0.ori130308 -rw-r--r--. 1 root root 30148 oct 17 13:46 install.log130309 -rw-r--r--. 1 root root 7119 Oct 17 13:45 install.log.syslog157559 -rw-r--r-- 1 root root 823 feb 25 19:49 optimise_sysctl157552 -rw-r--r-- 1 root root 1150 nov 23 2013 sysctl.conf.ori
2. Simple process for accessing files
When a user attempts to access a file in a Linux system, the system first finds its inode based on the file name, to see if the user has permission to access the file. If so, point to the corresponding file data block, and if there is no permission, return to permission denied.
3. The size of the Inode
Because the inode wants to store the file's attribute information, it is also of a size. The default size of the Inode is 128 bytes in the CentOS 5.x system, and 256 bytes in CentOS 6.x. The size of the inode can be specified when the file system of the storage device is created, and cannot be changed after formatting. However, there is no such requirement in the general working environment. You can use the DUMPE2FS command to view the inode size in the current system:
[[email protected] ~]# dumpe2fs /dev/sda3 | grep -i "Inode size" dumpe2fs 1.41.12 (17-may-2010) inode size: 256[[email protected] ~]# dumpe2fs /dev/sda1 | grep -i "Inode size "dumpe2fs 1.41.12 (17-may-2010) inode size: 128[[email protected] ~]# df -hFilesystem Size Used Avail Use% Mounted on/dev/sda3 9.2G 5.0G 3.7G 58% /tmpfs 242m 0 242m 0% /dev/shm/dev/sda1 194m 29m 155m 16% /boot
My system is CentOS 6.5, as you can see, the default inode size for the/boot partition is still 128, and the root partition (regular partition) is 256.
4. Size of block
In ext3 or EXT4 file systems, the block size is generally 1k,2k or 4k. In my CentOS 6.5 system, the block size of the boot partition is 1k, and the regular partition is 4k:
[Email protected] ~]# DUMPE2FS/DEV/SDA1 | Grep-i "Block Size" dumpe2fs 1.41.12 (17-may-2010) block Size:1024[[email protected] ~]# Dumpe2fs/dev/sda3 | Grep-i "Block Size" dumpe2fs 1.41.12 (17-may-2010) block size:4096
5. Number of Inode and block
If you want to see the number and usage of the inode on the disk, you can use the Df-i command:
[Email protected] ~]# df-ifilesystem inodes iused IFree iuse% mounted On/dev/sda3 610800 110679 500121 19% /TMPFS 61778 1 61777 1%/dev/shm/dev/sda1 51200 $51162 1%/boot
You can also use the DUMPE2FS command to view the total number of inode and block in a partition:
[Email protected] ~]# Dumpe2fs/dev/sda3 | Grep-i "Inode count" Dumpe2fs 1.41.12 (17-may-2010) inode count:610800[[email protected] ~]# DUMPE2FS/DEV/SD A3 | Grep-i "Block Count" Dumpe2fs 1.41.12 (17-may-2010) block count:2438912reserved block count:121945
6. Correspondence between files, Inode, and block
The disk read file data is read in block units. No matter how much a file must occupy an inode and at least one block, a block can only be used by one file, and an inode can be occupied by multiple files (hard link).
7. Block Size selection
Because a block can only be used by one file, the block is not as large as possible. The larger the block, the more space is wasted on small files (below 1k or at least 4k), but for applications with large files, such as video and multimedia files, reading can improve the efficiency of reading, because the larger the block, Fewer blocks are required to read files of the same size, reducing disk IO consumption. If the block is too small, it will reduce the efficiency of the disk to read large files because more blocks need to be read. In fact, for the Ext3/ext4 file system, there are only three options for block size: 1k, 2k, 4k.
8. How to change the size of the inode and block
The size of the inode and block can only be changed at the time of formatting, as in the case of the Ext4 file system:
[Email protected] ~]# mkfs.ext4-b 2048-i 2048/dev/sda2
For information on how to choose File system types and block sizes in a production environment, refer to this blog: http://blog.csdn.net/liuaigui/article/details/5521024
Linux system Inode and block knowledge detailed