"Go" Drive partition knowledge Introduction (MBR)

Source: Internet
Author: User

transferred from: http://www.blogjava.net/galaxyp/archive/2010/04/25/319344.htmlhard drives are one of the most commonly used memory on your computer today. As we all know, computers are magical because they have the ability to process data at high speed. This data is stored on the hard drive as a file. However, computers are not as smart as people. When reading the corresponding file, you must give the corresponding rules. This is the concept of partitioning.

A partition is essentially a format for a hard disk. When we create the partition, we have set the physical parameters of the hard disk, specified the hard disk master boot record (that is, the master boot record, generally referred to as MBR) and the location of the boot record backup. The information required for the file system and other operating systems to manage the hard drive is implemented by a later advanced format, the Format command. Polygon, track, and sector hard disk partitions are divided into polygons (Side), tracks, and sectors (Sector). It is important to note that these are just virtual concepts, not really on the hard drive to draw tracks.

First from the face, the hard disk is generally composed of a piece or a few pieces of circular film superimposed. We say that each circular film has two "faces", and these two faces are used to store data. According to the number of faces, which is called 0-side, 1-face, 2-side ... Since each face is proprietary to a read-write head, it is also commonly used for 0 head, 1 head ... Call it. According to the hard disk capacity and specifications, hard disk surface number (or the number of head) is not necessarily the same, less than 2 side, more than dozens of sides. Tracks with the same track number on each face are combined, called a cylinder (Cylinder).

Above we mentioned the concept of the track. So what exactly is a track? Since the disk is rotated, the data that is written continuously is arranged on a circumference. We call this circle a track. If the read-write head moves a distance along the radius of the circular film, the data written later is arranged on another track. Depending on the specifications of the hard disk, the number of tracks can range from hundreds of to thousands of, a track can hold several kilobytes of data, and the host read and write often do not need to read and write so much, so, the track is divided into several paragraphs, each section is called a sector. A sector typically holds 512 bytes of data. Sectors also need to be numbered, sectors in the same track, called 1 sectors, 2 sectors, respectively.

The computer reads and writes to the hard disk, is in the efficiency consideration, is takes the sector as the basic unit. Even if the computer only needs a byte stored on the hard disk, it must read all 512 bytes in the sector of the byte in memory at once, and then use the desired byte. However, in the above, we also mentioned that the hard disk above, track, Sector division surface is not visible any traces, although the head can be based on the radius of a track to align the track, but how to find in the end-to-end sector in a circle of the desired sector? Originally, each sector is not only composed of 512 bytes, the data accessed by the computer before and after the two ends, there are some other specific data, which constitutes a sector of the boundary mark, the flag contains sector numbers and other information. The computer relies on these flags to identify sectors. Data structure of hard disk in the previous section, we talked about the general principle of the storage in the hard disk. In order to gain a deeper understanding of the hard drive, we must also have a simple understanding of the data structure of the hard disk. The data on the hard disk can be broadly divided into 5 parts according to its different characteristics and functions: MBR, DBR, fat, dir and data.

Let's take a look at each:

1. MBR area

The MBR (main boot record master boot recording area) is located on the 0 track 0 cylinder 1 sector of the entire hard drive. However, in a total of 512 bytes of the main boot sector, the MBR occupies only 446 bytes, the other 64 bytes to the DPT (disk Partition table hard disk partition table), and the last two bytes "55,aa" is the end of the partition flag. This whole constitutes the main boot sector of the hard disk.

The Master boot record contains a series of parameters and a boot program for the hard disk. The primary role of the hard disk bootstrapper is to check that the partition table is correct and boot the operating system on the partition that has the activation flag after the system hardware completes the self-test, and give control to the startup program. The MBR is made up of partitioner (such as Fdisk. EXE), it does not rely on any operating system, and the hard drive boot program can also be changed to achieve multi-system coexistence.

Below, let's take a look at the master boot record in an example to make it more intuitive:

Example: 0B FE BF FC 3F (xx), 7E, BB xx Here we can see that the first "80" is a partition of the activation flag, indicating that the system is bootable; "01 01 00" indicates that the partition begins with the first magnetic number 01, the beginning of the fan The area code is 01, the beginning of the cylinder number is XX, "0B" indicates that the partition system type is FAT32, the other more commonly used is FAT16, (NTFS), "FE BF FC" indicates that the partition end of the magnetic number 254, the partition end of the sector area code 63, the partition end of the cylinder number 764 ; "3F 00 00 00" indicates that the relative sector area of the first sector is a quarter, and "7E 00" means that the total number of sectors is 12289622.

