Knowledge about hard disk partition tables-detailed explanation of Hard Disk MBR

Source: Internet
Author: User

This article is very detailed, the original article: http://hi.baidu.com/waybq/blog/item/3b8db64bef3dc7f583025c66.html

---------------------------------------------------------------------------

Hard Disks are one of the most commonly used storage devices on computers. We all know that computers are amazing because they have the ability to analyze and process data at a high speed. These data are stored in the hard disk as files. However, computers are not as intelligent as humans. When reading the corresponding file, you must give the corresponding rules. This is the concept of partitioning.

Partitioning is essentially a format of the hard disk. When we create a partition, we have already set the physical parameters of the hard disk, specifying the Hard Disk Master Boot Record (Master Boot Record, generally referred to as MBR) and the location where the Boot Record backup is stored. For file systems and other operating systems, the required information for disk management is achieved through the advanced formatting, that is, the format command. After partitioning, the surface, channels, and sectors are divided into the side, track, and sector sectors ). It should be noted that these are just virtual concepts, and they are not really track on the hard disk.

Starting from the surface, the hard disk is generally made up of one or more circular films. As we said, each circular film has two "faces", both of which are used to store data. The number of faces is called 0, 1, and 2 ...... Since each side has a dedicated read/write head, it is also commonly used with 0 heads and 1 heads ...... . According to the disk capacity and specifications, the number of hard disk faces (or heads) is not necessarily the same. Only two sides are missing, and dozens of sides can be reached. A cylinder is a cylinder ).

 

We mentioned the concept of track above. So what exactly is the track? Since the disk is rotated, the data written continuously is arranged in a circle. We call this circumference a track. If the read/write head moves a distance along the radius of the circular film, the data written later will be arranged on another track. Based on Different Hard Disk specifications, the number of tracks can range from several hundred to several thousand; a track can accommodate several KB of data, and the host does not need to read and write that much at a time, therefore, the track is divided into several segments, each of which is called a sector. A single slice generally stores 512 bytes of data. The sector also needs to be numbered. The sectors in the same track are called one sector, two sectors ......

The efficiency of the computer's read and write to the hard disk is the basic unit of the sector. Even if the computer only needs a certain byte stored on the hard disk, it must read all the 512 bytes in the sector where the byte is located into the memory at a time, and then use the required byte. However, as we mentioned above, there is no trace on the hard disk's top, track, or sector division. Although the head can be aligned with the proper radius of a track, but how can we find the desired sector in the first and end links in a circle of sectors? It turns out that each sector is not only composed of 512 bytes, but also has some specific data before and after the data accessed by the computer, the data constitutes the boundary mark of the slice, which contains the slice number and other information. The computer uses these labels to identify the sector. In the previous article, we talked about the general principle of data storage on the hard disk. In order to gain a deeper understanding of the hard disk, we must also have a simple understanding of the data structure of the hard disk. The data on the hard disk is divided into five parts according to their different characteristics and functions: MBR, DBR, fat, Dir, and data.

 

Let's introduce them separately:

1. MBR Zone

MBR (Main Boot Record primary Boot Record) is located in the 0 track 0 cylinder 1 Sector of the entire hard disk. However, in a total of 512 bytes of the primary Boot Sector, MBR only occupies 446 of the bytes, And the other 64 bytes are handed over to the DPT (Disk Partition Table hard disk partition table ), the last two bytes "55, AA" indicate the end of the partition. This constitutes the primary Boot Sector of the hard disk.

The Master Boot Record contains a series of Hard Disk parameters and a boot program. The main function of the hard disk boot program is to check whether the partition table is correct and boot the operating system on the partition with the activation mark after the system hardware completes the self-check, and hand over the control to the Startup Program. Mbris generated by a partition program (such as fdisk.exe). It does not depend on any operating system, and the hard disk boot program can also be changed to realize coexistence of multiple systems.

Next, we will use an example to help you better understand the Master Guide record:

Example:80 01 01 00 0b Fe bf fc 3f 00 00 00 7E 86 BB 00 here we can see that the front "80" is a partition activation sign, indicating that the system can be guided; "01 01 00" indicates the start head of the partition is 01, the start slice is 01, and the START cylinder is 00. "0b" indicates that the system type of the partition is FAT32, other commonly used types include 04 (fat16) and 07 (NTFs). "Fe bf fc" indicates that the number of heads ending with the partition is 254, the end slice number is 63, and the end slice number is 764; "3f 00 00" indicates the relative slice number of the first slice is 63; "7E 86 BB 00" indicates that the total number of sectors is 12289622.

2. DBR Zone

DBR (DOS Boot Record) refers to the Operating System Boot Record area. It is usually located in the hard disk's 0 track 1 cylindrical 1 sector, is the first sector that the operating system can directly access, it includes a boot program and a known as BPB (BiOS parameter block) this partition parameter record table. The main task of the boot program is to determine whether the first two files in the partition and directory are operating system boot files when the MBR gives control of the system (in DOS example, I/O. sys and msdos. sys ). If it exists, read it into the memory and give control to the file. The BPB parameter block records important parameters such as the starting sector, ending sector, file storage format, hard disk media descriptor, root directory size, fat number, and allocation unit size of the partition. DBR is generated by advanced formatting programs (such as format.com.

3. Fat Zone

After DBR, we are familiar with the fat (File Allocation Table) area. Before explaining the concept of a file allocation table, let's talk about the concept of a cluster. When a file occupies disk space, the basic unit is not a byte but a cluster. In general, a floppy disk has one sector per cluster. The number of sectors in each cluster of the hard disk is related to the total capacity of the hard disk, which may be 4, 8, 16, 32, 64 ...... The data of the same file is not necessarily completely stored in a continuous area of the disk, but is often divided into several segments and stored like a chain. This storage method is called the chained storage of files. Because the connection information (FAT) between segments is stored on the hard disk, the operating system can always accurately locate the segments and read them correctly when reading files. To achieve file chain storage, the hard disk must accurately record which clusters have been occupied by files, and specify the cluster number of the next cluster for each occupied cluster. For the last cluster of a file, you must specify that the cluster has no successor cluster. These are all stored in the fat table. There are many table items in the table, and each item records the information of a cluster. Because of the importance of fat for file management, fat has a backup, that is, the same fat is created after the original fat. All items in the initial fat are marked as "not occupied", but if the disk is partially damaged, the formatting program will detect the damaged cluster, if the corresponding item is named "Bad cluster", the cluster will not be used when files are stored in the future. The number of fat items is the same as the total number of clusters on the hard disk. The number of bytes occupied by each item must be consistent with the total number of clusters, because the number of clusters must be stored. There are multiple fat formats, the most common of which are fat16 and FAT32.

 

4. dir Zone

 Dir (directory) is the root directory, followed by the second fat table (that is, the backup fat table), records the starting unit of each file (directory) in the root directory, file attributes. When locating the file location, the operating system can know the specific location and size of the file on the hard disk based on the starting unit in the Dir and the fat table.

 

5. Data Zone

The data zone is the place where data is stored in the real sense. After the Dir zone, it occupies most of the data space on the hard disk.

 

I. Physical Structure of the hard disk:

Hard Disk Storage Data is implemented based on the principle of electric and magnetic conversion. The hard disk is composed of one or more metal or glass material disks with Magnetic Material plating on the surface and the magnetic head mounted on both sides of the disk and the corresponding control circuit (figure 1 ), the disc and head are sealed in a dust-free metal shell.

 

When a hard disk is working, the disk is rotated at a designed high speed. The head configured on the disk surface is radial under the control of the circuit and then stored or read data. When the system writes data to the hard disk, the "Write Data" current in the head generates a magnetic field, which changes the magnetic material status on the disk surface, and remains unchanged after the write current magnetic field disappears, in this way, the data is stored. When the system reads data from the hard disk, the head goes through the specified area of the disk. The magnetic field on the disk surface causes the head to generate induced current or coil impedance changes, after being processed by related circuits, the data is restored. Therefore, as long as the disk surface can be processed more smoothly, the head can be designed more precisely, and the disk rotation speed can be improved as much as possible, the disk can be created with a larger capacity and faster Data Reading and Writing speed. This is because the smoother the disc surface processing, the faster the rotation speed, the closer the head is to the disc surface, and the higher the Read and Write sensitivity and speed; the smaller the head design, the more precise it will make the head occupy less space on the disk, so that the head can create more tracks on a disk to store more data.

 

Ii. Logical Structure of the hard disk:

