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 -lThis 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/procThe following command is optional (it copies resolv.conf)
$sudo cp /etc/resolv.conf /mnt/etc/resolv.confNow chroot into the enviroment we made :
sudo chroot /mntAfter 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/grubPlay 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/sdacommand.However you may get errors with that code like me.If so please use this command :
#grub-install --recheck /dev/sdaNow 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:
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 :)
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 :)
Sure thing, and thank you for sharing!
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.
very nice, thank you very much!
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
Thank you so much!
Alex.
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
Thanks so much for this info!
I'm getting this when I boot:
error: no such device: d4e47e4ce47e313a
Failed to boot default entries
:/
@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 :)
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.
YOU'RE A FUCKING GODDDDDDDDDDDDDDDD
IT REALLY WORKS.
THANK YOU, REALLY THANK YOU VERY MUCH
Thanks man! You've saved me countless hours!
Saved. My. Day.
As everyone is saying... "Thank You, Thank You, Thank You"!!!
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!
Thanks!
btw it's 'update-grub' not 'grub-update'
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.
I can't execute grub-install /dev/sda. There is no such command. My /usr is located on different partition. What should I do?
@Pavel, Bulgaria
Man, you are genious.
Thank you very much.
It's working. I can not believe, but it's realy working
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...
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?
how about using dd to recover the first 446 bytes of MBR?
Simply put.. Genius !!
Thank you so much !
Fantastic. Done with no errors.
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...
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
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.
Thanks man, you saved my day as well!
I guess my grub2 doesn't like Win98...
its working, thanks you very much
Thanks! You saved my day.
thanks a gzallion!
thanx, it worked, i'll print your article & put it in a safe place, thank you again ;-)
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.
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
this only made the windows partition bootable, cant see ubuntu :(
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
Man what can i say :
THAAAAAAAAAAAAANKS you resolved abig problem in my pc
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.
It works, thanks so much!
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.)
Awesome! This saved my bacon!
Thank you!! This worked beautifully on my dual-boot netbook running Windows 7 and Ubuntu 10.04!
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.
Yeah, tried your method. I encountered some problems, but all of them were overcame. Thanks.
After few days system is up again!
There is a short method to do it.
http://h0w-t0.blogspot.com/2010/08/how-to-reinstall-grub2-after-installing.html
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