当前位置:网站首页>Understanding formatting principles
Understanding formatting principles
2020-11-06 21:04:00 【Zhang Yanfei Allen】
In the foreword 《 Disk opening : Remove the hard shell of the mechanical hard disk !》 and 《 Disassemble the SSD structure 》 in , We learned that the basic unit of hard disk is sector . stay 《 Disk partitioning also implies technical skills 》 We also learned about how disk partitioning works , However, the hard disk just divided can not be directly used by the operating system , It has to be formatted . So let's have a brief talk today ,Linux What's going on in the format below .
Linux The format command is mkfs
,mkfs When formatting, you need to specify the partition and file system type . This command is actually to partition and manage our continuous disk space . I did it on my machine , Output is as follows :
# mkfs -t ext4 /dev/vdb
mke2fs 1.42.9 (28-Dec-2013)
File system tags =
OS type: Linux
Block size =4096 (log=2)
Block size =4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
6553600 inodes, 26214400 blocks
1310720 blocks (5.00%) reserved for the super user
The first data block =0
Maximum filesystem blocks=2174746624
800 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, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872
Let's take a closer look at the information carried in the output above .
inode And block
In the above results, we see several important information
- Block size :4096 byte
- inode Number :6553600
- block Number :26214400
The block size is set to 4096 byte , Let's analyze two scenarios
- If your file system is all for storage 1KB The following little file , This time your disk 1/3 Space will be wasted and unusable .
- If all your papers are GB The big documents above , This is your inode In an index node, you need to maintain many of them directly or indirectly block Reference no.
Obviously , In both cases 4096 The block size of bytes is not appropriate . You need to choose your own block size and reformat it .
Let's look at the other two data ,inode Quantity and sum block Number . We use it block Divide the quantity by inode,26214400/6553600=4, That is to say, on average 4 individual block There will be one. inode. Two more extreme examples :
- Case one , Let's say our documents are all 4KB Following , So the last thing that we use our file system is inode It's all used up , also 1/3 Of block Free , And there's no way to create new files anymore .
- The second case , If our files are all very large , Every document needs 1000 individual block, The end result is block It's all used up , however inode It's all free again , There is no way to create documents at this time .
In these cases ,block and inode The ratio is not suitable for your use , You need to reconfigure according to your business .mkfs The results in a fool's format can't meet your business needs , You need to use some other formatting commands , such as mke2fs, This command allows you to enter more detailed formatting options ,demo as follows :
mke2fs -j -L " Volume label " -b 2048 -i 8192 /dev/sdb1
Block group
Let's go back to the formatted results , The results show some and groups Related east east , as follows :
800 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
So this groups What the hell is that ? In fact! , All formatted inode It's not placed next to each other , Again block Neither . It's divided into group, every last group There are some in it inode and block. The logic diagram is as follows :
How big is this block group ? Note that there is only one data block bitmap in each block , If your block size is 4KB, Such a bit Represents a block of data ,4KB There can be 32KB individual bit, Can manage 32K*4K=128M A block of data . Let's actually verify , as follows :
# dumpe2fs /dev/vdb
......
Block size: 4096
Inode size: 256
Inode count: 6553600
Block count: 26214400
......
Group 16: (Blocks 524288-557055) [INODE_UNINIT, ITABLE_ZEROED]
Checksum 0xe838, unused inodes 8192
Block bitmap at 524288 (+0), Inode bitmap at 524304 (+16)
Inode The watch is located in 524320-524831 (+32)
24544 free blocks, 8192 free inodes, 0 directories, 8192 Unused inodes
Number of blocks available : 532512-557055
You can use inode Count : 131073-139264
......
Group 799: (Blocks 26181632-26214399) [INODE_UNINIT, ITABLE_ZEROED]
......
The information contained in the above results is as follows :
- The partition has been formatted in total 800 Block groups
- Block group 16 share 32K individual block( The first 524288-557055),
- block The bitmap is in 524288 On this block
- inode The bitmap is in 524304 On this block
- inode table Occupied 612 individual block(524320-524831)
- The rest of it block(32K-1-1-612) It's really for users , At present, the idle and unallocated are in Free blocks You can see that .
Understand the table of contents again
Okay , After understanding the above principles , Let's go back and see how the data used by directories is organized on disk . When you create a directory , The operating system will be in inode Find unused on bitmap inode Number , When you find it, put inode Assigned to you . The directory will be assigned a by default block, So we need to check block Bitmap , Find and assign one block. stay block Inside , What is stored is defined by the file system itself desty It's structured , Each structure will save the file name under it , Of documents inode Number and other information . The final space used by an actual folder on disk is shown in the figure below :
The directory block The files and subdirectories under it are saved in desty Structure , Save their file names and inode Number . Understand the catalog , The same is true for documents . Also need to consume inode, When data is written , Apply again block.
Conclusion
A hard disk is a large array of sectors , It can't be used by us , It needs to be partitioned 、 Format and mount three steps . Partition is to divide all sectors into different blocks according to the cylinder , Formatting changes the original array of sectors into a Linux The file system uses inode、block Wait for the basic elements . The formatter feels a little bit like the chopper in the chef team , Turn raw materials into scallion that can be directly used by cooks , Meat section . After formatting, mount it through the last step , The corresponding order is mount
, Then you can create and save files under it .
In fact, the equipment that has just been partitioned can also be used , The partition at this time is called bare partition , It's also called naked devices . such as oracle It is to bypass the operating system and use naked devices directly . But you can't use it at this time Linux It's packaged for you in the file system inode、block Composed of files and directories , The development workload will increase .
The most time-consuming part of writing is drawing , I'm going blind , Give me a compliment when I pass by , Thank you !
Development of hard disk album of internal training :
- 1. Disk opening : Take off the hard coat of the mechanical hard disk !
- 2. Disk partitioning also implies technical skills
- 3. How can we solve the problem that mechanical hard disks are slow and easy to break down ?
- 4. Disassemble the SSD structure
- 5. How much disk space does a new empty file take ?
- 6. Only 1 How much disk space does a byte file actually take up
- 7. When there are too many documents ls Why is the command stuck ?
- 8. Understand the principle of formatting
- 9.read How much disk does a byte of file actually take place on IO?
- 10.write When to write to disk after one byte of file IO?
- 11. Mechanical hard disk random IO Slower than you think
- 12. How much faster is a server equipped with a SSD than a mechanical hard disk ?
My official account is 「 Develop internal skill and practice 」, I'm not just talking about technical theory here , It's not just about practical experience . It's about combining theory with practice , Deepen the understanding of theory with practice 、 Use theory to improve your technical practice ability . Welcome to my official account , Please also share with your friends ~~~
版权声明
本文为[Zhang Yanfei Allen]所创,转载请带上原文链接,感谢
边栏推荐
- CCR coin frying robot: the boss of bitcoin digital currency, what you have to know
- Contract trading system development | construction of smart contract trading platform
- Get twice the result with half the effort: automation without cabinet
- 行为型模式之备忘录模式
- nacos、ribbon和feign的簡明教程
- From overseas to China, rancher wants to do research on container cloud market
- 【:: 是什么语法?】
- Staying up late summarizes the key points of report automation, data visualization and mining, which is different from what you think
- JVM内存分配 -Xms128m -Xmx512m -XX:PermSize=128m -XX:MaxPermSize=512m
- 使用 Iceberg on Kubernetes 打造新一代雲原生資料湖
猜你喜欢
With this artifact, quickly say goodbye to spam messages
An article will take you to understand CSS alignment
Behind the first lane level navigation in the industry
CCR coin frying robot: the boss of bitcoin digital currency, what you have to know
ES6 learning notes (4): easy to understand the new grammar of ES6
事件监听问题
递归、回溯算法常用数学基础公式
Swagger 3.0 brushes the screen every day. Does it really smell good?
What is the purchasing supplier system? Solution of purchasing supplier management platform
An article taught you to use HTML5 SVG tags
随机推荐
Multi robot market share solution
window系统 本机查找端口号占用方法
Will blockchain be the antidote to the global epidemic accelerating the transformation of Internet enterprises?
Read the advantages of Wi Fi 6 over Wi Fi 5 in 3 minutes
The method of realizing high SLO on large scale kubernetes cluster
Python basic variable type -- list analysis
list转换map(根据key来拆分list,相同key的value为一个list)
Share with Lianyun: is IPFs / filecoin worth investing in?
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
意外的元素..所需元素..
DC-1靶機
一路踩坑,被迫聊聊 C# 代码调试技巧和远程调试
小游戏云开发入门
[efficiency optimization] Nani? Memory overflow again?! It's time to sum up the wave!!
ES6 learning notes (3): teach you to use js object-oriented thinking to realize the function of adding, deleting, modifying and checking tab column
【学习】接口测试用例编写和测试关注点
Tron smart wallet PHP development kit [zero TRX collection]
C#和C/C++混合编程系列5-内存管理之GC协同
Bitcoin once exceeded 14000 US dollars and is about to face the test of the US election
An article takes you to understand CSS gradient knowledge