Self-programming to achieve multiple boot

Source: Internet
Author: User
Tags root directory

If you are a computer user who believes you must have installed the operating system, when you use a long operating system, you may install a new operating system, but you often want to keep the current operating system. For example, when you have a Windows98, you can install WINDOWS2K or Windows XP on it, because Windows Ntloader can recognize an earlier operating system, so you can keep your previous operating system. But if you already have a windows2k or Windows XP you have to install a WINDOWS98 on your hard drive. Even some nostalgic people want to have a DOS6.22 on it, what should we do now? You will often use third-party software, such as V Communications,.inc's System Commander series, PowerQuest Corporration bootmagic and so on are good choices. These software set the hard disk partition to two or more than two primary partitions, (that is, we call the Double "C" disk, or more "C" disk), the installation of different operating systems to different primary partitions, by activating different partitions to achieve multiple boot, the advantage is security and stability, once the operating system is paralyzed, The point does not affect other operating systems, personally considered worthy of recommendation.

This article is not a multi-operating system implementation experience, so the use of bootmagic and other third-party software I will not waste space to introduce, I want to give you an analysis of this kind of software implementation principle.

To understand how it works, you must first understand the overall structure of your hard disk, if you don't understand its structure, refer to table 1.

Table 1:

Name notes

1 primary boot sector (master boot sector) occupies one sector

2 The boot sector (boot sector) of the first primary partition occupies one sector

3 The Fat area footprint of the first primary partition is determined by disk size and fat type

4 The root of the first partition stores the partition root directory

5 The first partitioned data area is used to store various data

6..

7 Extended partition Table occupies one sector

8 The boot sector of the first extended partition occupies one sector

9 The Fat area footprint of the first extended partition is determined by the disk size and fat type

10 The root of the first extended partition holds the partition root directory

11 The data area of the first extended partition is used to store various data

12..

Note: This table is described in a spatial order, with a hard drive allowing up to four primary partitions and multiple extended partitions

We also need to know the structure of the primary boot sector (master boot sector), which is the first sector of the hard disk, by the master bootstrapper (Masterboot record for short, MBR), hard disk partition table (disk Partition table abbreviation DPT ) and the end of the identification three components. Its structure is shown in table 2.

Table 2:

Location name comments in the primary boot sector

1 offset 00H~1BDH The primary bootstrapper takes up 446 bytes, but it may not actually be full

2 offset 1BEH~1FDH hard disk Primary partition table is 64 bytes, each partition entry occupies 16 bytes, can have up to 4 partition items: 1BEH~1CDH partition item 11CEH~1DDH partition item 21DBH~1EDH partition item 31EFH~1FDH partition Item 4

3 offset 1FEH~1FFH End identification for 2 bytes, used to determine the validity of partitioned tables

Master Bootstrapper I'm not going to analyze this. Note that there are some error messages in the main bootstrapper, and some boot viruses will often overwrite this information to embed themselves in the main bootstrapper, and change the number of bytes from the primary bootstrapper to a jump instruction, by observing the changes in the master boot program, Can often let us see whether our computer has a boot-type virus, once we find the exception, we can use the FDISK/MBR command to overwrite the original MBR. The two bytes of the end identity are always 55H AAH, which is used only to determine if the sector is a valid primary boot sector, and if the primary bootstrapper finds no such end identity, the operating system is considered lost and the "Missing operating system" is displayed.

The last thing we want to know is the hard disk partition table, multi-boot software is generally used to modify a specific byte in the partition table to achieve multiple boot, in the main boot area of the hard disk, from the offset 1beh~1fdh 64 bytes of the disk partition table, which contains up to 4 partition entries, Each partition entry is made up of 16 bytes, so let's look at the detailed meaning of each partition item, assuming that one of our partitions occupies 16 bytes labeled 00H~0FH, and its structure is table 3:

Table 3:

Offset meaning

00H boot identity byte with a value of only 00H or 80H, which indicates that the partition is not bootable when it is 00H, and that the partition is available for booting when 80H.

01H partition starting magnetic number one

02H its high 2-bit height for the partition starting cylinder number, the bottom 6 bit is the partition start sector area code

03H Partition starting cylinder number low

The 04H partition system flag, when the value is 00H, indicates that the partition is an unrecognized system, that the partition is a FAT16 partition for 04H, or that the partition is an extended partition for 05H or 0FH, and that the partition is a FAT32 partition when 0B, and that the partition is a Linux partition when 83H. is 07 o'clock the partition is an NTFS partition

05H partition End Magnetic Number One

06H its high 2-bit for the partition end cylinder number high, the bottom 6-bit is the partition end sector area code

07H Partition End Cylinder number low

08H~0BH the sector address of a partition under a linear addressing mode.

0CH~0FH the partition size in sectors (total sectors)

Let's take a look at how software like Bootmagic is implemented in multiple systems, and in table 3 we see that a byte at offset 00H represents the partition as a boot zone when its value is 80H, and that the partition is not a boot area when its value is 00H, In fact, the principle of multiple-boot implementation is to select the partition to boot by changing the value of that place.

Assuming that you have understood the above principles, we are fully able to make our own multiple-boot program, I write a complete implementation program, I will analyze how this program should be written. Suppose you have a hard drive, you have a Windows XP installed on it, but you want to install a windows98 now, so you use PartitionMagic to set your first extended partition, which is your D area, as the primary partition, and then activate, Reboot and install the disc Boot system with Windows98 and install the Windows98. To this, you do not rush to install bootmagic, let us try to do their own bootmagic how to do.

Obviously, to implement this feature, you need at least two modules, module one: is written into the main boot sector, used to replace the original MBR area, it must be able to get the execution power before the system boot, the main partition of the boot selection, the executive power to the selected operating system, so as to achieve multiple system boot; module two: Realize three functions, You first back up one of the original boot sectors to another sector (in my case, back it up to 0 0 6), and then write the module as the master boot sector. In addition, module II also implement a multiple-boot program Uninstall

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.