Thursday, December 08, 2005

Dual Boot Windows XP and Linux

I installed Linux first. I left the first partition for Windows. I installed Linux first and then installed Windows XP Pro.

Steps:
1) Partition entire drive during linux install. I created the following partitions:
Partition 1 - ntfs - /dev/hda1 - 10gigs
Parittion 2 - ext3 - /dev/hda2 - I made this just a 512M /boot partition to contain my boot images and GRUB config.
Partition 3 - Logical Partition (LVM) - /dev/hda3 - containing 1 volume group with two volumes: home and root - 68 gigs
Partition 4 - Swap - /dev/hda4 - 2 gigs

The nice thing about using a logical volume is that it can be dynamically sized and resized over time. It supposedly does have a small performance hit, so for servers with lots of disk activity, it needs more investigation.

2) Install Linux.
Easy step.

3) Backup MBR
The MBR is stored on first 512 bytes of your primary drive. To back it up is really easy -- just use "dd". One word of caution, though -- make sure you back it up to a drive that is NOT a Logical Volume. That is, put it on a floppy (or your iPod as I did!). If you do, it is still possible to get it back, so don't worry.

$ dd if=/dev/hda of=/media/ipod/mymbr.bak count=1 bs=512

4) Install Windows.
When installing windows, choose the parition you want to install it on. I've heard Windows only really likes to be installed on /dev/hda1, so that is what I always stick to.

Windows will tromp your MBR, so it will only boot into Windows. No worries, though -- the partition table is still there and your data should be there, too!

5) Restore MBR because Windows is not nice and rewrites it.

To do this, I use Knoppix. Download it for free and burn a cd. You can use just about any bootable linux distro. Basically, it is linux which boots into a desktop with most of the common utilities ever needed. I've even used it as a diskless workstation before and used a 512meg pen drive as my home directory.

Once booted into Linux, just put in your floppy or mount your disk where you backed the MBR up to. Then restore the MBR:

$ mount -t ext3 /dev/hda2 /mnt/hda2 (this was my /boot partition was just an ext3 partition)
$ dd in=/mnt/hda2/mymbr.bak of=/dev/hda count=1 bs=512

Then reboot and you should be back into Linux.

6) Update GRUB to boot Windows.
Once back into your previously installed linux, edit /boot/grub/menu.lst and add the following to GRUB's config to optionally boot into Windows during power on:

title Microsoft Windows XP Pro
root (hd0,0)
makeactive
chainloader +1

Other notes:
When I originally partitioned my /dev/hda1, I set the partition type to FAT32. However, when I installed XP, I formatted it as NTFS. When I did all of the above steps, Ubuntu would not load. It complaied during startup that /dev/hda1's partition type was incorrect and just hung. Seems like it should have continued, but it didn't. In /etc/fstab, I could probably add "errors=remount-ro" to /dev/hda1. Anyways, this is what I had to do to get things all fixed back up.

1) Boot into Knoppix
2) Install LVM support (http://www.knoppix.net/wiki/LVM2) and mount your root partition (or wherever you have /etc mounted on).
3) vi /mnt/myoldroot/etc/fstab and comment out the entry for /dev/hda1
4) Once I was able to boot back into my Ubuntu system, I again edited /etc/fstab and changed the type to NTFS and did a "mount -a" to mount it and check it out.
5) To fsck the filesystem:
fsck -a /dev/VolGroup00/LogVol00 # took a long time

Other LVM links:
http://www-128.ibm.com/developerworks/library/l-lvm2.html?n-l-4121
Channel #lvm on freenode

No comments: