error: no such partition. in GRUB

I was a bit of an idiot and wiped my old Ubuntu partition whilst in Windows XP, forgetting to fix the MBR. Rebooting gives:

error: no such partition.
grub rescue>

The only things I've entered that do anything are set, which gives:

prefix=(hd0,msdos5)/boot/grub
root=hd0,msdos5

and ls, which gives:

(hd0) (hd0,msdos2) (hd0,msdos1)

I have no CD drive so I can't boot from CD, but I should be able to boot from USB (haven't tested it as I need to go find one first). Is there anything I can do to fix it without external media, and if not how would I go about fixing it from USB?


Solution 1:

Try running these commands on the GRUB command line:

insmod part_msdos
insmod chain
set root=(hd0,msdos1)
chainloader (hd0,msdos1)+1

If that fails, try using msdos2 in place of msdos1.

If you get it to to boot that way, you'll have to do that every time until you replace that bootloader.

To fix it from a USB drive, you'd either need to use a Linux LiveUSB to reinstall GRUB (the easiest way being just to reinstall Linux, although it is possible just install a GRUB partition for bootloading), or copy a Windows XP install CD to a USB drive and make it bootable and use the Recovery Console in Windows Setup to replace the Windows bootloader.