2. DBR Zone

DBR (Dos boot record) is the meaning of the operating system boot record area. It is typically located on the hard disk's 0 track 1 cylinder 1 sector, which is the first sector that the operating system can access directly, including a bootstrap and a sub-parameter record table called BPB (Bios Parameter Block). The main task of the bootloader is that when the MBR takes control of the system to it, it is judged that the first two files of this partition and the directory are the boot files of the operating system (in DOS, for example, IO). SYS and MSDOS. SYS). If it is determined to exist, read it into memory and give control to the file. The BPB parameter block records important parameters such as the start sector, end sector, file storage format, hard disk media descriptor, root directory size, fat count, allocation unit size, and so on for the sub-region. DBR is made up of the advanced formatter (that is, format. COM and other programs).

3. Fat Area

Behind the DBR is the area of fat (file Allocation table) that we are more familiar with. Before explaining the concept of a file allocation table, let's talk about the concept of cluster (Cluster). When a file occupies disk space, the base unit is not a byte but a cluster. In general, the floppy disk per cluster is 1 sectors, the number of disk per cluster sector and the total size of the hard disk capacity, it may be 4, 8, 16, 32, 64 ... The data of the same file does not necessarily reside in a contiguous area of the disk, but is often divided into segments that are stored like a chain. This type of storage is called chained storage of files. Since the connection information (i.e. fat) between the segment and segment is kept on the hard disk, the operating system is always able to accurately find the location of each segment and read it correctly when reading the file. To achieve chained storage of files, the hard disk must accurately record which clusters have been consumed by the file, and must indicate the cluster number of the next cluster that stores the successor for each occupied cluster. For the last cluster of a file, indicate that there are no subsequent clusters in this cluster. These are saved by the Fat table, which has many table entries, each of which records a cluster of information. Because fat is important for file management, FAT has a backup that builds the same fat after the original fat. All items in the initial fat are marked as "unoccupied", but if the disk is partially damaged, the formatter detects the damaged cluster, and the corresponding entry is "Bad cluster", which is no longer used when the file is saved. Fat has the same number of items as the total number of clusters on the hard disk, and each item occupies a number of bytes to match the total number of clusters, because the cluster number needs to be stored. There are several formats for fat, the most common being FAT16 and FAT32.

4. Dir Zone

DIR (directory) is the root area, followed by the second Fat table (the Fat table that is backed up), records the starting unit of each file (directory) in the root directory, the properties of the file, and so on. When locating the file location, the operating system can know the exact location and size of the file on the hard disk based on the starting unit in Dir, combined with the fat table.

5. Data area

The data area is where the data is stored in a real sense, after the Dir area, occupying most of the data space on the hard disk.

First, the physical structure of the hard disk:

The hard disk storage data is realized according to the principle of electric and magnetic conversion. A hard disk consists of one or more metal or glass plates with magnetic material on the surface, and a magnetic head mounted on both sides of the platter and a corresponding control circuit (Fig 1) in which the platters and heads are sealed in a dust-free metal shell.

When the hard disk is working, the disc rotates at a high speed at design speed, and the head on the disc surface is moved radially to the specified position under the control of the circuit and the data is stored or read out. When the system writes data to the hard disk, the "write data" current in the head creates a magnetic field that changes the magnetic state of the disc surface and remains after the write-current field disappears, so that the data is stored; When the system reads the data from the hard disk, the head passes through the specified area of the disc. magnetic field on the surface of the disc causes the magnetic head to generate a current or coil impedance change, after the relevant circuit processing to restore data. So as long as the surface of the disc can be processed smoother, the head is designed more precisely and as much as possible to increase the speed of the disc rotation, you can create a larger capacity, read and write data faster disk. This is because the more flat surface treatment, the faster the speed can make the head away from the surface of the disc closer, improve the reading, writing sensitivity and speed; the smaller the head design, the smaller the disk space on the disc, and the more tracks the head takes on a platter to store more data.

Second, the logical structure of the hard disk:

The hard disk consists of a number of platters (platter), each with a read-write head on each side of the platter. If there are n platters. There are 2N faces, corresponding to 2N heads (Heads), numbering starting at 0, 1, and 2. Each platter is divided into a number of concentric circular tracks (logically, not visible.) The rules for dividing each platter are usually the same. In this way, the radius of each disc is a fixed value of r concentric circles and logically formed a cylinder with the motor spindle axis (cylinders), from the outside to the inside number 0, 1, 2 ... Each track on each platter is divided into dozens of sectors (Sector), the usual capacity is 512byte, and according to a certain number of rules numbered 1, 2, 3 ... Form a cylindersxheadsxsector sector. 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.
The hard disk storage data is realized according to the principle of electric and magnetic conversion. A hard disk consists of one or more metal or glass plates with magnetic material on the surface, and a magnetic head mounted on both sides of the platter and a corresponding control circuit (Fig 1) in which the platters and heads are sealed in a dust-free metal shell.

Three, disk boot principle:

3.1 MBR (master boot Record) sector:

The computer starts to perform the motherboard BIOS program after the Power key is pressed. After a series of tests and configurations are completed. Start booting the system in the system boot order set in the BIOS. It is assumed that it is a hard disk. How does the BIOS give execution to the hard drive after executing its own program? After handing over to the hard drive and then executing the program where it was stored. In fact, a piece of code called MBR plays an important role. MBR (master boot Record), which is the master boot record, sometimes referred to as the primary boot sector. The 0-cylinder 0 Head 1 sector (which can be seen as the first sector of the hard disk) on the entire hard drive, and the BIOS will jump to the first instruction in the MBR after executing its own inherent program. Take control of the system to the MBR. In a total of 512byte master boot records, the MBR's bootloader accounted for the first 446 bytes (offset 0h~ offset 1BDH), followed by 64 bytes (offset 1beh~ offset 1FDH) for DPT (disk partitiontable, hard disk partition table), The last two bytes "1feh~" (offset, offset, 1FFH) is the partition valid end flag.

MBR does not vary with the operating system, meaning that different operating systems may have the same MBR, even if different, the MBR will not be entrained by the nature of the operating system. Features that have a public boot.

Let's analyze a piece of MBR. The following is an MBR of a Seagate 120GB hard drive viewed with Winhex.

MBR Sector code

The MBR boot code for your hard drive may not be the case. However, the functions performed are generally the same, even if they are different. Here to find wowocock about the disk MBR anti-compilation, has been added detailed comments, interested can be studied carefully.

Let's look at the DPT section. Operating system in order to facilitate user management of the disk. Added the concept of disk partitioning. A piece of disk logic is divided into pieces. How much of the number of disk partitions is limited by the number of c~z letters in the DPT, how do you represent the properties of multiple partitions in a total of 64 bytes? Microsoft has addressed this issue through a linked approach. In the DPT total of 64 bytes, the properties of a partition are described in 16 bytes for the partitioned table item units. That is, the first partition table entry describes the properties of a partition, typically a basic partition. The Second partition table entry describes the rest of the space except the base partition, which is generally what we call an extended partition. The general description of this section is shown in table 1.

DPT Code Analysis

Note: More than 1 bytes of data in the table above are displayed in actual data, which is displayed in the high-to-status way. Storage is stored at low to high levels. Please take a closer look at the difference between the two performances. The table that appears later, the diagram is the same.

You can also see the meaning of these parameters in Winhex:

Description: each partition table entry occupies 16 bytes, assuming that the offset address starts at 0. 3 Partition Table Entry 3. Partition table entry 4 with partition table entry 3.

1, 0H offset is the active partition is the flag, only select 00H and 80H. 80H is active and 00H is inactive. The remaining values are illegal for Microsoft.

2. Re-explain (this is important): a number greater than 1 bytes is saved in the previous storage format format (little endian format) or counter-byte order in low bytes. The low byte in the previous format is a method of saving the number, so that the lowest bit byte first appears in the hexadecimal number symbol. For example, the value of a relative sector number field 0x3f000000 a low byte that is previously represented as 0x0000003f. The decimal number of this low-byte number in the previous format is 63.

