Monday, September 22, 2008

Dual boot with XP/2000/NT and install linux/windows whenever You want

This is for those people who have dumped Windows 98 and adopted Windows 2000/NT/XP as their os's and want linux to dual boot with these.

CAUTION : This how to wont work with Windows 98/95/ME . Actually i haven't used ME and so i don't know.Anyways this will only work with those Windows versions which use ntloader to boot.

There are a few pre requisites.

a) a linux boot disk/live cd
b) Use Windows 2000/NT/Xp and one of its partitions must be FAT (other than NTFS)
c) You should really know basics like partition naming in Linux and mounting.


Problem :

Installing / re installing Linux/Windows 2000/XP/NT whenever You want , without managing to mess up the MBR.


Scenario 1.

Installing Linux along with an existing windows installation .

I.Setting Up partitions

If You don't have a linux partition , make space for it , by repartitioning my disk.

Ideally You would free up a partition and divide it into two , one part for swap space , the other part for the installation.swap space partition size = 2 times that of your RAM

In the non ideal case that is , if you cant free up a whole partition you would first defragment the drive and then create two new partitions from it using PQMagic , so you don't loose data and you get two more drives. the new partition's size will be as above

II.Installing Linux

Now you can go about installing your linux system. Here the issue to be taken care of is installing the boot loader (LILO/GRUB) to the proper place

Usually the installation program will ask u were to load the boot loader. default choice would be on the MBR. Now DON'T GO FOR THIS . If u want to go my way , don't go for it. Instead , get the installer to install the boot loader onto the root partition.Also note down the root partition's name , ie) the '/dev/hda*' where * is 1,4,5 etc.
If possible create a boot disk

III. Setting up the system to boot windows too.

now when you reboot , you will go directly to the NT/XP/2000 boot menu.

Don't worry , your Linux installation is safely sitting there.

Now boot using the linux boot disk / live cd

mount the non NTFS windows partition using the following commands

mkdir /mnt/windowsdrive
mount /dev/hda* /mnt/windowsdrive

where * is 1,4,5 etc.


Now use this command to get first 512 bytes of your root partition


dd if=/dev/hdaN of=/mnt/windowsdrive/bootsect.lnx bs=512 count=1


replace /dev/hdaN with your Linux root partition name (/dev/hda something) .I had asked you to note it down , hadn't I?

now boot to windows. find out the bootsect.lnx file from which ever drive u wrote it to using the previous command.Copy it to C:\

open boot.ini and add the following line to its end

c:\bootsect.lnx="Linux"

Reboot

Now you will see "Linux" showing up in your Windows boot menu.

When u choose linux it will load the linux boot loader (LILO/Grub which ever u installed.)

You may want to remove the "Windows" choice from the linux boot loader's menu. There is no harm if u leave it there



Scenario 2.

Installing Windows NT/2000/XP along with an existing Linux installation .

1.Setup partitions.

Don't touch the linux partitions. No other precaution needed. also make the windows partition bootable.

2.Install Windows NT/2000/XP. Let it over write the MBR

3.Follow step III of Scenario 1.

Thats all