rss
twitter
    Find out what I'm doing on Twitter

Howto Recover Grub2 After Windows Installation

Today i destroyed my Grub2 via installing windows on my notebook which i write blog posts.(I quit smoking , so i have to play some games : ) No rush). It may be hard to recover it since there are not much (i did not find anything) howtos around the net about recovering Grub2.Here is the step by step guide to recover it :

You will need a LIVE cd if you are going to recover an Ubuntu Box.Download Ubuntu Jaunty, Karmic whatever you want.Open the system with Live CD (I assume you are using Ubuntu Live CD).Press Alt+F2 and enter gnome-terminal command.And continue by entering :

$sudo fdisk -l


This will show your partition table.Here is my table to understand it better :

/dev/sda1 29 8369 66999082+ 83 Linux
/dev/sda2 * 8370 13995 45190845 7 HPFS/NTFS
/dev/sda3 13996 14593 4803435 5 Extended
/dev/sda5 13996 14593 4803403+ 82 Linux swap / Solaris

Now i will mount Linux (sda1 here), i have no external boot partition as you can see.(IF YOU HAVE external one, do not forget to mount it! )

$sudo mount /dev/sda1 /mnt
$sudo mount --bind /dev /mnt/dev
$sudo mount --bind /proc /mnt/proc

The following command is optional (it copies resolv.conf)

$sudo cp /etc/resolv.conf /mnt/etc/resolv.conf

Now chroot into the enviroment we made :

sudo chroot /mnt

After chrooting, you do not need to add sudo before your commands because from now, you will run commands as root.

You may want to edit /etc/default/grub file to fit your system (timeout options etc)

#nano -w /etc/default/grub

Play with the options if you want.(But do not forget to give grub-update command if you saved it ;) )

Now install/recover Grub2 via :

#grub-install /dev/sda

command.However you may get errors with that code like me.If so please use this command :

#grub-install --recheck /dev/sda

Now you can exit the chroot, umount the system and reboot your box :

#exit
$sudo umount /mnt/dev
$sudo umount /mnt/proc
$sudo umount /mnt
$sudo reboot

47 comments:

Anonymous said...

I have read your article, seems very straightforward. I have one question though, wouldn't it be easier, since you already use a live CD, to boot into desktop, open a terminal and then "sudo grub-install --recheck /dev/sda"? Because, as I understand, a Live CD session mounts all filesystems it finds automatically, so you don't have to bother mounting them manually. I haven't tried this, it's just a theory :)

Binbash said...

That will not work.You have to give that command in chrooted environment and that is what we are doing at this how to.

Please bookmark this article, or copy/paste it since you may need this and it was hard to find grub2 re-install articles when i destroyed mine :)

Anonymous said...

Sure thing, and thank you for sharing!

chris said...

beautiful. Thank you so much. I didn't realize I needed to bind /dev and /proc until I read your how to. I have my laptop back now.

Anonymous said...

very nice, thank you very much!

mewt said...

hi, will this procedure overwite the existing grub? I just recently installed openGEU and now I lost my grub2 and was replaced by the old grub. I want my grub2 back.

Thanks!
mewt

Anonymous said...

Thank you so much!

Alex.

Martin said...

I can't thank you enough. I have a dual boot system (Ubuntu 9.10 & Windows Vista). I restored my Ubuntu 9.10 partition using Clonezilla Live CD version 1.2.2-31 and upon reboot all I got was GRUB with a flashing cursor and nothing else. After scouring the web for the last 4 hours and trying numerous suggested fixes (none of which worked) I finally found your article which has worked perfectly without any problem. I am so relieved I finally have my system back.

Thank you, thank you, thank you!
Martin

Pothi said...

Thanks so much for this info!

Augusto said...

I'm getting this when I boot:

error: no such device: d4e47e4ce47e313a

Failed to boot default entries

:/

Anonymous said...

@Martin
I suppose the Clonezilla restore didn't work because I think it uses GRUB Legacy.

I am using Parted Magic and so far this is an excellent distro, but it also has GRUB Legacy, so I could not restore GRUB2 properly. I hope this blog post helps me :)

Anonymous said...

Thank you! Worked perfectly. XP was damn stubborn. It just doesn't play nice with others. :) Next time I'll have to put the windows on the machine first.

Anonymous said...

YOU'RE A FUCKING GODDDDDDDDDDDDDDDD

IT REALLY WORKS.

THANK YOU, REALLY THANK YOU VERY MUCH

Anonymous said...

Thanks man! You've saved me countless hours!

Anonymous said...

Saved. My. Day.

As everyone is saying... "Thank You, Thank You, Thank You"!!!

Anonymous said...

This works great, however for me it only works for the rest of the day. Then I have to reinstall grub the first time I turn on my computer the next day. Not sure what's wrong. Currently dual booting Ubuntu 9.10 with Windows 7 on separate but identical hard drives. Reinstalling Ubuntu will most likely solve my problem, but was wondering if there was a way of fixing things without having to start over!

Anonymous said...

Thanks!
btw it's 'update-grub' not 'grub-update'

tyler-harangozo said...

I followed a similar procedure (I kinda figured it out myself) before, and it always has worked fine for me WITHOUT binding the /dev and /proc. So as far as I can tell, these steps are not necessary. I suppose it could be useful, though... but Ubuntu Live should recognize your drives in the same manner as your Ubuntu install does. Anyway, this article can often be a great help! Thanks for posting.

Anonymous said...

I can't execute grub-install /dev/sda. There is no such command. My /usr is located on different partition. What should I do?

Anonymous said...

@Pavel, Bulgaria
Man, you are genious.
Thank you very much.
It's working. I can not believe, but it's realy working

