Sunday, October 19, 2008

How to dualboot Linux and winblows XP

If you want to install XP on your machine alongside your existing Linux installation on the same physical drive which already has Ubuntu 8.04 installed.You will have to create space on the Linux partition to install winblows XP.
XP bootloader is fairly clumsy when it comes to dualbooting and will overwrite GRUB completely. You will have to reinstall GRUB to the MBR and configure it to dualboot both Ubuntu and XP.

So regardless of which bootloader you end up using, it's a very good move to first back up the GRUB bootloader. It's easy to lose it and unless you know how to re-write it you will hav to re-install Ubundu. tongue.gif

Ok so first start your Ubuntu and go to Applications --> Accessories --> Terminal.
Then, type in sudo gedit /boot/grub/menu.lst.
This text file contains all the information GRUB uses to configure various boot options.

Make a backup of the file by going to File, Save As and selecting a different location. Or take a full copy of the contents and place it into a new text file. If you can, create the backup on a removable disk or networked location. smile.gif

You will need to create space on the hard drive for XP, so this will involve resizing the main Ubuntu partition. Restart the system using the Ubuntu Live CD as this gives you access to GNOME Partition Editor. When the CD loads, select "Try Ubuntu without any change to your computer".
Once the CD loads, go to System, Administration, Partition Editor.
Right-click on the main data partition which has been formatted with ext3 - it should be /dev/sda1 - and select "Resize/Move". Move the slider from the right to shrink the ext3 partition and create free space on the hard drive, which will take the NTFS XP partition. Make sure that the free space is sufficient to hold XP (at least 2GB - preferably 5GB). Then click "Resize/Move" to confirm the selection, and "Apply" back in the main screen to carry out the pending change.

Restart the system with the winblows XP CD and boot into the install program.
In my opinion nfortunately XP isn't so adaptive at handling existing partitions during installation. It detects the two Ubuntu partitions and marks then C: and E: accordingly.
The remaining unpartitioned space which is available for XP will be marked as F:.
For the OS and the vast majority of winblows applications which have properly-coded installation scripts, this is not a problem. Some older applications will assume that C: is the system partition and may bring up errors. sad.gif
There are ways of changing the drive letter assignation of the system partition, but in this scenario it's strongly discouraged.
To insult to injury, XP detects the Linux partition as an active system partition and won't install unless it marks this partition as inactive.

Oki once XP has been installed, it will boot happily into XP but there's no sign of Ubuntu and you will be like WTF???. Tho to reinstate GRUB as the system bootloader it needs to be reinstalled into the MBR.
Boot the system from the Ubuntu Live CD and select "Try Ubuntu without any change to your computer".
Open a Terminal session again - Applications, Accessories, Terminal
To enter the GRUB configuration mode, type in "sudo grub" and press Enter. Then type in the following commands in sequence:
- root (hd0,0)
- setup (hd0)
- quit
- exit

Now once you enter that you need to rboot the system you'll get the GRUB bootloader but XP won't be an option - we need to add this to the boot options.
Boot into Ubuntu and open up another Terminal session. Then, type in sudo gedit /boot/grub/menu.lst then scroll down to the bottom of the file and type in the following text strings:
title winblows XP
root (hd0,1)
makeactive
chainloader +1

Save the file and reboot. When the GRUB loader launches hit ESC for the boot menu. winblows XP is the last option - select it and XP will load.
And thats it now you have two OS's and you can chose which one you would like to start.

Alternate method to repair grub with Knoppix


Here's an alternate method to repaid the boot loader if you've installed winblows. Im assuming knoppix, but im not sure if you can do this with other live cd's as well.

First identify the root partition (im assuming this is something like /dev/hda1).
Mount the partition as writeable (if it isnt).

CODE
sudo mount -o dev,rw /mnt/hda1


Once mounted restore grub:

CODE
sudo chroot /mnt/hda1 grub-install /dev/hda


Note: if you use devfs or for some reason the chroot environment doesn't work you can mount the file system with write permissions then run:

CODE
sudo grub-install -root-directory=/mnt/hda1 /dev/hda


Knoppix also has an update-grub utility (i don't know if it's knoppix specific or if other distros have it). This will automatically generate a menu.lst file for you by scanning the disk for usable kernels and automatically create the menu.lst file. To use it you must run it in a chroot environment. Assuming the root partition is /mnt/hda1:

CODE
cd /mnt/hda1
sudo mkdir boot/grub
sudo cp /sbin/update-grub ./
sudo chroot /mnt/hda1 /update-grub


The final command will prompt you to create a menu file. Click yes.

If you dont have grub installed but want to you can with knoppix. First use the above commands to create the menu file. If the first time grub-update is run it fails to detect the correct root device to use (lets say instead of hda1 you use hda2) open the newly generated menu.lst file (/boot/grub/menu.lst) and edit the line:

CODE
# groot=(hd0,0)


to

CODE
# groot=(hd0,1)


DO NOT REMOVE THE HASH (comment)!! This line is simply a hint to the grub-update tool. Keep it commented out.

The numbering system is pretty simple. It starts from 0 rather than 1. So hda1 = hd0,0 hda2 = 0,1 hda3 = 0,2 and so forth.

Once this is done rerun update-grub to update the menu.lst file:

CODE
cd /mnt/hda2
sudo chroot /mnt/hda2 /update-grub


(Assuming your root is hda2)

Once this is done you are ready to install grub to the boot sector. This doesn't require a chroot environment but you must tell grub-install to use /mnt/hda1 (or whatever) as your root directory:

CODE
sudo grub-install --root-directory=/mnt/hda1 /dev/hda
I hope you find this Topic helpfull. tongue.gif

No comments: