设为首页 收藏本站
查看: 700|回复: 0

[经验分享] Linux Centos的Inode及Block相关知识

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-6-1 16:49:47 | 显示全部楼层 |阅读模式
本经验均在CentOSrelease6.7(Final)下操作,如知识有欠缺之处 欢迎批评指正。linux 的inode及block的相关知识:
1>  Linux系统分区格式化文件系统之后,系统会分为Inode及Block两部分:
    1)Inode为系统文件的属性信息(ls -l的结果)及指向文件实体的指针,但是没有存放文件名,一般在上级目录里的Block。
    2)Block为存放数据的,ext3/ext4一般为1k,2k,4k,一般默认4k
    3)一个文件不论多大至少占用一个Inode和一个Block,一个Block只能存放一个文件的内容,block的数量大于Inode的数量,多个文件可以占用同一个 inode(硬链接) 。
    4)访问文件, 通过文件-->inode(验证权限)--->blocks.
    5)inode 一般情况默认256B,block大小1k,2k,4k,默认4k,注意,引导分区等特殊分区除外。
    6)通过df -i 查看inode的数量及使用情况,dumpe2fs /dev/sda1  查看inode及block的大小和数量。
    7)一个block只能 被一个文件使用 ,如果一个文件很小block太大,剩余空间浪费,无法继续被其他文件使用。
    8)block不是越大越好,根据业务的文件大小进行选择,一般就是默认 4k。
    9)可以在格式化的时候改变inode及block的大小,使用mkfs.ext4 -b 2048 -I 1024  /dev/sdb2
QQ截图20160601164935.jpg





2>Linux中df命令的功能是用来检查linux服务器的文件系统的磁盘空间占用情况。可以利用该命令来获取硬盘被占用了多少空间,目前还剩下多少空间等信息。
1.命令格式:
df [选项] [文件]
2.参数 :
df -i  查看参数多少 个
1
2
3
4
5
6
[iyunv@techW ~]# df -i
Filesystem            Inodes IUsed   IFree IUse% Mounted on
/dev/mapper/vg_techw-lv_root
                     1152816 55846 1096970    5% /
tmpfs                 125596     1  125595    1% /dev/shm
/dev/sda1             128016    38  127978    1% /boot



df -h  查看磁盘大小:
1
2
3
4
5
6
[iyunv@techW ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_techw-lv_root
                       18G  1.5G   15G   9% /
tmpfs                 491M     0  491M   0% /dev/shm
/dev/sda1             477M   36M  416M   8% /boot





查看当前系统分区的Inode及Block的总量及使用量:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[iyunv@techW ~]# dumpe2fs  /dev/sda1 | grep -i "block size"
dumpe2fs 1.41.12 (17-May-2010)
Block size:               1024
[iyunv@techW ~]#
[iyunv@techW ~]#
[iyunv@techW ~]# dumpe2fs  /dev/sda1 | grep -i "inode size"
dumpe2fs 1.41.12 (17-May-2010)
Inode size:               128    ###boot分区为128,常规分区为256
[iyunv@techW ~]#
[iyunv@techW ~]#
[iyunv@techW ~]# dumpe2fs  /dev/sda1 | grep -i "inode count"
dumpe2fs 1.41.12 (17-May-2010)
Inode count:              128016
[iyunv@techW ~]#
[iyunv@techW ~]# dumpe2fs  /dev/sda1 | grep -i "block count"
dumpe2fs 1.41.12 (17-May-2010)
Block count:              512000
Reserved block count:     25600



3>添加一块磁盘,格式化,改变Inode及 Block的大小,挂载查看硬盘的Inode及Block数量:
1)添加一块5G的磁盘,为方便区分设置为/dev/sdb,fdisk分区,然后mkfs.ext4格式化
(虚拟机增加一块5G的硬盘,分区,格式化)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
[iyunv@techW ~]# fdisk  /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x2d37eabe.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').
Command (m for help):  n ### add a new partition
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2  ### 为做区分,选择2
First cylinder (1-652, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-652, default 652):
Using default value 652
Command (m for help): w   ###  write table to disk and exit
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

分区时的参数命令:
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[iyunv@techW ~]# mkfs.ext4 /dev/sdb2
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)    ###默认的Block的大小为4096
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1309289 blocks
65464 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736
Writing inode tables: done                           
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 26 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.




2)###inode的大小范围为128-2048,block的大小范围为1024-4096####


3)将Block和Inode的大小都改为2048:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[iyunv@techW ~]# mkfs.ext4 -b 2048 -I 2048 /dev/sdb2
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=2048 (log=1)
Fragment size=2048 (log=1)
Stride=0 blocks, Stripe width=0 blocks
326400 inodes, 2618578 blocks
130928 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=540016640
160 block groups
16384 blocks per group, 16384 fragments per group
2040 inodes per group
Superblock backups stored on blocks:
        16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816, 1327104,
        2048000
Writing inode tables: done                           
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 30 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.




4)使用dumpe2fs命令查询Inode和Block的大小:
1
2
3
4
5
6
7
[iyunv@techW ~]# dumpe2fs  /dev/sdb2 | grep "Inode size"
dumpe2fs 1.41.12 (17-May-2010)
Inode size:               2048  ###大小更改成功
[iyunv@techW ~]#
s  /dev/sdb2 | grep "Block size"
dumpe2fs 1.41.12 (17-May-2010)
Block size:               2048  ###大小更改成功






运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-224904-1-1.html 上篇帖子: epoll实现socket通信 下篇帖子: Ubuntu 下解决【no crontab for root - using an empty one】方法 Linux 知识
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表