Dual booting Linux/Win2K off two drives with GRUB

This is a brief guide to how I got my Thinkpad T20 to boot off both Windows2000 and Linux on separate drives.

See also Linux gazette article on GRUB
GRUB home page
Obviously there are no guarantees that this will all work with your configuration (or even that I've remembered it all properly for mine), but hopefully it will help you. Some of the operations are necessarily destructive and therefore dangerous if you get the parameters wrong. Grub is great in that if you get something wrong, as long as it finds stage1 & 2 it will give you a command line and you can change the parameters a bit (point to a different linux kernel / partition for windows etc). I recommend making a grub floppy before doing this as a last resort (and I used it to put grub on my windows disk).

So, here's my description of how I installed Linux on a second drive, to the best of my memory. It relies on being able to swap my drives - one goes in the main slot of my thinkpad (/dev/hda), one in an ultrabay drive adapter (/dev/hdc). The drives themselves I'll refer to as "30" and "20" (their capacities).

I had Windows on one drive "30". With partition magic, I made a small (7MB) ext2 linux partition on drive 30. (You may be able to avoid this)

I took this out, put the other drive "20" in as the primary (only) drive and did a network install of an IBM variant of Redhat 7.2

Boot this, create a grub.conf file (see append) and run grub, to install grub in the master boot record:

grub> install (hd0,0)/boot/grub/stage1 (hd0) (hd0,0)/boot/grub/stage2 (hd0,0)/boot/grub/grub.conf
(Here I'm assuming that linux's /boot is in partition /dev/hda1 which appears as partition hd0,0 in grub. Filename completion with should find these files if they're in the right place. )

This is if I ever want to boot linux as /dev/hda again, though generally I want it to be /dev/hdc

Make a grub boot floppy disk.
Edit /etc/fstab so that it will work when 20 is /dev/hdc. (ie change all partition names from /dev/hdaX to /dev/hdcX If you do boot it as /dev/hda, then it will fail, but will give you a root command prompt, you can

mount -o remount,rw /dev/hda1 /
edit /etc/fstab to point to /dev/hdaX again, and reboot. I'm putting something in my /etc/rc.d/sysinit.d to make this happen automatically, After the action after this comment:
# Remount the root filesystem read-write.
I inserted the following:
mount | awk '$3=="/" {a=$1; gsub("/dev/hd","",a); gsub("[0-9]$","",a); } END {if (a!="") { b="ln -sf /etc/fstab"a" /etc/fstab"; system(b); print b;} else print "No mount drive found"; }'
Add 20 as /dev/hdc (may need a reboot), mount the new small ext2 partition on it and copy the grub files to it (in directory /boot/grub).

Swap the drives /dev/hda=30 (windows) /dev/hdc=20 (linux)
Boot with the grub floppy disk.
Install grub on the Master Boot Record of /dev/hda, with a grub.conf table (see below) pointing to the small linux partition (here assumed to be on partition 7, with windows on partition 0.

 
grub> install (hd0,7)/boot/grub/stage1 (hd0) (hd0,7)/boot/grub/stage2 (hd0,7)/boot/grub/grub.conf
I haven't checked booting into Windows with the drives reversed, but it seems to work into Linux or Windows when /dev/hda=30 (windows) and /dev/hdc=20 (linux).

windows hibernates OK, but I haven't yet managed to make a hibernate file that will let me hibernate linux.


######################################################################
# /boot/grub/grub.conf on 20: 
default 0
timeout 20

title Linux Ultrabay
	root (hd1,0)
	kernel /boot/vmlinuz-2.4.9-31 root=/dev/hdc1
	initrd /boot/initrd-2.4.9-31.img

title Linux MainDrive
	root (hd0,0)
	kernel /boot/vmlinuz-2.4.9-31 root=/dev/hda1
	initrd /boot/initrd-2.4.9-31.img

title Win2K Ultrabay
	rootnoverify (hd1,0)
	chainloader +1
	makeactive

title Win2K MainDrive
	rootnoverify (hd0,0)
	chainloader +1
	makeactive


######################################################################
# /boot/grub/grub.conf on 30: 
default 0
timeout 20

title Win2K MainDrive
	root (hd0,0)
	chainloader +1
	makeactive

title Linux Ultrabay
	rootnoverify (hd1,0)
	kernel /boot/vmlinuz-2.4.9-31 root=/dev/hdc1
	initrd /boot/initrd-2.4.9-31.img

title Linux MainDrive
	rootnoverify (hd0,0)
	kernel vmlinuz-2.4.9-31 root=/dev/hda1
	initrd /boot/initrd-2.4.9-31.img

title Win2K Ultrabay
	root (hd1,0)
	chainloader +1
	makeactive

Andrew Senior