当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- 代码生成器插件与Creator预制体文件解析
- 事务的隔离级别与所带来的问题
- Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
- Contract trading system development | construction of smart contract trading platform
- C#和C/C++混合编程系列5-内存管理之GC协同
- Elasticsearch Part 6: aggregate statistical query
- An article takes you to understand CSS3 picture border
- 【:: 是什么语法?】
- 大数据处理黑科技:揭秘PB级数仓GaussDB(DWS) 并行计算技术
- python100例項
猜你喜欢
如何在终端启动Coda 2中隐藏的首选项?
window系统 本机查找端口号占用方法
IPFs rudder filecoin landing at the same time, fil currency price broke a thousand
GUI engine evaluation index
An article will take you to understand SVG gradient knowledge
Ronglian completed US $125 million f round financing
To teach you to easily understand the basic usage of Vue codemirror: mainly to achieve code editing, verification prompt, code formatting
FastThreadLocal 是什么鬼?吊打 ThreadLocal 的存在!!
An article taught you to use HTML5 SVG tags
Behind the first lane level navigation in the industry
随机推荐
electron 實現檔案下載管理器
常用SQL语句总结
The importance of big data application is reflected in all aspects
jenkins安装部署过程简记
Analysis of serilog source code -- how to use it
An article will take you to understand SVG gradient knowledge
An article will take you to understand CSS3 fillet knowledge
嘉宾专访|2020 PostgreSQL亚洲大会阿里云数据库专场:王涛
一路踩坑,被迫聊聊 C# 代码调试技巧和远程调试
How does filecoin's economic model and future value support the price of fil currency breaking through thousands
ES中删除索引的mapping字段时应该考虑的点
CloudQuery V1.2.0 版本发布
Junit测试出现 empty test suite
面试官: ShardingSphere 学一下吧
How to understand Python iterators and generators?
代码生成器插件与Creator预制体文件解析
image operating system windows cannot be used on this platform
A small goal in 2019 to become a blog expert of CSDN
Introduction to Google software testing
list转换map(根据key来拆分list,相同key的value为一个list)