当前位置:   article > 正文

[svc]为何linux ext4文件系统目录默认大小是4k?

为什么创建一个目录就有4k

linux ext4普通盘为什么目录大小是4k?

Why does every directory have a size 4096 bytes (4 K)?
To understand this, you'd better have some basic knowledge of the following (file system):

  • inode (contains file attributes, metadata of file, pointer structure)
  • file (can be considered a table with 2 columns, filename and its inode, inode points to the raw data blocks on the block device)
  • directory (just a special file, container for other filenames. It contains an array of filenames and inode numbers for each filename. Also it describes the relationship between parent and children.)
  • symbolic link VS hard link
  • dentry (directory entries)
    ...
    On typical ext4 file system (I reckon most likely this is what you are using), the default inode size is 256 bytes, block size is 4096 bytes.

A directory is just a special file which contains an array of filenames and inode numbers. When the directory was created, the file system allocated 1 inode to the directory with a "filename" (dir name in fact). The inode points to a single data block (minimum overhead), which is 4096 bytes. That's why you see 4096 / 4.0K when using ls.

要理解这个,你首先要懂:(注: 这里我用c7.4,默认xfs:/etc/fstab,我又挂了一个格式化成ext4做的实验)

  1. inode:
  2. file
  3. directory
  4. symblic: 软链接

参阅:
磁盘MBR分区机制- inode/Block深入实战
linux的inode和block-软硬链接

806469-20180305205644145-2050317113.png
我猜目录名字占了第一个inode-index.
806469-20180305211602324-1847878562.png

inode-index和inodetable单独开辟了一个block

806469-20180305213458179-103232273.png

目录是特殊的文件,目录内容包含: 文件名+inode号, 当目录被创建后,文件系统会给这个目录分配1个inode+特殊文件(即以目录为名). inode指向一个block. 所有你才会看到目录大小为4k.

这就能理解目录里的文件,文件名字保存在了所在目录的block里.

查看和修改ext4的inode和block

ext4 默认inode大小是256bytes, block大小是4096bytes

  1. [root@moban ~]# dumpe2fs /dev/sdb |grep "Inode size"
  2. Inode size: 256
  3. [root@moban ~]# dumpe2fs /dev/sdb |grep "Block size"
  4. Block size: 4096
  5. - 格式化时候指定inode和block大小
  6. [root@moban ~]# mkfs.ext4 -I 2048 -b 2048 /dev/sdb

查看目录的inode内容

806469-20180305210151947-1761495704.png

806469-20180305210059302-386922743.png

转载于:https://www.cnblogs.com/iiiiher/p/8511351.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/185466
推荐阅读
相关标签
  

闽ICP备14008679号