A hard disk consists of many disks (platters). Each disk has a read/write head. If n disks exist. There are 2n faces, corresponding to 2N head (heads), starting from 0, 1, 2. Each disc is divided into several concentric magnetic channels (logically invisible .) The partition rules for each disk are usually the same. In this way, the radius of each disc is the concentric circle with a fixed value R and then logically forms a cylinders with the motor Spindle as the axis, numbered 0, 1, 2 ...... Each track on each disk is divided into dozens of sectors (sector). The common capacity is 512 bytes, and is numbered 1, 2, 3 according to certain rules ...... Multiple cylinders × heads × sector sectors are formed. These three parameters are the physical parameters of the hard disk. Many of our practices below require a deep understanding of the meaning of these three parameters.

Hard Disk Storage Data is implemented based on the principle of electric and magnetic conversion. The hard disk is composed of one or more metal or glass material disks with Magnetic Material plating on the surface and the magnetic head mounted on both sides of the disk and the corresponding control circuit (figure 1 ), the disc and head are sealed in a dust-free metal shell.

 

Iii. Disk boot principle:

3.1 MBR (Master Boot Record) sectors:

After pressing the power key, the computer starts to execute the BIOS program on the motherboard. After a series of detection and configuration. Start to boot the system in the boot sequence set in BIOS. Assume that the current
In the hard disk. After the BIOS executes its own program, how can the execution right be handed over to the hard disk. After being handed over to the hard disk, where is the stored program executed. In fact, a piece of code called MBR plays an important role.
MBR (Master Boot
Record), that is, the primary Boot Record, also known as the primary Boot Sector. Located in the entire hard disk, the 0-cylinder, 0-head, and 1-sector (which can be regarded as the first sector of the hard disk), BIOS is executing its own program
Then the first command in MBR will be dumped. Control of the system is handed over to MBR for execution. In a total of 446 bytes of Master Boot records, MBR boot procedures accounted for the first words
Section (offset 0h ~ Offset 1bdh), followed by 64 bytes (offset 1beh ~ 1 FDH offset) to DPT (Disk
Partitiontable, Hard Disk Partition Table), the last two bytes "55 AA" (offset 1feh ~ Offset 1ffh) indicates the effective end of the partition.

MBR does not differ with the operating system, meaning that different operating systems may have the same MBR. Even if they are different, MBR will not attach the nature of the operating system. Has the characteristics of public guidance.

Let's analyze an MBR. The following is an MBR of Seagate GB hard disk viewed by winhex.

MBR Sector Code

 


The MBR Boot Code on your hard disk may not be like this. However, different functions are generally the same. For details about disk MBR decompilation, see wowocock.


Let's look at the DPT section. To facilitate disk management, the operating system. Added the concept of disk partitioning. Divide the logic of a disk
. The number of disk partitions is limited to C ~ How do I express the attributes of multiple partitions in 64 bytes of DPT? Microsoft solution through link
. In DPT, the attribute of a partition is described in 16 bytes as the Partition Table item unit. That is to say, the first partition table describes the attributes of a partition, which is generally a basic partition. The
The two Partition Table items describe the remaining space except the basic partitions. In general, they are called extended partitions. The general description of this part is shown in table 1.


DPT code analysis

 
Note: The data exceeding 1 byte in the Table above is displayed as the actual data, that is, the data is displayed as high as the position. Storage is stored at low-level to high-level. The two are different. Please take a closer look. The tables that will appear later are all the same.

You can also see the meanings of these parameters in winhex:


Note:
Each partition table item occupies 16 bytes. Assume that the offset address starts from 0. Partition Table item 3. Partition Table item 4 is the same as Partition Table item 3.

1. 0 h offset indicates whether the active partition is marked. Only h and 80 h can be selected. 80 h is activity, and H is not activity. Other values are invalid for Microsoft.

