Linux Centos的Inode及Block相关知识

<p>本经验均在CentOSrelease6.7(Final)下操作,如知识有欠缺之处 欢迎批评指正。</p><p>linux 的inode及block的相关知识:</p><p>1&gt; Linux系统分区格式化文件系统之后,系统会分为Inode及Block两部分:</p><p>1)Inode为系统文件的属性信息(ls -l的结果)及指向文件实体的指针,但是没有存放文件名,一般在上级目录里的Block。</p><p>2)Block为存放数据的,ext3/ext4一般为1k,2k,4k,一般默认4k</p><p>3)一个文件不论多大至少占用一个Inode和一个Block,一个Block只能存放一个文件的内容,block的数量大于Inode的数量,多个文件可以占用同一个 inode(硬链接) 。</p><p>4)访问文件, 通过文件--&gt;inode(验证权限)---&gt;blocks.</p><p>5)inode 一般情况默认256B,block大小1k,2k,4k,默认4k,注意,引导分区等特殊分区除外。</p><p>6)通过df -i 查看inode的数量及使用情况,dumpe2fs /dev/sda1 查看inode及block的大小和数量。</p><p>7)一个block只能 被一个文件使用 ,如果一个文件很小block太大,剩余空间浪费,无法继续被其他文件使用。</p><p>8)block不是越大越好,根据业务的文件大小进行选择,一般就是默认 4k。</p><p>9)可以在格式化的时候改变inode及block的大小,使用mkfs.ext4 -b 2048 -I 1024 /dev/sdb2</p><p>2&gt;Linux中df命令的功能是用来检查linux服务器的文件系统的磁盘空间占用情况。可以利用该命令来获取硬盘被占用了多少空间,目前还剩下多少空间等信息。</p><p>1.命令格式:</p><p>df [选项] [文件]</p><p>2.参数 :</p><p>df -i 查看参数多少 个</p><pre class="brush:cpp;toolbar:false">[root@techW~]#df-i FilesystemInodesIUsedIFreeIUse%Mountedon /dev/mapper/vg_techw-lv_root 11528165584610969705%/ tmpfs12559611255951%/dev/shm /dev/sda1128016381279781%/boot</pre><p>df -h 查看磁盘大小:</p><pre class="brush:cpp;toolbar:false">[root@techW~]#df-h FilesystemSizeUsedAvailUse%Mountedon /dev/mapper/vg_techw-lv_root 18G1.5G15G9%/ tmpfs491M0491M0%/dev/shm /dev/sda1477M36M416M8%/boot</pre><p>查看当前系统分区的Inode及Block的总量及使用量:</p><p>[root@techW ~]# dumpe2fs /dev/sda1 | grep -i &quot;block size&quot;</p><pre class="brush:cpp;toolbar:false">dumpe2fs1.41.12(17-May-2010) Blocksize:1024 [root@techW~]# [root@techW~]# [root@techW~]#dumpe2fs/dev/sda1|grep-i&quot;inodesize&quot; dumpe2fs1.41.12(17-May-2010) Inodesize:128###boot分区为128,常规分区为256 [root@techW~]# [root@techW~]# [root@techW~]#dumpe2fs/dev/sda1|grep-i&quot;inodecount&quot; dumpe2fs1.41.12(17-May-2010) Inodecount:128016 [root@techW~]# [root@techW~]#dumpe2fs/dev/sda1|grep-i&quot;blockcount&quot; dumpe2fs1.41.12(17-May-2010) Blockcount:512000 Reservedblockcount:25600</pre><p>3&gt;添加一块磁盘,格式化,改变Inode及 Block的大小,挂载查看硬盘的Inode及Block数量:</p><p>1)添加一块5G的磁盘,为方便区分设置为/dev/sdb,fdisk分区,然后mkfs.ext4格式化</p><p>(虚拟机增加一块5G的硬盘,分区,格式化)</p><p>[root@techW ~]# fdisk /dev/sdb</p><p>Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel</p><p>Building a new DOS disklabel with disk identifier 0x2d37eabe.</p><p>Changes will remain in memory only, until you decide to write them.</p><p>After that, of course, the previous content won&#39;t be recoverable.</p><p>Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)</p><p>WARNING: DOS-compatible mode is deprecated. It&#39;s strongly recommended to</p><p> switch off the mode (command &#39;c&#39;) and change display units to</p><p> sectors (command &#39;u&#39;).</p><p>Command (m for help): n ### add a new partition</p><p>Command action</p><p> e extended</p><p> p primary partition (1-4)</p><p>p</p><p>Partition number (1-4): 2 ### 为做区分,选择2</p><p>First cylinder (1-652, default 1):</p><p>Using default value 1</p><p>Last cylinder, +cylinders or +size{K,M,G} (1-652, default 652):</p><p>Using default value 652</p><p>Command (m for help): w ### write table to disk and exit</p><p>The partition table has been altered!</p><p>Calling ioctl() to re-read partition table.</p><p>Syncing disks.</p><p>分区时的参数命令:</p><p> a toggle a bootable flag</p><p> b edit bsd disklabel</p><p> c toggle the dos compatibility flag</p><p> d delete a partition</p><p> l list known partition types</p><p> m print this menu</p><p> n add a new partition</p><p> o create a new empty DOS partition table</p><p> p print the partition table</p><p> q quit without saving changes</p><p> s create a new empty Sun disklabel</p><p> t change a partition&#39;s system id</p><p> u change display/entry units</p><p> v verify the partition table</p><p> w write table to disk and exit</p><p> x extra functionality (experts only)</p><pre class="brush:cpp;toolbar:false">[root@techW~]#mkfs.ext4/dev/sdb2 mke2fs1.41.12(17-May-2010) Filesystemlabel= OStype:Linux Blocksize=4096(log=2)###默认的Block的大小为4096 Fragmentsize=4096(log=2) Stride=0blocks,Stripewidth=0blocks 327680inodes,1309289blocks 65464blocks(5.00%)reservedforthesuperuser Firstdatablock=0 Maximumfilesystemblocks=1342177280 40blockgroups 32768blockspergroup,32768fragmentspergroup 8192inodespergroup Superblockbackupsstoredonblocks: 32768,98304,163840,229376,294912,819200,884736 Writinginodetables:done Creatingjournal(32768blocks):done Writingsuperblocksandfilesystemaccountinginformation:done Thisfilesystemwillbeautomaticallycheckedevery26mountsor 180days,whichevercomesfirst.Usetune2fs-cor-itooverride.</pre><p>2)###inode的大小范围为128-2048,block的大小范围为1024-4096####</p><p>3)将Block和Inode的大小都改为2048:</p><pre class="brush:cpp;toolbar:false">[root@techW~]#mkfs.ext4-b2048-I2048/dev/sdb2 mke2fs1.41.12(17-May-2010) Filesystemlabel= OStype:Linux Blocksize=2048(log=1) Fragmentsize=2048(log=1) Stride=0blocks,Stripewidth=0blocks 326400inodes,2618578blocks 130928blocks(5.00%)reservedforthesuperuser Firstdatablock=0 Maximumfilesystemblocks=540016640 160blockgroups 16384blockspergroup,16384fragmentspergroup 2040inodespergroup Superblockbackupsstoredonblocks: 16384,49152,81920,114688,147456,409600,442368,802816,1327104, 2048000 Writinginodetables:done Creatingjournal(32768blocks):done Writingsuperblocksandfilesystemaccountinginformation:done Thisfilesystemwillbeautomaticallycheckedevery30mountsor 180days,whichevercomesfirst.Usetune2fs-cor-itooverride.</pre><p>4)使用dumpe2fs命令查询Inode和Block的大小:</p><pre class="brush:cpp;toolbar:false">[root@techW~]#dumpe2fs/dev/sdb2|grep&quot;Inodesize&quot; dumpe2fs1.41.12(17-May-2010) Inodesize:2048###大小更改成功 [root@techW~]# s/dev/sdb2|grep&quot;Blocksize&quot; dumpe2fs1.41.12(17-May-2010) Blocksize:2048###大小更改成功</pre>
返回顶部 留言