Sunday, August 21, 2005

Basics of Boot Process

Hard Disk and Partitions:
Partitioning is a process of dividing the Hard Disk (HD) into several chunks, and uses anyone of the partition to install Operating System (OS), or use two or more partitions to install multiple OSes. You can have one partition and use up the entire HD space to install a single OS; but this will become data management nightmare for large HD users. The advantage of partitioning lie here! Because of the structure of the Master Boot Record (MBR), you can have only four partitions, and are called Primary Partitions. Again, if we have even larger HD, to induce more partitions, Extended Partition is introduced. Extended Partition is not a usable partition by itself. But it’s like a container and is used to hold Logical Drives! , i.e., the Extended Partition can be subdivided into multiple logical partitions.
In order to boot into a partition, it must be designated as Active or Bootable Partition. Active Partition is one which is flagged as bootable or which contains OS, this is generally a Primary Partition.


Boot Records (Master, Partition, Extended, Logical-Extended):
Master Boot Record (MBR): MBR is a small, 512 bytes partition which is at the first physical-sector of the HD. MBR contains a small program known as bootstrap program, which is responsible for booting into any OS. Also MBR contains a table known as Partition Table which lists the available Primary Partitions in the hard disk (can hold only 4 entries).What if we have more than four partitions? This is solved by Extended Partition principle. Partition Table assumes entire Extended Partition as one Primary Partition and lists it in the table.
So a Partition Table can have two possible entries,
- Up to 4 Primary Partitions
- Up to 3 Primary Partitions & 1 Extended Partition (Total not exceeding 4).
Partition Boot Record (PBR): This is the logical first sector, i.e., sector at the start of a Primary Partition. This is a 512 byte area, which contains some programs to initialize or run OS files. All Primary Partitions have their own PBRs.
Extended Boot Record (EBR): This is the logical first sector, i.e., the sector at the start of the Extended Partition. EBR contains a Partition Table, which lists the available Logical Partitions inside Extended Partition, i.e., it contains the starting addresses of each Logical Partition.
Logical Extended Boot Record (LEBR): This is the logical first sector residing at the start of each Logical Partition, similar to PBR.


