当前位置:网站首页>Comparison of disk partition modes (MBR and GPT)
Comparison of disk partition modes (MBR and GPT)
2022-06-26 14:09:00 【lengye7】
stay disk As mentioned in , The disk will undergo a low-level format before leaving the factory , So as to determine the track partition of the disk , After the lower level formatting of the disk , The sectors of the disk are established , Sector is a basic unit of disk for data storage management .
Partition is a way to organize and manage sectors , It divides sectors into different groups , Each group contains certain sectors , Each is called a partition . At present, there are two well-known partition methods :MBR Zoning and GPT Partition .
MBR(Master Boot Record) Partition
MBR Partition is as follows IBM PC DOS From the times , At the same time, he was born with tradition BIOS, It was born in an era when hard disk capacity was very small , therefore MBR The partition is designed according to the current hard disk capacity , That's why , With the increasing capacity of hard disk , Its disadvantages are gradually emerging : Can only be created 4 Primary partitions , adopt 4 Primary partitions can only manage 2TiB Hard disk space for .
1、MBR Partition format

The illustration above : In the picture above partition3 And Extened Use parentheses to indicate the meaning : This piece is either Partition3, Contains the part from the beginning of the yellow area to the next yellow area ; This piece is either Extened Partition, Contains the part from the beginning of the blue area to the next yellow area .
in addition , The yellow in the above figure is Partition Boot Record( Also called partition boot sector, perhaps volume boot record,VBR, perhaps volume partition sector) It varies depending on the file system or operating system , This area is in IBM The operating system of personal computer , That is to say DOS Time . Later, Microsoft's operating systems are compatible with this VBR, Whether it's FAT12,FAT16,FAT32 still NTFS, These file systems are compatible VBR In this area , And keep this area , This area holds some information about the file system . Nowadays, large capacity hard disks are all made of GPT Partition format , These file systems remain VBR This area .
about linux Come on , Whether it's MBR still GPT Partition ,ext4 File systems have a boot block area , This area is similar to VBR An area of , Called the guide block ,group 0 padding.
( About ext4 File System Overview - You know )
(https://blog.csdn.net/lengye7/article/details/122904639 ext4 Backup address )
Master boot record (Master Boot Record, abbreviation :MBR), Also known as the primary boot sector , It is the first sector that must be read when accessing the hard disk after the computer is turned on , Its three-dimensional address on the hard disk is (0 cylinder ,0 head ,1 A sector ) perhaps LBA Addressing 0 Sector No . When discussing the internal structure of the primary boot sector , Sometimes it begins with 446 Byte content refers specifically to “ Master boot record ”(MBR), Followed by 4 individual 16 Bytes of “ Partition table ”(DPT), as well as 2 End of byte flag (55AA). therefore , In the use of “ Master boot record ”(MBR) When this term is used , It needs to be judged according to the specific situation that it refers to the entire primary boot sector , It is also the front of the primary boot sector 446 byte .
The standard MBR The sector structure is as follows :

code area: Code section , The area where the boot code is stored ,BIOS After the power on self-test , Read in MBR, Then execute the code for this area .
Disk signature: The hard disk flag is used to distinguish the hard disk , When there are multiple hard disks , convenient BIOS By matching this field, you can determine whether you are loading correctly MBR.
Table of primary patitions: Partition table ,16 Byte a table entry ,BIOS Or the operating system finds the partition entry from here . In total 4 Zones , It can be 4 Primary partitions , perhaps 3 Primary partitions +1 Extended partitions .

Partition table item format :
Patition Flag:1 byte ,0x80:bootable, Activity zones , Start partition ,0x00:not bootable, Inactive zones , Non boot partition . This sign is used to guide Boot Loader Used to load specific partitions Partition Boot Sector, When the flag bit of a partition 0x80 When ,Boot Loader The partition will be loaded later Partition Boot Sector.4 Of the divisions , It's better to have only one 0x80 sign , Boot partition , Or the boot partition .
Start CHS:3 byte , Used in the early days to mark the position of the starting sector of the partition .
Partition Type:1 byte , Partition type , The specific partition needs to be viewed separately .
End CHS:3 byte , Used earlier to mark the position of the end sector .
Start LBA:4 byte , The first... At the beginning of the partition LBA Fan area code , How to mark the starting position of the sector now used .
Size:4 byte , The number of sectors occupied by the partition .
CHS Mode is the marking mode used by the early hard disk , It can not support more than 7.875GiB.
In order to support a larger hard disk , So a transitional approach is adopted , Start using LBA and Size Method to mark the beginning and end of the partition .
But even with LBA And Size The way ,MBR The hard disk supported by the mode cannot exceed 2TiB.
Let's explain why :
1、 because size by 4 byte , A partition can have at most 2 Of 32 Power sector , Suppose a sector is 512 byte , A partition cannot exceed 2TiB.
Then a partition can at most 2TiB,4 A partition can support 8TiB?
2、Start LBA The limitation of , because Start LBA use 4 byte , The addressable sector space is 2 Of 32 Power , Suppose the first partition is 2TiB, So the second partition Start LBA The address must go beyond 4 Representation range of bytes , So the second partition Start LBA You can't say , Naturally, there is no second partition . Empathy , There will be no third and fourth partitions .
therefore ,MBR Cannot support more than 2TiB The hard disk of .
But if you want to use BIOS Boot the operating system and use 2TiB What should I do with the above hard disks ?
Optimal scheme :
Suppose the operating system supports GPT Partition plan , Then you can use two hard disks , The hard disk where the operating system is located adopts MBR Partition , Then another block has a capacity of more than 2TiB The hard disk of is GPT The way .
Other options :
Of course , There are also whole Sao operations , hold MBR Zoning and GPT Partitions are consolidated in a block with more than 2TiB On your hard drive , This had better not be done , In case any software does not support GPT The partition , When operating the disk, put GPT If the partition is damaged, it will be fun .
MBR Partitions can only support 4 Primary partitions , What if you want more partitions ?
MBR You can also create an extended partition , Many logical partitions can be created in the extended partition , Compared with the primary partition , A logical partition cannot be used as a boot partition, a boot partition, or an active partition .
Extended partition diagram :


Boot record of extended partition (Extended Boot Record,EBR)
Each logical partition is preceded by EBR, Used to describe the starting position and size of the current logical permission , Mark the current partition as a logical partition , It also gives the starting position of the next logical partition .

EBR The format and MBR No big difference , The difference lies in the purpose of each field .
about EBR Come on , Generally do not use the front 446 byte , Use only the first and second entries of the partitioned table at the same time , And the sign on the back 0xAA,0x55.
The first table item is used to record the information of the current logical partition ( Partition start position , Logical partition size ), The second table entry is used to record the information of the next logical partition ( Partition start position , Logical partition size ).

Boot indicator:1 byte , It's always 0x00.
Partition type: There are specific fields ,0x05(CHS Addressing mode ),0x0F(LBA Addressing mode ), But different operating systems may be different .
Start LBA: This is related to MBR The partition table entries of are different , The value here is relative to the sector number at the beginning of the logical partition .
Other values are not explained with MBR Agreement .
A typical diagram of a logical partition :

In the above figure, it is specially separated before each logical partition 19 Sectors , The purpose is to better explain , The value of the starting sector number of the logical partition is relative to the partition EBR The area code of the starting fan , For example, the first EBR in , The value given is 20, So the starting position of the first logical partition is relative to 5000 Of the 20 Starting from sectors , The logical sector code is 5020.
2、MBR Partition of the hard disk BIOS Simple boot process


GPT Partition
because MBR Partition cannot support 2TiB The above hard disk , therefore GPT It was developed , And in order to UEFI Part of the standard , The minimum number of partitions it can support is 128 individual ( At least so much , actually windows Just support 128 individual , How many are supported , Depends on the implementation .), The maximum supported hard disk capacity can reach 8388608 PiB.
therefore ,GPT It can be considered to support infinite partitions , Unlimited capacity .
GPT:GUID partition table, Globally unique identifier partition table .
GUID:global unique identifier, Globally unique identifier .
1、GPT Partition format
# The overall format of the partition

The above figure is just a schematic diagram , To illustrate GPT The basic format of , there 128 A partition is a description .
LBA0: It's still MBR, But in GPT in ,MBR( Master boot record ) There is only one partition in , That is, the identification type is EE Partition , That is, protective partition , This is to tell some underlying operating software , If the software does not recognize GPT, Don't operate it , To protect GPT The partition is not destroyed .
LBA1: Store here GPT Main partition header of (Primary GPT Header).
LBA2-LBA33: altogether 32 Sectors , We call it “ Primary partition node ”.
LBA34-LBA-34: natural GPT Zoning area , file system ( Such as FAT,NTFS,EXT4 etc. ) It is built in this .
LBA-1: Here is GPT Backup of partition header .
LBA-2-LBA-33: This is the backup primary partition node .
#LBA1 Of GPT Main partition header format :

Above picture , We can see :
Hard disk GUID: This is used to distinguish hard disk devices , Unique identification .
Number of partitioned table entries : This is 4 byte ,32bit, This explanation GPT The number of partitions can be as high as 2 Of 32 Power .
The size of the partitioned table entry : It is commonly 128 Bytes .
CRC32 check : Used for data verification of the entire partition header , If something goes wrong , Read in the partition header of the backup to restore , If the partition header of the backup is also wrong , False report .
The other fields are as shown in the figure .
# Format of partitioned table entries

Partition type GUID: This is a very important field , Use this field to distinguish different partition types , for example EFI The partition has a specific GUID.
Partition GUID: This should be related to the partition type GUID Distinguish , This is the unique identifier for the partition , Different partitions have the same type , Partition GUID It's not the same .
Section name : This is the MBR The important difference between ,MBR No partition name ,72 Bytes , Can have 72 individual ASCII character .
Property tags : This is an interesting field , You can directly specify the partition properties here , for example , read-only , Hiding and so on . commonly EFI Partition (ESP Partition ), Will set its attribute as hidden .
For more information, please refer to EFI Standard documents .
2、UEFI stay GPT Boot process under partition
Tradition BIOS I won't support it GPT Partition start , If you use GPT Partition , Can only be used UEFI start-up .

UEFI After starting , Into the DXE Stage , Start loading device drivers , then UEFI There will be a list of devices .
For the disks ,UEFI The corresponding driver will be loaded to resolve the partition table (GPT and MBR, you 're right UEFI You can know MBR Partition ). then UEFI There will be a list of all partitions . then UEFI Will use the built-in file system driver , Resolve each partition . then UEFI You will know the files in the partition .
Into the BDS Stage , Then go to the corresponding device according to the order of startup items , The startup item is BDS Stage from NVRAM Read in , It can be set through tools NVRAM The content in , For example, the order of startup items can be changed .
In the startup phase of the operating system , According to the set startup item order , Go to the device ( Limited to GPT equipment , If you start tradition MBR equipment , You need to turn on CSM Support ) The leading item of , Boot and enter the operating system .
There are two types of startup items :
- File startup item : It records about a file in a path of a partition of a disk . For file startup items , The firmware will load this directly EFI file , And implement . Be similar to DOS Next you hit win.com It's done Windows 3.2/95/98 Start of . Fail if the file does not exist .
- Equipment startup items : The approximate record is “ Some U disc ”、“ A hard disk ”.( Only... Is discussed here U disc 、 Hard disk ) For device startup items ,UEFI The standard specifies the default path
\EFI\Boot\bootX64.efi.UEFI The file on the disk will be loaded . Fail if the file does not exist .
As UEFI In the standard , An appointed file system ,FAT32.efi Every motherboard comes with . all UEFI We all know the motherboard FAT32 Partition .
about windows Come on :
General situation : a main board UEFI initialization , Then I found the default startup item Windows Boot Manager(windows The default startup item will be changed directly , Change it to EFI\microsoft The startup file under Lu Jin ). Write the inside bootmgfw.efi The location of . Firmware loading bootmgfw.efi.bootmgfw.efi according to BCD Start item ( Be careful : This refers to the operating system startup item , No UEFI Device or file startup item for , Pay attention to differences .) Storage , Find the package Windows The specific partition of the disk , Load the WinLoad.efi. from WinLoad.efi Finish the rest of the startup work .

The dotted line , It's the same as the one above , intend ,Windows Startup disk and EFI Startup disk , It can be a hard disk , It can also be a different hard disk . So for UEFI Come on , The startup disk is bootmgfw.efi On the same plate .
On the same hard disk , ESP Can I have two partitions ?
ESP Partitions can of course have two or more , however UEFI Start-up phase , Only one boot entry will be loaded , in other words , Even if there are more than one ESP, There is only one ESP By UEFI Loaded .
If there are multiple systems that need to be booted , It is better to allocate a larger one on a hard disk ESP, Then write the boot files of each operating system to this ESP partition .
And then when it starts :
1、 from UEFI In the startup entry of , Manually select the system startup items to be loaded . This is method one .
2、 Select a bootstrap that can switch from itself to another system boot item as UEFI Default startup item for . for example ,Grub Is such a boot program . This is method two , Method two is obviously better .
It has been tested in the virtual machine .
边栏推荐
- Create your own cross domain proxy server
- 虫子 内存管理 下 内存注意点
- Codeforces Global Round 21A~D
- Detailed introduction to shell script (4)
- CF676C Vasya and String
- Wechat applet -picker component is repackaged and the disabled attribute is added -- above
- Is it safe to open a securities account? Is there any danger
- Linear basis count (k large XOR sum)
- Codeforces Round #765 (Div. 2) D. Binary Spiders
- Luogu p4145 seven minutes of God created questions 2 / Huashen travels around the world
猜你喜欢

Free machine learning dataset website (6300+ dataset)

Jenkins build prompt error: eacces: permission denied

Wechat applet -picker component is repackaged and the disabled attribute is added -- above

hands-on-data-analysis 第三单元 模型搭建和评估

2021-10-09

windows版MySQL软件的安装与卸载

9項規定6個嚴禁!教育部、應急管理部聯合印發《校外培訓機構消防安全管理九項規定》
![[MySQL from introduction to mastery] [advanced part] (II) representation of MySQL directory structure and tables in the file system](/img/03/a1885e4740bbfdbdee2446e3dd81d0.png)
[MySQL from introduction to mastery] [advanced part] (II) representation of MySQL directory structure and tables in the file system

Gartner 2022年顶级战略技术趋势报告

A must for programmers, an artifact utools that can improve your work efficiency n times
随机推荐
Traverse the specified directory to obtain the file name with the specified suffix (such as txt and INI) under the current directory
Wechat applet -picker component is repackaged and the disabled attribute is added -- above
[jsoi2015] string tree
Cloudcompare - Poisson reconstruction
C language ---getchar() and putchar()
Nexys A7开发板资源使用技巧
[node.js] MySQL module
创建一个自己的跨域代理服务器
[scoi2016] lucky numbers
First k large XOR value problem
爱可可AI前沿推介(6.26)
Go language - pipeline channel
9項規定6個嚴禁!教育部、應急管理部聯合印發《校外培訓機構消防安全管理九項規定》
Zero basics of C language lesson 7: break & continue
"Scoi2016" delicious problem solution
Generation and rendering of VTK cylinder
HW蓝队溯源流程详细整理
Pointer
Free machine learning dataset website (6300+ dataset)
Zero basics of C language lesson 8: Functions