Centos的Inode及Block相關知識

來源:互聯網
上載者:User

Centos的Inode及Block相關知識

本經驗均在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

2>Linux中df命令的功能是用來檢查linux伺服器的檔案系統的磁碟空間佔用情況。可以利用該命令來擷取硬碟被佔用了多少空間,目前還剩下多少空間等資訊。
1.命令格式:
df [選項] [檔案]

2.參數 :

df -i 查看參數多少 個

[root@techW~]#df-iFilesystemInodesIUsedIFreeIUse%Mountedon/dev/mapper/vg_techw-lv_root11528165584610969705%/tmpfs12559611255951%/dev/shm/dev/sda1128016381279781%/boot

df -h 查看磁碟大小:

[root@techW~]#df-hFilesystemSizeUsedAvailUse%Mountedon/dev/mapper/vg_techw-lv_root18G1.5G15G9%/tmpfs491M0491M0%/dev/shm/dev/sda1477M36M416M8%/boot

查看當前系統磁碟分割的Inode及Block的總量及使用量:

[root@techW~]#dumpe2fs/dev/sda1|grep-i"blocksize"dumpe2fs1.41.12(17-May-2010)Blocksize:1024[root@techW~]#[root@techW~]#[root@techW~]#dumpe2fs/dev/sda1|grep-i"inodesize"dumpe2fs1.41.12(17-May-2010)Inodesize:128###boot分區為128,常規分區為256[root@techW~]#[root@techW~]#[root@techW~]#dumpe2fs/dev/sda1|grep-i"inodecount"dumpe2fs1.41.12(17-May-2010)Inodecount:128016[root@techW~]#[root@techW~]#dumpe2fs/dev/sda1|grep-i"blockcount"dumpe2fs1.41.12(17-May-2010)Blockcount:512000Reservedblockcount:25600

3>添加一塊磁碟,格式化,改變Inode及 Block的大小,掛載查看硬碟的Inode及Block數量:

1)添加一塊5G的磁碟,為方便區分設定為/dev/sdb,fdisk分區,然後mkfs.ext4格式化

(虛擬機器增加一塊5G的硬碟,分區,格式化)

[root@techW~]#fdisk/dev/sdbDevicecontainsneitheravalidDOSpartitiontable,norSun,SGIorOSFdisklabelBuildinganewDOSdisklabelwithdiskidentifier0x2d37eabe.Changeswillremaininmemoryonly,untilyoudecidetowritethem.Afterthat,ofcourse,thepreviouscontentwon'tberecoverable.Warning:invalidflag0x0000ofpartitiontable4willbecorrectedbyw(rite)WARNING:DOS-compatiblemodeisdeprecated.It'sstronglyrecommendedtoswitchoffthemode(command'c')andchangedisplayunitstosectors(command'u').Command(mforhelp):n###addanewpartitionCommandactioneextendedpprimarypartition(1-4)pPartitionnumber(1-4):2###為做區分,選擇2Firstcylinder(1-652,default1):Usingdefaultvalue1Lastcylinder,+cylindersor+size{K,M,G}(1-652,default652):Usingdefaultvalue652Command(mforhelp):w###writetabletodiskandexitThepartitiontablehasbeenaltered!Callingioctl()tore-readpartitiontable.Syncingdisks.分區時的參數命令:atoggleabootableflagbeditbsddisklabelctogglethedoscompatibilityflagddeleteapartitionllistknownpartitiontypesmprintthismenunaddanewpartitionocreateanewemptyDOSpartitiontablepprintthepartitiontableqquitwithoutsavingchangesscreateanewemptySundisklabeltchangeapartition'ssystemiduchangedisplay/entryunitsvverifythepartitiontablewwritetabletodiskandexitxextrafunctionality(expertsonly)

[root@techW~]#mkfs.ext4/dev/sdb2mke2fs1.41.12(17-May-2010)Filesystemlabel=OStype:LinuxBlocksize=4096(log=2)###預設的Block的大小為4096Fragmentsize=4096(log=2)Stride=0blocks,Stripewidth=0blocks327680inodes,1309289blocks65464blocks(5.00%)reservedforthesuperuserFirstdatablock=0Maximumfilesystemblocks=134217728040blockgroups32768blockspergroup,32768fragmentspergroup8192inodespergroupSuperblockbackupsstoredonblocks:32768,98304,163840,229376,294912,819200,884736Writinginodetables:doneCreatingjournal(32768blocks):doneWritingsuperblocksandfilesystemaccountinginformation:doneThisfilesystemwillbeautomaticallycheckedevery26mountsor180days,whichevercomesfirst.Usetune2fs-cor-itooverride.

2)###inode的大小範圍為128-2048,block的大小範圍為1024-4096####

3)將Block和Inode的大小都改為2048:

[root@techW~]#mkfs.ext4-b2048-I2048/dev/sdb2mke2fs1.41.12(17-May-2010)Filesystemlabel=OStype:LinuxBlocksize=2048(log=1)Fragmentsize=2048(log=1)Stride=0blocks,Stripewidth=0blocks326400inodes,2618578blocks130928blocks(5.00%)reservedforthesuperuserFirstdatablock=0Maximumfilesystemblocks=540016640160blockgroups16384blockspergroup,16384fragmentspergroup2040inodespergroupSuperblockbackupsstoredonblocks:16384,49152,81920,114688,147456,409600,442368,802816,1327104,2048000Writinginodetables:doneCreatingjournal(32768blocks):doneWritingsuperblocksandfilesystemaccountinginformation:doneThisfilesystemwillbeautomaticallycheckedevery30mountsor180days,whichevercomesfirst.Usetune2fs-cor-itooverride.

4)使用dumpe2fs命令查詢Inode和Block的大小:

[root@techW~]#dumpe2fs/dev/sdb2|grep"Inodesize"dumpe2fs1.41.12(17-May-2010)Inodesize:2048###大小更改成功[root@techW~]#s/dev/sdb2|grep"Blocksize"dumpe2fs1.41.12(17-May-2010)Blocksize:2048###大小更改成功

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.