2. Explain it again (this is very important): the number of bytes greater than 1 is in the storage format before low bytes (little endian
Format. The format before the low byte is a method to save the number. In this way, the byte with the lowest byte first appears in the hexadecimal notation. For example, the value of the relative sector numerical segment
The low byte of 0x3f000000 is expressed as 0x0000003f. The number of low bytes in the front format is 63 in decimal format.

3. When the system is partitioned, each partition is not allowed to span the cylindrical, that is, all are in the cylindrical unit, which is generally referred to as the partition granularity. Sometimes, the input partition size is 7000 MB.
It is 6997 MB, which is the reason.
In the sector and cylindrical parameters offset by 2 h and 6 h, the slice occupies 6 bits and the cylinder occupies 10 bits. Take the 6 h offset as an example, the lower six bits are used as the binary representation of the number of sectors. Its height is two columns
The top two of the ten sides of the surface, the 8-bit position composed of 7 h offset is used as the low eight of the 10-bit cylindrical surface. It can be seen that the partition capacity expressed in this way is limited, and the cylinder and the head are numbered from 0, and the slice
The number starts from 1, so it can only represent a maximum of 1024 cylinders × 63 sectors × 256 heads × 512byte = 8455716864 bytes. That is, the average 8.4 GB (actually
It should be about GB. In fact, the number of magnetic heads is usually only 255 (determined by the addressing registers of the assembly language), even if the three bytes are linearly addressable, it is still insufficient.
In the later operating system, partitions larger than GB were not addressed in the C/h/S mode. Instead, offset CH ~ Offset FH 4 bytes 32-bit linear sector address to represent the partition
The total number of slice occupied. 4 bytes can represent 2 ^ 32 sectors, that is, 2 TB = 2048 GB. Currently, this is an astronomical number for most computers. Not exceeding
On a GB partition, the size of the C/h/s representation is the same as that of the linear sector representation. That is to say, the two representation methods are coordinated. Linear addressing
Accurate. (Errors may occur in some systems ). C/h/s is usually filled with Feh FFH when the partition is over GB.
FFH. That is, the maximum value that C/h/s can represent. Sometimes it will be filled with a cylindrical model of 1024. However, these bytes are irrelevant.

Although the current system uses linear addressing to handle the partition size. However, the principle of not cross-cylinder remains unchanged. The total number of sectors in the current partition plus the number of reserved sectors between the original partition and
It must be an integer multiple of the cylindrical capacity. (The first sector in the reserved sector is the MBR or virtual MBR that stores the partition table. The total number of partition sectors is not counted in the linear representation. If yes
In the first partition, the reserved slice is all the slice before the current partition.

Appendix: Partition Table type mark 4


 

3.2
Extended partition

 
Each logical drive in the extended partition has an extended Boot Record,
EBR), also known as virtual MBR or extended MBR, means the same. The extended boot record includes an extended partition table and the tags of this sector. The extended Boot Record contains only each of the extended partitions
The first information of the first cylinder of the logical drive. The Boot Sector in a logical drive is generally located in the relative Sector 32 or 63. However, if there is no extended partition on the disk, there will be no extended boot records
Recording and logical drive. The first entry in the extended partition table of the first logical drive points to its own Boot Sector. The second option points to the EBR of the next logical drive. If no further logical drive exists
The two items will not be used and will be recorded as a series of zeros. If an attached logical drive exists, the first entry of the extended partition table of the second logical drive points to its own Boot Sector. The second logical drive
The second entry of the extended partition table points to the EBR of the next logical drive. The third and fourth items of the extended partition table will never be used.


A four-partition disk structure shows the general structure of the disk. 5



For extended partitions, 6 shows that the extended Boot Record of the logical drive in the extended partition is a connection table. The figure shows the three logical drives on an extended partition, indicating the differences between the previous logical drive and the last logical drive in the extended partition table.



Except for the last logical drive on the extended partition, the format of the extended partition table described in table 2 is repeated in each logical drive: the first entry identifies the Boot Sector of the logical drive, item 2
The EBR that identifies the next logical drive. The extended partition table of the last logical drive only lists its partition items. The second to fourth items of the last extended partition table are used.


 


The numeric segment of the relative sector in the extended partition table shows the number of bytes that are displaced from the extended partition to the first sector in the logical drive. The number in the total sector number segment refers to the number of sectors that constitute the logical drive. The value of the number segment of the total sector is equal to the number of sectors from the boot sector defined by the extended partition table entry to the end of the logical drive.


Sometimes there is surplus space at the end of the disk. What is the surplus space? As we have mentioned above, the partition is based on the capacity of 1 cylinder as the partition granularity. If the total disk space is not an integer cylinder, it is not enough.
The remaining space of the cylinder is the remaining space, which is not used in the partition, so it is generally unavailable. In principle, the physical mode of a disk determines the total capacity of the disk.
What does it mean that there is not enough space for a cylinder. In my understanding, for the purpose of making greater use of space, disks are generally not managed physically based on the external sector that is larger than the internal sector.
CHS are abstracted to be compatible with the operating system. The actual space capacity may not necessarily be the capacity of an integer cylindrical.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.