3, the system in the partition, the partitions are not allowed to cross the cylinder, that is, the cylinder is the unit, which is usually said the granularity of the partition. Sometimes we partition is the size of the input partition is 7000M, the point is 6997M, that is the reason. Sectors and cylinder parameters with offset 2H and offset 6H, sector 6 bits (bit), cylinder 10 bits (bit), offset 6H as an example, and its low 6 bits are used as a binary representation of the number of sectors. Its high two bits are made of 10 bits in the height of two bits, the offset 7H consists of 8 bits made of 10 bits of the lower 8 bits in the number of bars. Thus, in fact, the partition capacity represented in this way is limited, the cylinder and the head are numbered starting from 0, the sector is numbered from 1, so it can only represent 1024 cylinders x63 sector x256 heads x512byte=8455716864byte. That is, the usual 8.4GB (which should actually be around 7.8GB) is limited. In fact, the number of heads is usually only 255 (as determined by the address register of assembly language), even if the 3 bytes are linearly addressed, still powerless. In later operating systems, more than 8.4GB of the partition has not been addressed by C/H/S way. Instead, the total number of sectors occupied by the partition is represented by the offset ch~ offset by a total of 4 bytes of 32-bit linear sector addresses. It is known that by 4 bytes can represent 2^32 sector, that is, 2TB=2048GB, now for most computers, this is an astronomical. On partitions that do not exceed 8.4GB, the representation of the c/h/s is consistent with the partition size represented by the representation of the linear sector. In other words, the two representations are coordinated. Even if it is uncoordinated, linear addressing is the standard. (Errors may be prompted on some systems). Partitions over 8.4GB end c/h/s are generally populated with Feh FFH FFH. That is, the maximum value that c/h/s can represent. Sometimes it is filled with a bar facing 1024. But what these few bytes are doesn't really matter.

Although the system now uses linear addressing to handle the size of the partition. But the principle of non-cross-cylinder remains unchanged. The total number of sectors in this partition plus the amount of reserved sectors between the previous partition must still be an integer multiple of the cylinder capacity. (The first sector in a reserved sector is the sector of the MBR or virtual MBR that holds the partitioned table, and the total number of sectors in the partition is not counted as a reserved sector in linear notation.) If it is the first partition, the reserved sector is all sectors before this partition.

Attached: Partition table type flag 4

3.2 Extended partitions

Each logical drive in the extended partition has an extended boot record similar to MBR (Extended boot record, EBR), which is also called virtual MBR or extended MBR, meaning the same. The extended boot record includes an extended partition table and a label for that sector. The extended boot Record records information that contains only the first side of the first cylinder for each logical drive in the extended partition. The boot sector in a logical drive is typically in relative sector 32 or 63. However, if there is no extended partition on the disk, there will be no extended boot record and logical drive. The first entry in the Extended partition table of the first logical drive points to its own boot sector. The second item points to the EBR of the next logical drive. If no further logical drives exist, the second item is not used and is recorded as a series of zeros. If there is an additional logical drive, the first item in the Extended partition table of the second logical drive points to its own boot sector. The second entry of the second logical drive's 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 disk map of 4 partitions allows you to see the approximate organization of the disk. 5

For the extended partition, 6, the extended boot record for the logical drive in the extended partition is a connection table. The figure shows the three logical drives on an extended partition, explaining the differences between the previous logical drive and the last logical drive in the extended partition table.

In addition to the last logical drive on the extended partition, the format of the extended partition table described in table 2 is duplicated in each logical drive: The first item identifies the boot sector of the logical drive itself, and the second identifies the EBR of the next logical drive. The last logical drive's extended partition table lists only its own partition entries. The second item of the last Extended partition table is used in the fourth item.

The relative Sector number field in an Extended partition table entry displays the number of bytes from the extended partition to the first sector in the logical drive. The number in the total Sector number field refers to the number of sectors that comprise the logical drive. The value of the total Sector number field equals 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 space left at the end of the disk, what is the remaining space? As we said before, the partition is based on a 1-cylinder capacity of the partition granularity, then if the total disk space is not the entire number of cylinders, the remaining space is not enough for a cylinder is the remaining space, this part of the space does not participate in the partition, it is generally not available. According to reason, the physical mode of disk determines the total capacity of the disk should be the capacity of the whole number of cylinders, why there is not enough space for a cylinder. In my understanding, the current disk in order to make greater use of space, generally in the physical not according to the peripheral sector is larger than the circle of the sector of the management mode, just to be compatible with the operating system and abstracted out chs. It is possible that the space capacity is not necessarily exactly the capacity of the entire number of cylinders.

"Go" Drive partition knowledge Introduction (MBR)

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.