# [Guide] Operating System Boot Process.



## swatkat (Mar 23, 2005)

*Hard Disk and Partitions:-*

Partitioning is a process of dividing the Hard disk into several chunks, and use any one of the partition to install OS or use two or more partitions to install multiple OSes.
But you can always have one partition, and use up the entire Hard disk space to install a single OS, but this will become data management nightmare for users of large Hard disks.
This is where advantage of partitioning lie!

Now, because of the structure of the Master Boot Record (MBR), you can have only _four_ partitions, and these _four_ partitions are called *Primary Partitions*.
Again, If we have a large hard disk, we can not have only four primary partitions, hence *Extended Partition* is introduced. This Extended Partition is not a _usable_ partition by itself, but it’s like a “container” and it is used to hold *Logical Drives*!
That is this Extended Partition can be subdivided into multiple logical partitions.

In order to boot into a Partition, *it must be designated as bootable partition or Active Partition*. Active Partition is that partition 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 hard disk. The location is denoted as CHS 0,0,1 meaning 0th Cylinder, 0th Head and 1st Sector. MBR contains a small program known as _*bootstrap*_ program which is responsible for booting into any OSes. MBR also contains a _table_ known as *Partition Table*.
This Partition Table is a table which lists the available *Primary Partitions* in the hard disk. So it can have only four entries. This rises another question, what if we have more than four partitions? This is solved by Extended Partition principle. Partition Table considers whole Extended Partition as one Primary partition and lists it in the table!
So a Partition Table can have two possible entries:-
1] up to 4 Primary Partitions
2] up to 3 Primary Partitions and 1 Extended Partition.(Total not exceeding 4)

Partition Boot Sector (PBR):- This is the *logical* first sector, that is sector at the start of a Primary Partition. This is also 512 byte area, which contains some programs to initialize or run OS files.All Primary Partitions have it’s own PBRs.

Extended Boot Sector (EBR):- This is the *logical* first sector, that is the sector at the start of the Extended Partition. This EBR contains a Partition Table, which lists the available Logical Partitions inside Extended Partition. That is it contains the Starting addresses of each Logical Partitions.

Logical Extended Boot Sector (LEBR):- This is the logical first sector residing at the start of *each* Logical Partition. This is similar to PBR for Primary Partitions.



 *Single OS Boot Process:-*

Whenever PC is turned ON, BIOS takes the control, and it performs _a lot_ of operations. It checks the Hardware, Ports etc and finally it loads the MBR program into memory (RAM).
Now, MBR takes control of the booting process. Functions of  MBR, when there is only *one* OS is installed in the system are as given below:-
1] The boot process starts by executing code in the first sector of the disk, MBR.

2] The MBR looks over the partition table to find the *Active Partition*.

3] Control is passed to that partition's boot record (PBR) to continue booting.

4] The PBR locates the system-specific boot files (such as Win98's io.sys or WinXP’s ntoskrnl). 

5] 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, then Boot process will be slightly different.
Actually, there can be two different types of Boot Process in multiple OS environment, Microsoft way and Non-Microsoft way (or Third Party Boot Loader way!).

Microsoft way:- Microsoft Master Boot loaders doesn’t recognize other types of OSes like Linux (in default, that is!), hence using Microsoft MBR in the presence of Linux is ruled out.
Consider the case that (_this is the general case_), 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 program 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 does not happen in Microsoft Boot loader! It does a peculiar thing, that it always considers the current *Active Partition* as the default *System/Boot Partition*.
That is Primary Partition in which Win98 was installed is the Active Partition, then when WinXP is installed another partition, instead of writing the code for booting in it's partition, WinXP writes the code in current Active Partition (that is, where Win98 is installed)! 
Program responsible for loading the WinXP is *ntldr* standing for NTLoader. Theoretically, this should be in it’s partition, but this copied to that of Win98.
Then files responsible for Win98 booting is combined into a single file called *bootsect.dos* and this is also placed in the Win98 partition.
Then, WinXP creates another file called *boot.ini* which contains the names of *Microsoft* OSes installed and path for System files of each OS.

After all this prelims, Windows multiboot can be represented as below:-
1] When BIOS hands over control to Microsoft MBR , this program looks into Partition Table for Active Partition.

2] Then it hands over the control to the PBR of Active Partition. In this case, the Active Partition is where Win98 was installed.

3] But Win98 PBR has been altered by WinXP, and it no longer contains Win98 boot program (like io.sys or msdos.sys). But it contains *ntldr*! Peculiarity is that one OS’s Boot program is in another OS’s Partition!

4]ntldr looks into boot.ini file and _finds out_ the Microsoft OSes installed in the System and displays the option menu.

5] When user slects Win98, the file *bootsect.dos* (which is in same partition) is executed, and if WinXP is selected, *ntoskrnl* is executed (which is in another partition!).

The good thing about Microsoft way is that, it’s very easy to configure (_you don’t have to configure at all!_).
But the bad thing about Microsoft MBR is that, the two OSes are *not independent* of each other.It is because, that Microsoft MBR *always* boots into the Active Partion (that is it always boots into Win98 Partition, but executes WinXP program!) and from here other OSes are loaded.
This does not provide flexibility of installing multiple Microsoft OSes in a random order, because here _older version_ of OS should be installed first and then _newer versions_ of OSes should be installed.

This boot process also has two limitations:-
1] 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 simply not possible.

2]Microsoft MBR looks for Active Status in *Primary Partitions* only and not in Logical Partitions. This means, Microsoft 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 it’s own Logical Partition).

But this has led to misconception that only OSes in Primary Partitions can be booted. But by replacing Microsoft 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 come into picture!


Non-Microsoft way:- Third-party Boot Loader load before the OS, so 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 on OS. After this set the status of that partition as “Hidden” (or “Inactive” ) and set another Partition as “Active” and install another OS and this can be done for all Partitions. 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 provides with an option of OSes to boot.

The functions of a Third Party Boot Loader can be stated as below:-
1] Displays a list of all OSes present in both Primary and Logical Partitions.

2] When an user selects one 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 Microsoft way, because in Microsoft MBR, the “Active” Partition always remains same and after booting into it, OSes in other (Logical) Partitions are booted.
But here, a Partition is flagged as Active at the time of the selection by the user,by this way, any OS can be booted directly, by toggling it’s Inactive/Active Status when an user selects it.*

3] 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 (io.sys, msdos.sys) can remain in _it’s partition._.
Since Third Party Boot Loaders are independent of OS, they support all type of OSes like Windows, Linux, Unix, BeOS etc.


A good Boot Loader is XOSL, which has a graphical interface and supports upto 24 OSes and it can also boot OSes installed in Logical Partitions.
Download XOSL


----------



## tuxfan (Mar 24, 2005)

Good informative post  Are these your own words? If yes, great work. If no, still great work, but please let us have the source. May be there's some more info there at that place.


----------



## swatkat (Mar 24, 2005)

it's my work indeed!


----------



## theraven (Mar 24, 2005)

2 brainiacs fighting for it eh ? 
nice work swat ... as usual


----------



## tuxfan (Mar 25, 2005)

swatkat said:
			
		

> it's my work indeed!


Then, hats off to you buddy. GRAND WORK 



			
				theraven said:
			
		

> 2 brainiacs fighting for it eh ?
> nice work swat ... as usual



Not fighting, just clarifying. Trying to find out how much credit is due for the work to sawtkat  As it turned out, lots of it is due


----------



## Sourabh (Mar 25, 2005)

i wod like the guys to check this and temme

swatkat wht is tht forum and u posted there abt 10 days back and so late on digit

very badd !!

whts tht portal abt ??


----------



## swatkat (Mar 25, 2005)

Sourabh said:
			
		

> i wod like the guys to check this and temme
> 
> swatkat wht is tht forum and u posted there abt 10 days back and so late on digit
> 
> ...



Sourabh, found it!  
i think you Google'd the Post tilte, and my post in CCSP came in 3rd! i really didnt checked out that!
It is a Computer Security forum. Yea, i posted there some days back, someone there had some doubts about the boot.ini and dual booting stuff!
But, this guide was posted first here.


----------



## Sourabh (Mar 26, 2005)

well isnt it a good idea to get more info abt the topic which are posted

everyone has to be more broad minded and use the forum to learn more new things

i read the whole thing in ur post and wanted more info about it

anyways a good Guide

keep them coming


----------



## nmanikoth (Jul 31, 2008)

Thanks very much for the useful info for laymen like me!
Can you please guide me how to recover data from my 250 GB SATA drive? Had formatted the OS partitions and re-installed, now the remaining 7 partitions are inaccessible and show the partition names as "Local Disk" with file system as "Raw".
Thanks in advance.


----------



## amitava82 (Jul 31, 2008)

there u go.. another NOTW. Tnx for pulling out 3 years old thread.


----------



## New (Jul 31, 2008)

Very informative..Thanks for the post..


----------



## tapan.d.thakkar (Apr 9, 2009)

swatkat said:


> it's my work indeed!




wen ever  i start my pc i get an error like
c:\windows
boot.ini file is invalid

wat should i do to solve it?????

plz rpl.....


----------



## Cool Joe (Apr 9, 2009)

^Your boot.ini is damaged or missing.
Follow the steps mentioned here to solve the issue.
-----------------------------------------
Posted again:
-----------------------------------------
And look at the date of the previous post!


----------



## i-Alpha (Apr 17, 2009)

gr8 tutorial
Thanks a lot!


----------



## Krazy Bluez (Apr 17, 2009)

STOP pulling out old threads from Grave...


----------



## vishwakarma (Apr 19, 2009)

cool!!!
This is very informative.
This has enriched my knowledge


----------



## prudhivisekhar (Apr 19, 2009)

really nice info.!!!!!!!!!!!11
-----------------------------------------
Posted again:
-----------------------------------------
Really informative.


----------



## Rahim (Apr 20, 2009)

The explanation is very lucid. Thanks swatkat.

@Krazy Bluez: The info doesnt become old and unimportant just because the thread is old.


----------



## topgear (Aug 11, 2009)

Great tutorial..& very comprehensive & nice explanation


----------



## ramprasad (Oct 29, 2009)

Awesome work.. 
I appreciate it... 

BTW, I liked ur username...


----------



## silicon_fusion (Nov 7, 2009)

Thanks for sharing such a useful info...


----------