Anonymous said...

I last commented here on January 15th saying that this only works for the rest of the day for me. Since then it only ever worked once at a time and I would have to do it again EVERY time I turn on my computer. Like I said before, Ubuntu and Windows are on different hard drives. Does it mean anything that my Windows hard drive is sda and my Ubuntu hard drive is sdb? When replacing every mention of sda here with sdb, grub says it is loading and then hangs infinitely. When replacing sda1 with sdb1 (my linux partition), but then executing grub-install /dev/sda it works. but like I said, only temporarily...

Anonymous said...

So when I run:
ubuntu@ubuntu:~$ sudo mount --bind /dev /mnt/dev
I get an error that says:
mount: mount point /mnt/dev does not exist

I'm too new to know if that means something I can fix?

Anonymous said...

how about using dd to recover the first 446 bytes of MBR?

Anonymous said...

Simply put.. Genius !!


Thank you so much !

Anonymous said...

Fantastic. Done with no errors.

vs4vijay said...

when i type...
grub-install /dev/sda
it says an error ...
"Probing devices to guess BIOS drives. This may take a long time.
/dev/sda8: Not found or not a block device."
what to do...
help me out...

Levi said...

I'm getting this error after grub-install /dev/sda:

/usr/sbin/grub-probe: error: cannot find a device for /boot/grub (is /dev mounted?).
No path or device is specified.
Try `/usr/sbin/grub-probe --help' for more information.
Auto-detection of a filesystem module failed.
Please specify the module with the option `--modules' explicitly.

I'm using Ubuntu 10.04 with Windows 7

Anonymous said...

that's probably because you mounted in mnt the wronc /dev/sdx. Make shure it's the good one with sudo fdisk -l. It should be the one where you have linux / installed.

Anonymous said...

Thanks man, you saved my day as well!
I guess my grub2 doesn't like Win98...

free cell phone said...

its working, thanks you very much

Anonymous said...

Thanks! You saved my day.

muchness said...

thanks a gzallion!

Mohammed Séddik said...

thanx, it worked, i'll print your article & put it in a safe place, thank you again ;-)

Anonymous said...

See also:
https://help.ubuntu.com/community/Grub2
At the bottom of the page there is a section called "Reinstalling GRUB 2" with three different methods.

KP said...

Just wanted to post and say thank you! This guide was of immense help to me this morning after screwing up my install last night. I hadn't seen your blog previously, but I'll be bookmarking it now.
Thanks again!
Ken

Anonymous said...

this only made the windows partition bootable, cant see ubuntu :(

Eddie said...

Not sure which versions had what options but the solution at
http://maketecheasier.com/restore-grub-2-as-the-main-bootloader/2010/05/05
seems easier and I've used it on Ubuntu 10.04 a couple times now.

Summary:
1. boot with live CD or USB
2. use gparted or palimpsest to determine root partition
3. sudo mount /dev/sda5 /mnt #substitute your root partition
4. sudo grub-install --root-directory=/mnt /dev/sda #substitute your disk (not partition)
5. reboot into Ubuntu
6. sudo update-grub
7. you're free to go break something else

abdel rahman said...

Man what can i say :

THAAAAAAAAAAAAANKS you resolved abig problem in my pc

vpxl said...

Thanks for the review. I am using Parted Magic and so far this is an excellent distro, but it also has GRUB Legacy, so I could not restore GRUB2 properly.

Anonymous said...

It works, thanks so much!

chiriones said...

This didn't work for me. I have XP on the entire hd0 drive and Ubuntu on the entire hd1 drive.

I think my problems started with having hd1 set to "OFF" in BIOS. XP still saw this drive somehow, but when I installed Ubuntu all I got was the grub rescue prompt saying that it couldn't find hd1. I updated the BIOS and set hd1 to "AUTO" in BIOS & went from there.

What worked for me was using the Ubuntu live CD to delete grub from /dev/sdb using "dd if=/dev/null of=/dev/sdb bs=446 count=1" and then install lilo in /dev/sdb1 where ubuntu root is. Then I used UBCD (the Ultimate Boot CD) to run SuperGrub and finally booted the Ubuntu partition on hd1. Then I installed GAG (the graphical bootloader) from UBCD as well. Why lilo you ask? Cuz I was getting grave warnings from Grub for trying to install it on /dev/sdb1 instead of /dev/sdb and GAG requires it on /dev/sdb1 (if that's where your linux root is.)

Per said...

Awesome! This saved my bacon!

Glenn O'Donnell said...

Thank you!! This worked beautifully on my dual-boot netbook running Windows 7 and Ubuntu 10.04!

growingneeds said...

Please consider this method of updating grub2:
Boot into Ubuntu 10.04 Live CD.
In terminal, key
"sudo fdisk -l" (Note the partition on which Linux resides)
"sudo mount /dev/sda1 /mnt"
"sudo grub-install --root-directory=/mnt/ /dev/sda"
"sudo reboot"
"sudo update-grub"

Credits to
http://mundogeek.net/archivos/2009/12/08/recuperar-grub-2/ for the enlightening post
http://www.webupd8.org/2009/12/how-to-recover-grub2-linux.html for the awesome translation.

Jony said...

Yeah, tried your method. I encountered some problems, but all of them were overcame. Thanks.

After few days system is up again!

Bhawana Subba said...

There is a short method to do it.
http://h0w-t0.blogspot.com/2010/08/how-to-reinstall-grub2-after-installing.html

Seb Smith said...

This saved my life! I'd been trying for a day to get it to work using other instructions without success, and yours just worked!

THANKS SO MUCH! :D

Post a Comment