# Booting Windows XP from GRUB (was: Where is my filesystem?!)

## Theophile

Okay, I will try to be concise yet descriptive. I've been trying to install Windows XP on a primary slave drive for gaming. That was a hassle in and of itself. Finally, I'm ready to add a GRUB entry for XP. I follow the suggestion here and add the following to /boot/grub/grub.conf:

```
title=Windows XP

map (hd0) (hd1) # Tell the first hard drive to pretend to be the second

map (hd1) (hd0) # Tell the second hard drive to pretend to be the first

root (hd1,0) # Tell GRUB Windows is on /dev/hdb1 (No pretending here)

rootnoverify (hd1,0) # GRUB won't attempt to mount the Windows drive

makeactive # Sets the partition to active

chainloader +1 # Tells GRUB to load the Windows bootloader when done 
```

Then I do 'grub-install /dev/hda' and reboot. I get the new GRUB menu but the XP entry doesn't work. Complains about wrong executable format or some such thing. So I boot back into Gentoo to tweak the entry a bit. This time, based on this thread I change it to the following:

```
title              Windows XP

root               (hd1,0)

savedefault

makeactive

map                (hd0) (hd1)

map                (hd1) (hd0)

chainloader        +1
```

I re-do 'grub-install /dev/hda' and reboot. Except now, instead of a GRUB menu, I get a blinking "_" in the upper left corner.

So I figure I've hosed my MBR. No big deal, I just use a boot device to get back into the OS and reinstall GRUB. So I threw my 64MB USB flash drive into another machine, make a new ext2 partition on it, and install GRUB to the USB drive with a basic menu entry:

```
title=Linux

root (hd0,0)

kernel (hd0,0)/boot/vmlinuz root=/dev/hda1
```

At this point I must mention that the drive has two partitions. /dev/hda1 is the data partition and /dev/hda2 is the swap partition. I did not create a dedicated boot partition as the install guide recommends.

So this should work. I put the USB drive in the hosed machine, configure the BIOS to boot off the USB drive, and fire her up. GRUB menu appears and I select "Linux" but it complains about file not found. So I go into the command edit mode in GRUB with allows you to modify the bootloader commands. I go to edit this command:

kernel (hd0,0)/boot/vmlinuz root=/dev/hda1

Now, this allows you to use TAB completion, which I was counting on to find whatever file it can't find. I type in:

"kernel (hd0," and hit TAB, and it automatically fills in the second zero. So I have "kernel (hd0,0)". So I add the slash and hit TAB and it only gives me two directories!

```
kernel (hd0,0)/

lost+found    boot
```

ACK! I type 'boot' and hit TAB and the subdirectory 'grub' is automatically filled. If I hit TAB again, it lists the contents of the directory:

```
device.map     grub.conf.sample  reiserfs_stage1_5  ufs2_stage1_5

e2fs_stage1_5  iso9660_stage1_5  splash.xpm.gz      vstafs_stage1_5

fat_stage1_5   jfs_stage1_5      stage1             xfs_stage1_5

ffs_stage1_5   menu.lst          stage2

grub.conf      minix_stage1_5    stage2_eltorito
```

But as far as I can tell, the /boot directory appears to GRUB to be empty, other than the grub subdirectory!

So where is my filesystem?! And how could this have happened? I have all the commands I typed leading up to this issue because I was doing the work over ssh. This even shows that there are files in /boot! Look:

```
theophile@graven ~ $ ssh root@farmer

root@farmer's password: 

Last login: Thu Jul 19 2007 18:56:39 -0500

No mail.

Farmer ~ # grub

grub              grub-md5-crypt    grub-terminfo     

grub-install      grub-set-default  

Farmer ~ # grub 

Probing devices to guess BIOS drives. This may take a long time.

Farmer ~ # cd /boot

Farmer boot # ls

System.map                       config-2.6.17.13

System.map-2.6.19-gentoo-r7      config-2.6.19-gentoo-r7

System.map-2.6.19-gentoo-r7.old  config-2.6.19-gentoo-r7.old

System.map-2.6.21-gentoo         config-2.6.21-gentoo

System.map.old                   config.old

boot                             grub

config                           vmlinuz

config-2.6.12.3                  vmlinuz-2.6.19-gentoo-r7

config-2.6.12.3.old              vmlinuz.old

Farmer boot # cd grub/

Farmer grub # ls

device.map     grub.conf.sample  reiserfs_stage1_5  ufs2_stage1_5

e2fs_stage1_5  iso9660_stage1_5  splash.xpm.gz      vstafs_stage1_5

fat_stage1_5   jfs_stage1_5      stage1             xfs_stage1_5

ffs_stage1_5   menu.lst          stage2

grub.conf      minix_stage1_5    stage2_eltorito

Farmer grub # nano -w grub.conf

Farmer grub # grub-install 

install_device not specified.

Usage: grub-install [OPTION] install_device

Install GRUB on your drive.

  -h, --help              print this message and exit

  -v, --version           print the version information and exit

  --root-directory=DIR    install GRUB images under the directory DIR

                          instead of the root directory

  --grub-shell=FILE       use FILE as the grub shell

  --no-floppy             do not probe any floppy drive

  --force-lba             force GRUB to use LBA mode even for a buggy

                          BIOS

  --recheck               probe a device map even if it already exists

INSTALL_DEVICE can be a GRUB device name or a system device filename.

grub-install copies GRUB images into the DIR/boot directory specfied by

--root-directory, and uses the grub shell to install grub into the boot

sector.

Report bugs to <bug-grub@gnu.org>.

Farmer grub # grub-install /dev/hda

Installation finished. No error reported.

This is the contents of the device map /boot/grub/device.map.

Check if this is correct or not. If any of the lines is incorrect,

fix it and re-run the script `grub-install'.

(hd0)   /dev/hda

Farmer grub # nano -w /boot/grub/device.map 

Farmer grub # grub-install /dev/hda

Installation finished. No error reported.

This is the contents of the device map /boot/grub/device.map.

Check if this is correct or not. If any of the lines is incorrect,

fix it and re-run the script `grub-install'.

(hd0)   /dev/hda

(hd1)   /dev/hdb

Farmer grub # reboot

Broadcast message from root (pts/0) (Thu Jul 19 19:46:56 2007):

The system is going down for reboot NOW!

Farmer grub # Read from remote host farmer: Connection reset by peer

Connection to farmer closed.

theophile@graven ~ $ ssh root@farmer

root@farmer's password: 

Last login: Thu Jul 19 2007 19:52:12 -0500

No mail.

Farmer ~ # nano -w /boot/grub/menu.lst

Farmer ~ # nano -w /boot/grub/grub.conf

Farmer ~ # grub-install /dev/hda

Installation finished. No error reported.

This is the contents of the device map /boot/grub/device.map.

Check if this is correct or not. If any of the lines is incorrect,

fix it and re-run the script `grub-install'.

(hd0)   /dev/hda

(hd1)   /dev/hdb

Farmer ~ # reboot

Broadcast message from root (pts/0) (Thu Jul 19 19:56:43 2007):

The system is going down for reboot NOW!

Farmer ~ # Read from remote host farmer: No route to host

Connection to farmer closed.
```

You can see the directory listing for /boot and you can also see the logoff an login from the first attempt with the new GRUB menu. After than successful reboot, all I did was edit the menu and re-run the GRUB installer with the same command I use the first time.

Please, I need help figuring out what to do. Can I boot into this system?

Thanks in advance!

----------

## bunder

don't worry about mapping for a while, and try with just:

 *Quote:*   

> title=winxp
> 
> rootnoverify (hd1,0)
> 
> makeactive
> ...

 

you shouldn't have to do a grub-install, just editing the grub.conf should suffice.

let us know how that turns out.   :Smile: 

----------

## Theophile

Thanks, I will try that. But right now, my main concern is getting back into my Gentoo system. Any ideas on that?

----------

## bunder

 *Theophile wrote:*   

> Thanks, I will try that. But right now, my main concern is getting back into my Gentoo system. Any ideas on that?

 

you can list multiple operating systems in the grub.conf... just add a section for gentoo along with the windows config i mentioned earlier...  something probably like:

 *Quote:*   

> title=gentoo
> 
> root (hd0,0)
> 
> kernel /boot/vmlinuz root=/dev/hda2

 

see http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?full=1#grub

cheers

----------

## Theophile

Thanks, I do appreciate the support. But if you read the original post, you'll see that my difficulty is a bit more advanced than that. Please let me know what you think. Thanks!

----------

## bunder

give this a try... hopefully it gets you going without using a usb stick to boot.

make the windows drive the primary master.

make a /boot partition on the linux drive... mount up, make sure that the kernel is there.

unmerge grub, clean out /boot/grub, re-emerge grub.

run grub... "root (hd1,0)" "setup (hd0)" "exit".  (this puts the mbr on the windows drive and points it to the linux drive)

edit grub.conf, add the windows and gentoo entries.

that should do it.   :Smile: 

----------

## Theophile

I was in the middle of doing that (actually, something similar) when you posted. It actually worked! Thanks! I am back into my Gentoo system now. If only I could get XP to boot.

I keep getting the unsupported executable format error, even with the menu entry you suggested.

----------

## bunder

 *Theophile wrote:*   

> I keep getting the unsupported executable format error, even with the menu entry you suggested.

 

can we see your new grub.conf and maybe listings of "fdisk -l /dev/hda" hdb etc?

----------

## Theophile

Absolutely!

```
Farmer ~ # cat /boot/grub/grub.conf

default 0

timeout 15

title=Gentoo

root (hd0,1)

kernel /boot/vmlinuz root=/dev/hda2

title=Windows XP 

rootnoverify=(hd1,0)

makeactive

chainloader +1
```

And...

```
Farmer ~ # fdisk -l /dev/hda

Disk /dev/hda: 122.9 GB, 122942324736 bytes

255 heads, 63 sectors/track, 14946 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System

/dev/hda1               1          31      248976   82  Linux swap / Solaris

/dev/hda2   *          32       14946   119804737+  83  Linux

Farmer ~ # fdisk -l /dev/hdb

Disk /dev/hdb: 40.0 GB, 40020664320 bytes

255 heads, 63 sectors/track, 4865 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System

/dev/hdb1   *           1        4864    39070048+   7  HPFS/NTFS
```

Thanks!

----------

## Veldrin

Change rootnoverify=(hd1,0) to root (hd1,0)...

I should look like this.

```
title=Windows XP

root (hd1,0)

makeactive

chainloader +1
```

----------

## xanas3712

Here's an example from another location where someone fixed a similar problem.

I haven't had this problem because my windows is /dev/sda1

It does appear that the mapping is needed from this..

```

#

# Note that you do not have to rerun grub after making changes to this file

# NOTICE: You do not have a /boot partition. This means that

# all kernel and initrd paths are relative to /, eg.

# root (hd0,0)

# kernel /boot/vmlinuz-version ro root=/dev/hdc1

# initrd /boot/initrd-version.img

#boot=/dev/hdc

default=1

timeout=8

splashimage=(hd0,0)/boot/grub/splash.xpm.gz

hiddenmenu

title Fedora Core (2.6.9-1.667)

root (hd0,0)

kernel /boot/vmlinuz-2.6.9-1.667 ro root=LABEL=/1 rhgb quiet

initrd /boot/initrd-2.6.9-1.667.img

title Microsoft Windows XP Pro

root (hd1,0)

map (hd1) (hd0)

map (hd0) (hd1)

makeactive

chainloader +1 

```

It also appears that "root" vs "rootnoverify" matters as well, so the suggestion above to change is something you'll apparently want to follow.

From :

http://www.linuxcompatible.org/GRUB_cant_boot_windows_XP._t30932.html

----------

## jburns

 *Veldrin wrote:*   

> Change rootnoverify=(hd1,0) to root (hd1,0)...

 

root will try to access the windows partition but because it does not understand the windows filesystem it will generate an error and abort the bootstrap of windows.  rootnoverify tells grub not to access the filesystem which avoids the error and allows the bootstrap to continue.

 *Quote:*   

> map (hd1) (hd0)
> 
> map (hd0) (hd1) 

 

Is needed because windows is not on the disk that the BIOS used to boot the system.

The grub.conf file should contain 

```
title Microsoft Windows XP Pro

rootnoverify (hd1,0)

map (hd1) (hd0)

map (hd0) (hd1)

makeactive

chainloader +1 
```

If windows generates an error about a corrupt or missing file when it is booted check the contents of windows boot.ini file.

----------

## Theophile

Okay, using the above posted grub.conf, attempting to boot into Windows gives this:

```
Booting command-list

root (hd1,0)

  Filesystem type unknown, partition type 0x83

map (hd1) (hd0)

map (hd0) (hd1)

makeactive

chainloader +1 

Error 13: Invalid or unsupported executable format

Press any key to continue..._
```

If I change the first line to "rootnoverify", the error is nearly identical:

```
Booting command-list

rootnoverify (hd1,0)

map (hd1) (hd0)

map (hd0) (hd1)

makeactive

chainloader +1 

Error 13: Invalid or unsupported executable format

Press any key to continue..._
```

Could it be due to the partition being formatted with NTFS? Is Grub unable to read NTFS?

When booted into Linux, the partition is clearly shown as being NTFS and it is formatted this way. But why does the error say partition type 0x83? That's ext2, no?

Thanks all for the help!

----------

## jburns

What is after the chainloader +1 line?  If it is followed by anything other than a title or end of file the additional lines could be generating the error.  You could add a line containing "boot" after the "chainloader +1" line.

----------

## Theophile

Here is the grub.conf file in its entirety:

```
Farmer iso # cat /boot/grub/grub.conf

default 0

timeout 15

title=Gentoo

root (hd0,1)

kernel /boot/vmlinuz root=/dev/hda2

#title=Windows XP 

#rootnoverify=(hd1,0)

#makeactive

#chainloader +1

title Microsoft Windows XP Pro

root (hd1,0)

map (hd1) (hd0)

map (hd0) (hd1)

makeactive

chainloader +1 
```

----------

## Theophile

Any ideas here? Really would like to get this working.

----------

## jburns

 *bunder wrote:*   

> make the windows drive the primary master.
> 
> make a /boot partition on the linux drive... mount up, make sure that the kernel is there.
> 
> unmerge grub, clean out /boot/grub, re-emerge grub.
> ...

 

If the BIOS is set up to boot from the windows drive which then loads grub from the linux disk, then I think the problem may be that the grub disk order does not match the BIOS disk order.  The grub disk order can be changed by changeing the device map in /boot/grub/device.map.  (hd0) be the windows disk and (hd1) should be the linux disk.

/boot/grub/device.map

```
(hd0)   /dev/hdb

(hd1)   /dev/hda

```

The /boot/grub/grub.conf file should be

```
default 0

timeout 15

title=Gentoo

root (hd1,1)

kernel /boot/vmlinuz root=/dev/hda2

title=Windows XP

rootnoverify (hd0,0)

makeactive

chainloader +1

```

I find the case where the mbr on one disk points to grub on the other disk confusing but I think that this may work.

----------

## Theophile

The BIOS loads GRUB off the Linux disk. Actually, it's supposed to. I have a Dell Dimension 4600 and it's acting up. I have to hit F12 at boot to get the boot menu and manually tell it to boot from the primary master drive, otherwise it hangs.

But if it were working right, it would load GRUB from the Linux disk, which is primary master. The XP volume is primary slave.

----------

## Theophile

Any thoughts? Is it an NTFS thing? Can GRUB read NTFS?

----------

## Veldrin

 *Quote:*   

> Any thoughts? Is it an NTFS thing? Can GRUB read NTFS?

  Grub does not really need to read an ntfs partition. I just shows the bootstrap process (not to confuse with a gentoo boostrap command during installation), where to go next. Bootstraps starts reading from the designated partition, and find the ntloader, which eventually boot windows.

The only part, where grub need to read a partition, is to get it's own config from withing boot.

cheers

V.

----------

## Theophile

Okay, then I'm stumped. I can boot the XP partition just fine by using my BIOS's boot loader, but not from GRUB. There must be something wrong in the configuration.

----------

## lyallp

I have had XP booting from a slave for, oh, ages.

My Primary Windows partition is NTFS, I have other partitions which are FAT32, so I can write in both Windows and Linux.

My GRUB conf /boot/grub/grub.conf is as follows :-

```

#

# Sample boot menu configuration file

#

# Boot automatically after 10 secs.

timeout 10

# By default, boot the first entry.

default 0

# Fallback to the second entry

fallback 1

# Display initial image

#splashimage=(hd0,0)/grub/splash.xpm.gz

# For booting Windows NT or Windows95

title Windows XP

map (hd0) (hd1)

map (hd1) (hd0)

rootnoverify (hd1,0)

makeactive

chainloader  +1

# For loading DOS if Windows NT is installed

# chainload /bootsect.dos

title  Gentoo Linux (vga=306)

root (hd0,0)

kernel /vmlinuz root=/dev/hda5 vga=306

title  Gentoo Linux (vga=306) - previous

root (hd0,0)

kernel /vmlinuz.old root=/dev/hda5 vga=306

#title  Gentoo Linux 2.6.8-r2 (Testing video=vesafb:ywrap,mtrr,1024x768@80 acpi=on)

#root (hd0,0)

#kernel /vmlinuz-2.6.8-gentoo-r2 root=/dev/hda5 video=vesafb:ywrap,mtrr,1024x768@80 acpi=on

# For installing GRUB into the hard disk

title Install GRUB into the hard disk

root    (hd0,0)

setup   (hd0)

# Change the colors.

#title Change the colors

#color light-green/brown blink-red/blue

```

To give you an idea of how my partitions/disks are laid out, here is a snippet of my /etc/fstab

```

# Device specific mounts rather than LABEL specific

#/dev/hda1      /boot      xfs      defaults,noatime   1 1

#/dev/hda5      /      xfs      defaults,noatime   1 2

#/dev/hda7      /usr      xfs      defaults,noatime   1 3

#/dev/hda8      /var      xfs      defaults,noatime   1 4

#/dev/hda9      /home      xfs      defaults,noatime   1 5

#/dev/hda10      /tmp      xfs      defaults,noatime   1 6

#/dev/hda11      /usr/local   xfs      defaults,noatime   1 7

#/dev/hda12      /opt      xfs      defaults,noatime   1 8

#/dev/hda14       /portage   xfs      defaults,noatime   1 9

# <fs>             <mountpoint>       <type>  <opts>            <dump/pass>

LABEL=boot      /boot         xfs   defaults,noatime   1 1

LABEL=root      /         xfs   defaults,noatime   1 2

/dev/hda6      none         swap   sw         0 0

LABEL=usr      /usr         xfs   defaults,noatime   1 3

LABEL=var      /var         xfs   defaults,noatime   1 4

LABEL=home      /home         xfs   defaults,noatime   1 5

LABEL=tmp      /tmp         xfs   defaults,noatime   1 6

LABEL=usr/local      /usr/local      xfs   defaults,noatime   1 7

LABEL=opt      /opt         xfs   defaults,noatime   1 8

LABEL=portage      /portage      xfs   defaults,noatime   1 9

/dev/cdrom      /mnt/cdrom      auto   noauto,ro,user,gid=cdrom 0 0

/dev/hdd1       /mnt/win_1      vfat   defaults,gid=vfat,umask=0,umask=007,quiet   0 0

/dev/hda13       /mnt/win_2      vfat   defaults,gid=vfat,umask=0,umask=007,quiet   0 0

/dev/hdb1       /mnt/win_3      ntfs   defaults,gid=ntfs,umask=0,umask=007,nls=utf8   0 0   ## Windows system disk!

/dev/hdb5       /mnt/win_4      ntfs   defaults,gid=ntfs,umask=0,umask=007,nls=utf8   0 0

```

----------

