Linux Step By Steps
Using GRUB to load Windows XP located on a second hard disk
Written by James McDonald on 01-Sept-03.


Please read this warning BEFORE you start.

Because my trusty old Pentium III died I moved two hard disks onto my Athlon 1GHz machine and made my Redhat 9.0 Linux install the Primary or first hard disk . The windows XP install which I use occassionally I inserted as the slave drive on the same IDE0 Channel. This is my setup as follows.

IDE0 Channel 0 = GNU/Linux Redhat 9.0 20GB
IDE0 Channel 1 = Windows XP SP1 30GB
IDE1 Channel 0 = DVD/CD ROM/CDRW

The out put from fdisk for my harddisks was this

[root@p3 james]# /sbin/fdisk -l

Disk /dev/hda: 20.4 GB, 20485785600 bytes
255 heads, 63 sectors/track, 2490 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot    Start       End    Blocks   Id  System
/dev/hda1   *         1        13    104391   83  Linux
/dev/hda2            14      2360  18852277+  83  Linux
/dev/hda3          2361      2490   1044225   82  Linux swap

Disk /dev/hdb: 30.0 GB, 30020272128 bytes
255 heads, 63 sectors/track, 3649 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot    Start       End    Blocks   Id  System
/dev/hdb1   *         1      1020   8193118+   7  HPFS/NTFS
/dev/hdb2          1021      3649  21117442+   7  HPFS/NTFS


I still wanted to be able to boot my XP install but I didn't want to go the way of installing the Windows XP boot loader (this is the booting Linux from Windows way of doing it - Not the booting Windows from Linux which is what I wanted)

I tried lilo but found the options confusing (and googling didn't give an obvious solution), but GRUB had a good bit of information on running DOS/Windows.

I found the info by running:

info grub
# Look for booting another OS and then find the Windows section

I didn't have GRUB installed I was running lilo so I installed GRUB to the MBR (master boot record) of the first hard disk by running the following command

/sbin/grub-install /dev/hda
# because the second hard disk wasn't present when grub was originally installed
# it had to be added to the /boot/grub/device.map file
vi
/boot/grub/device.map
# this device map was generated by anaconda
(fd0)     /dev/fd0
(hd0)     /dev/hda
(hd1)   /dev/hdb
# added this line


Contents of /etc/grub.conf

# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/hda2
# initrd /initrd-version.img
#boot=/dev/hda
default=0
timeout=10
splashimage=(hd0,0)/grub/splash.xpm.gz
title Red Hat Linux (2.4.20-8)
    root (hd0,0)
    kernel /vmlinuz-2.4.20-8 ro root=LABEL=/ hdc=ide-scsi
    initrd /initrd-2.4.20-8.img
title Windows XP
   
# as far as I can understand it the Windows XP hard disk hd1
    # needs to think it is the first disk on the IDE bus in order to boot
    # so do a swap and add the following two commands to change it
    map (hd0) (hd1)
    map (hd1) (hd0)
   
# you then need to tell grub which hard disk and which partition to read the booting information from
    # although you have done a swap using the above commands the disks don't change their labelling
    # so use hd1,0 as the root device (in grub all numbering starts at zero)
    # the telltale to knowing which partition to add to the rootnoverify option
    # is the output of fdisk -l the `*' on /dev/hdb1 showing it's the active or boot partition
    rootnoverify (hd1,0)
    # now tell grub that you are going to be doing an indirect boot using an external chainloader
    # i.e it's going to grab the Windows boot code and run it instead
    # of directly loading the linux kernel like it usually does.
    chainloader +1
 
   # not sure exactly what makeactive does
    # I'm assuming it is marking the root partition you specified
    # with the rootnoverify command as the active or boot partition
    # if it isn't already marked as the `*' or boot partition
    makeactive
   

nb: Make sure you back up your data and configuration before playing with your hard disk configuration it can really suck to lose important information.