Reinstall Ubuntu Grub Bootloader After Windows Wipes it Out
If you run a dual-boot system with Linux and Windows, this has happened to you. You had to do your monthly reinstall of Windows, and now you don't see the linux bootloader anymore, so you can't boot into Ubuntu or whatever flavor of linux you prefer.
Here's the quick and easy way to re-enable Grub.
1) Boot off the LiveCD
2) Open a Terminal and type in the following commands, noting that the first command will put you into the grub "prompt", and the next 3 commands will be executed there. Also note that hd0,0 implies the first hard drive and the first partition on that drive, which is where you probably installed grub to during installation. If not, then adjust accordingly.
sudo grub
> root (hd0,0)
> setup (hd0)
> exit
Reboot (removing the livecd), and your boot menu should be back.
Only read below if Windows is now missing from the boot menu
If you installed Ubuntu before you installed Windows, then Ubuntu will not have anything in the grub configuration for Windows. This is where you'll have to do a bit of manual editing to the grub boot menu file.
If you open the file /boot/grub/menu.lst with the following command:
sudo gedit /boot/grub/menu.lst
You'll see a sample section for Windows, which you'll want to uncomment and add to the boot menu list in whatever position you want it in. (uncomment by removing the #'s)
# title Windows 95/98/NT/2000
# root (hd0,0)
# makeactive
# chainloader +1
Note that you should also verify that hd0,0 is the correct location for Windows. If you had installed Windows on the 4th partition on the drive, then you should change it to (hd0,3)


Well, it didn't work for me, I mounted /boot to separate partition (hd0, 4) and grub failed to find the stage1 files..
I've to run windows repair to rewrite the boot sector in MBR.
Thanks for this solution, however it did not help my situation as windows was kind enough to rewrite the mbr on my laptop when it went into hibernate. This laptop does not have a working cd drive, thus is unable boot from a livecd.
Another solution I found is to use ntldr and load a version of grub from there (grub4dos). I think it would be a good idea to provide instructions for people on how to achieve this using ntldr and grldr.
The only caveat with having a setup like this is that you will need to copy menu.lst that grub uses to the default windows partition everytime you perform an system update (otherwise it wont load the latest kernel).
I have setup my laptop to use this method. First I added the line:
C:\grldr="GRUB Bootloader" to windows's boot.ini
I copied the file grldr from grub4dos to C:\
Using ext2ifs on windows I copied the menu.lst from /boot/grub to C:\ on my windows install.
After rebooting, I had a working install of GRUB. This didn't require me to rewrite the mbr of my hard drive.
What you need to do before entering root (hd0,0) is the folowing:
find /boot/grub/stage1
This wil give you the root you have to use. In my case it wasn't hd0,0 but hd0,1.
Once I'd used "find /boot/grub/stage1″ on hd2, I found I had to change the original command as such:
sudo grub
> root (hd2,0)
> setup (hd0)
> quit
it works on mine
sudo grub
> root (hd0,2) # this is sort of related to your partition ubuntu installed
> setup (hd0)
> exit
It worked for me. The only thing I had to do different is that I had to type
quit
instead of exit. exit doesn't seem to be a known command.
I use a program called "Super Grub Boot Disk" that allows repair of both Windows and Grub boot loaders…google it, download it and burn it to cd…works great and has loads of optins for Windows or Linux…it'll be worth the effort,believe me….Proximo
I use a program called "Super Grub Boot Disk" that allows repair of both Windows and Grub boot loaders…google it, download it and burn it to cd…works great and has loads of options for Windows or Linux…it'll be worth the effort,believe me….Proximo
is there a way to do the opposite? Restore the windows boot loader? When I bought my computer I was only supplied with the factory restore disks. I tried the wubi installer but it booted to ubuntu grub then pressed enter to boot into windows xp…it brought up a windows boat loader with windows and ubuntu. I am also looking to fix my partition table, and increase ubuntu disk space also.
The first step should be find /boot/grub/stage2 and whatever it returns should be used instead (hd0,0) in your examples.
I'm passing back and forth between having ubuntu running and having Vista running. I used to have them both, though. After I re-installed Vista, it over-wrote my MBR. So I re-installed the grubloader (on hd0,0, my Vista partition…maybe that's the problem?) but now even though Vista is listed on the boot menu, when I hit enter to boot into it, it returns me to the boot menu.
Ok guys I have a question for you. I have tried a lot of stuff on this one. Im running 2 Hard drives on my computer. My main Harddrive has windows vista on it (120gb hard drive). My second hard drive (30gb) has my linux installed on it. I cant get grub to boot. when it does boot i get a boot error. error 17. I cant even get to my second harddrive at all. I want to be able to boot into either of them when i please. What can i do to fix this guys ?!?!?!?! Thanks in advan.
To use the Windows boot loader, you can do one of two things:
In Win98/Me, type from a command line: fdisk /mbr
In Win2000/XP, go to the Recovery Console and type: fixmbr
Hope this helps.
I think VISTA would prefer to do its own thing and lead you to believe you have allowed GRUB to manage a dual-boot scenario. I see many symptoms of sneaky virtualization. You might as well run VMware.
Thank you because of you my computer have been save..
Worked for me. I used the Fiesty LiveCD since that's what I had installed. I originally had Vista and put Fiesty on hd0,1. Then today I installed XP in the same partition as Vista and just had to run through the recommended directions with hd0,1 for the root line. At this point I can't boot to Vista but well, that's no real loss.
Thanks for the great guide. It really helped me.
I've got a case.My computer runs Windows XP, then I installed Ubuntu Fiesty 7.04. Two days ago, I ran Update Manager, it required restart, After restarting, I couldn't get into Ubuntu ( I remember I got error when updating). I reinstalled Ubuntu but it's stayed the same.
I guess the first time I installed Ubuntu, grub manager know where to boot Ubuntu. But in the second time, It can't find because root disk is mouted differently.
The problems are I can't boot Ubuntu, I can't reinstall Ubuntu again.
Do I need install Win again that means format my primary disk to remove grub manager?
Thanks,
PS: My English is not good
with the Live CD Ubuntu
sudo grub –batch
grub>
grub> find /boot/grub/stage1
grub> root (hd0,1)
grub> setup (hd0)
grub> quit
Thank you so much! This worked perfectly after I had tried about everything else recommend by many other sites that did not work! I had installed Vista first and then after installing Ubuntu 7.10 I was unable to see Vista listed after I rebooted.
Also, after I did the procedure above and was able to see Vista listed in the grub menu, I got an error message about the MBR and wasn't able to startup Vista. So, I booted from the Vista install DVD and, instead of choosing Install, I chose Repair. It found the Vista installation, recognized that it had a problem, and asked me if I wanted it to fix it. So, I of course said yes - repair it! It took less than a minute to fix. I rebooted, saw the grub menu, selected Vista, and it started up perfectly. I then restarted to make sure that I could still start up Ubuntu, and it worked perfectly as well!
Hope this might help someone else! The Vista Recovery is awesome compared to the old XP method!
Thanks for the great help!!!
Ok, so I had Vista installed on here once long ago, I have like 5 partitions on this workstation (hardware R5 4x 300gb) I want to nuke anything even related to vista, where to find? I see that vista stuff on the import settings menu, I imagine its causing some problems here. how can I kill the beast forever?
Thanks for the information.
I think "exit" should be "quit", at least in Ubuntu 6.04, but that's a minor detail
This page worked for me, but I had to first repair the partitions that Windows messed up on my MaxBlast altered hard drive. The only thing that could find my Linux partitions from my searches was Partition Table Doctor (ptdd.com). It cost me $50, but I was able to fix the partition table and MBR. Then I used this page (my partition was at hd0,2) to recreate the grub bootloader and VOILA! I am back to normal.
(Interestingly, MaxBlast, Acronis Disk Manager, and the Ultimate Boot CD could not properly read the partition table and did not work. I am especially disappointed in MaxBlast as it was the cause to begin with.)
Thank you so much. After Windows finally died completely forcing a re-install the last thing I had to worry about was how to get Ubuntu back. This worked flawlessy, though I had no idea where Linux was in the disk map before I started.
My solution was to boot the live CD then explore the local drives until I found it. Had a quick look at menu.lst and there was all the info I needed.
You saved my day
I suggest you add the following command into your procedure to insure the correct HD and partition is selected. e.g. my is on HD 0,5
find /boot/grub/stage1
Thus, making procedure
sudo grub
find /boot/grub/stage1
root (hd?,??)
setup (hd?)
quit
where hd?,?? is returned from find command.
hello friends. my ram is 256mb so i cant install ubuntu of latest version which is live cd. so i have go to the older version of ubuntu so i installed edubuntu in my computer which is not a live cd. due to some problems in my windows xp i had removed xp and reinstalled it in my computer by this my grub has lost. i want to log in into edubuntu so i should install grub. so please help me in installing grub through edubuntu.
or else i should completely remove the edubuntu and reinstall it again in my computer
thanks "Jim Murray" your explanation really help cheers
unfornately i have failed to boot OS (XP) on my laptop which came with pre-installed Windows xp. when i boot my laptop using Windows XP CD it copies the required files but when i press ENTER to install Windows XP the message appears that " Setup did not find any hard disk drives installed in your computer. Make sure any hard disk drives are powered on and properly connected to your computer and that any disk related hardware configuration is correct. This may involve running a manufacture supplied diagnostic or setup program.
Setup cannot continue. To quit setup, press F3." Please note I have C: drive installed windows xp on it, i have drive D: files are available for recovery disk pre-installed by the windows manufacturer. My laptop is HP dv5000. Please advise how to install boot laoder on this laptop.
with the Live CD Ubuntu
grub> find /boot/grub/stage1
(hd0,5)
grub> root (hd0,5)
grub> setup (hd0)
Checking if "/boot/grub/stage1″ exists… yes
Checking if "/boot/grub/stage2″ exists… yes
Checking if "/boot/grub/e2fs_stage1_5″ exists… yes
Running "embed /boot/grub/e2fs_stage1_5 (hd0)"… 17 sectors are embedded.
succeeded
Running "install /boot/grub/stage1 (hd0) (hd0)1+17 p (hd0,5)/boot/grub/stage2
/boot/grub/menu.lst"… failed
Error 22: No such partition