Understanding formatting principles
2020-11-06 21:04:11 【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
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.
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]所创，转载请带上原文链接，感谢
- C++ 数字、string和char*的转换
- Won the CKA + CKS certificate with the highest gold content in kubernetes in 31 days!
- C + + number, string and char * conversion
- C + + Learning -- capacity() and resize() in C + +
- C + + Learning -- about code performance optimization
C + + programming experience (6): using C + + style type conversion
Latest party and government work report ppt - Park ppt
Online ID number extraction birthday tool
Field pointer? Dangling pointer? This article will help you understand!
GVRP of hcna Routing & Switching
- LeetCode 91. 解码方法
- Seq2seq implements chat robot
- [chat robot] principle of seq2seq model
- Leetcode 91. Decoding method
- HCNA Routing＆Switching之GVRP
- GVRP of hcna Routing & Switching
- HDU7016 Random Walk 2
- [Code+＃1]Yazid 的新生舞会
- CF1548C The Three Little Pigs
- HDU7033 Typing Contest
- HDU7016 Random Walk 2
- [code + 1] Yazid's freshman ball
- CF1548C The Three Little Pigs
- HDU7033 Typing Contest
- Qt Creator 自动补齐变慢的解决
- HALCON 20.11：如何处理标定助手品质问题
- HALCON 20.11：标定助手使用注意事项
- Solution of QT creator's automatic replenishment slowing down
- Halcon 20.11: how to deal with the quality problem of calibration assistant
- Halcon 20.11: precautions for use of calibration assistant
- "Top ten scientific and technological issues" announced| Young scientists 50 ² forum
- Reverse linked list
- JS data type
- Remember the bug encountered in reading and writing a file
- Singleton mode
- 在这个 N 多编程语言争霸的世界，C++ 究竟还有没有未来？
- In this world of N programming languages, is there a future for C + +?
- js Promise
- js 数组方法 回顾
- ES6 template characters
- js Promise
- JS array method review
- 【Golang】️走进 Go 语言️ 第一课 Hello World
- [golang] go into go language lesson 1 Hello World