Single OS Boot Process:
Whenever PC is turned ON, BIOS (Basic Input Output System) takes control, and performs a set of operations. It checks Hardware, Ports, etc. and finally loads the MBR program into memory (RAM).Now, MBR takes control over booting process.
Functions of MBR with only one OS installed in the system-
- Boot process starts by executing code in the first sector of the disk, MBR.
- MBR scans the partition table to find the Active Partition.
- Control is passed to that partition's boot record (PBR) to continue booting.
- The PBR locates the system-specific boot files (such as Win98's io.sys or WinXP’s ntoskrnl).
- Then these boot files continue the process of loading and initializing the rest of the OS.


Multiple OS Boot Process:
Whenever there are multiple OSes, be it multiple Windows or Windows with Linux, system boots a bit differently. Actually, there can be 2 different types of Boot Process in multiple OS environment; Microsoft way and Non-Microsoft way (or Third Party Boot Loader way).
Microsoft way: MS Master Boot loaders don’t recognize other types of OSes like Linux by default; hence using MS MBR in the presence of Linux is ruled out.
Consider the usual case, where there is one Primary partition and some Logical Partitions inside Extended Partition. Now if Win98 is installed in the Primary Partition, and afterwards WinXP is installed in a Logical Partition, then theoretically both OS should have their own Boot Records, i.e., PBR for Win98 and LEBR for WinXP, which contain programs to boot the respective OS, so that each individual OS can be booted up by the MBR by passing control to respective PBR of the OS as described in previous section.
But this doesn’t happen in MS Boot loader! It does a peculiar thing; it always considers the current Active Partition, the default System/Boot Partition, i.e., Primary Partition in which Win98 is installed as the Active Partition. When WinXP is installed in another partition, instead of writing the code for booting in WinXP's partition, WinXP writes the code in current Active Partition (where Win98 is installed)!
Program responsible for loading the WinXP is ntldr (standing for NTLoader). Theoretically, this should be in its partition, but is copied to that of Win98.
Then files responsible for Win98 booting are combined into a single file called bootsect.dos and placed in Win98 partition. Then, WinXP creates another file called boot.ini which contains the names of MS OSes installed and path for System files of each OS.

After all these preliminaries, Windows multi-boot can be represented as below-
- When BIOS hands over control to MS MBR, this program looks into Partition Table for Active Partition.
- Then it hands over the control to the PBR of Active Partition. In this case, the Active Partition is where Win98 was installed.
- But Win98 PBR has been altered by WinXP, and no longer contains Win98 boot program (like io.sys or msdos.sys). But it contains ntldr. The Peculiarity is that one OS’s Boot program is in another OS’s Partition!
- Ntldr looks into boot.ini file and finds out the MS OSes installed in the system and displays the option menu.
- When user selects Win98, the file bootsect.dos (present in same partition) is executed, and if WinXP is selected, ntoskrnl is executed (present in another partition).

The good thing about MS way is the ease to configure (you need not configure at all!). But the bad thing about MS MBR is that, the two OSes are not independent of each other. It is because, MS MBR always boots into the Active Partition, i.e., it always boots into Win98 Partition, but executes WinXP program! And further other OSes are loaded.
This does not provide flexibility of installing multiple MS OSes in a random order, because here older version of OS should be installed first and then newer versions of OSes should be installed (most common problem).

This boot process also has two limitations-
- There can be only one Real Mode DOS based OSes like Win95/Win98 along with NT based OSes. If you want both Win95, Win98 with any NT based OS, then it’s just not possible.
- MS MBR looks for Active Status in Primary Partitions only and not in Logical Partitions. This means, MS OSes should be installed in Primary Partitions only if it should be bootable. For this reason itself, WinXP boot file ntldr is placed in Primary Partition of Win98 instead of its own Logical Partition.
But this has led to the misconception that only OSes in Primary Partitions can be booted. But by replacing MS MBR by any other sophisticated MBR program which also looks for Active Status in Logical Drives, we can boot into OSes which are in Logical Drives directly. This is where third party Boot Loaders comes into picture!


Non-Microsoft way: Third-party Boot Loader load before the OS, hence they are independent of the OS. Therefore, they work fine with all versions of Windows and DOS.
In this system, installing multiple OSes is conceptually simple. First make as many Primary Partitions and Logical Partition as you want. Then set the status of one of the Partition as Active, and install an OS. After this set the status of that partition as Hidden (Inactive) and set another Partition as Active to install another OS and this can be repeated. By this older versions of Windows can be installed after the installation of new ones.
Then Third Party Boot Loader reads all Partitions (including Logical Partitions) from the Partition Table and prompts an option of OSes to boot.

The functions of a Third Party Boot Loader can be stated as below-
- Displays a list of all OSes present in both Primary and Logical Partitions.
- When the user selects an OS, Boot Loader makes the Partition of that OS as Active, and passes the control to it.
This step is the most important deviation from MS way, because in MS MBR, the Active Partition always remains same and after booting into it, OSes in other Logical Partitions are booted.
By this way, any OS can be booted directly, by toggling its Inactive/Active Status when the user selects it.
- Then, the Boot Sector of the corresponding OS takes control and loads the OS. This Boot Sector may be PBR of a Primary Partition or LEBR of a Logical Extended Partition.
By this way, each OS remains independent of each other. That is, boot programs ntldr of WinXP can remain in WinXP’s partition and Win98 boot programs can remain in its partition.
Since Third Party Boot Loaders are independent of OS, they support all type of OSes like Windows, Linux, UNIX, BeOS etc. XOSL is one free boot loader which is capable of handling 30 Operating Systems. To hide/unhide the partitions, Ranish Partition Manager, a freeware, can be used.

3 Comments:

Blogger Swapneel said...

Mate I needed to brush my partitioning skills & remembered this blog entry of yours.

Job well done mate.Really helpful.

11:21 AM  
Blogger swatkat said...

Thanks swapneel!

1:30 AM  
Anonymous Anonymous said...

Perfect. Well Done. The Best source on the net...

Just a thing to clear though>...

The MBR locates the active partition or
the mbr scans the partition boot record to locate the activer partition?

My book says the second version but I understood yours better!!!

Weird eh? lol

8:46 PM  

Post a Comment

<< Home