6

I have a desktop with two SATA hard drives installed. On one I have Windows, on the other I have Ubuntu 12.04. Everything works fine. Now, I want to install one more hard drive. This is an IDE drive. After installing the IDE drive, Grub no longer points to the correct hard drive and doesn't find the boot directory, so I end up in grub rescue. In my grub.cfg the Ubuntu installation is on hd1. It seems that the new IDE drive becomes hd0. Does that mean that my Ubuntu (and the boot directory) now is on hd2 (and Windows on hd1)? If so, how can I change this in Grub so that it points to the correct hard drive? Can it be done from the grub rescue prompt? Can I boot without the IDE drive installed, edit grub.cfg, torn off the computer, connect the IDE drive and boot? If I go wrong here, can I edit grub.cfg from a live CD? Or is there a better way to do this?

Bambino
  • 137
  • 1
  • 2
  • 11

4 Answers4

7

Grub command line have some commands that will help you to debug this issue. Check for the list of them here: https://www.gnu.org/software/grub/manual/grub/html_node/Command_002dline-commands.html
In your case you must identify the drive and the partition where your Grub files are located. Try ls command. Bear in mind that partition naming convention is different in Grub. For example, 2nd partition of the 1st drive will be called (hd0,1) (drives and partitions are counted starting from zero). Check "Device syntax" section in the help for ls command using the mentioned link.
As soon as you'll know exactly where /boot/grub folder is located, you can try to boot your system using the next commands (I'm using the previous example with Drive 1, Partition 2 - change them appropriately):

grub> set root=(hd0,1)
grub> set prefix=(hd0,1)/boot/grub
grub> insmod normal
grub> normal

Now your system should boot normally. Log in and restore your boot loader from the terminal:

sudo update-grub
sudo grub-install /dev/sda

(use appropriate /dev/sdX name for the drive, where your GNU/Linux installation is located).

whtyger
  • 5,810
  • 3
  • 33
  • 46
  • Thanks a lot! I was able to boot normally, using the grub rescue commands you suggested. I then ran the last two commands in terminal, but that didn't do much (I used sdb). I must have chosen the wrong drive in the last command. The IDE drive is sdc1. The Ubuntu drive is sdb5. The Windows drive is sda2. Should I use sudo grub-install /dev/sdb , sudo grub-install sdb5 , or something else? Sorry for not using quotes, but I haven't figured out how yet. – Bambino Jul 19 '13 at 14:57
  • Drives are named sda, sdb, sdc; partitions are named sda2, sdb5, sdc1 - do not mix them. I suppose that your boot loader was installed in MBR (this behavior is default), in that case you should use drive name, not partition name. And the command will be sudo grub-install /dev/sdb. – whtyger Jul 19 '13 at 15:35
  • Thanks. That's what I tried, but when I reboot I get back to the grub rescue prompt again. Grub-install reported: Installation finished. No error reported. I also tried to run grub-update again after grub-install, with the same result. – Bambino Jul 19 '13 at 16:11
  • It is possible, that when your Ubuntu was installed, it placed its boot loader on the first disk, where Windows was located. Take a look: http://superuser.com/questions/107235/how-do-boot-sectors-and-multiple-drives-works. In that case grub must be restored on /dev/sda. But I'd made a backup of the first disk before doing so. Just in case. – whtyger Jul 19 '13 at 17:06
  • So I tried sudo grub-install /dev/sda and sudo update-grub after that, and that did the trick! Now everything is back to working normally again. Thanks a lot for very precise and easy to understand help. The thread can be marked as solved. – Bambino Jul 19 '13 at 17:28
  • From the "e" edit mode, I found that grub is looking on the wrong disk (hd0,5 instead of hd1,5). However, the 4 grub commands above with hd1,5 just duplicate the existing grub menu entries, and it still looks on hd0,5. After doing this a few times, now I have 4x the same menu entries. – donquixote Jun 11 '15 at 19:24
  • @donquihote OP was talking about grub rescue prompt, when your system is broken and you even cannot reach grub OS selector. You shouldn't use these commands elsewhere, only use them when the computer isn't booting properly. – whtyger Jun 15 '15 at 07:30
  • Worked like a charm on Ubuntu 16.04 after a power cut - the problem was probably caused due to a recent change of hard disc. – Solomon Vimal Oct 08 '19 at 21:56
1

You must have an old, broken grub install on the IDE disk that is now being booted instead of the one on the original disk, which will still work fine if you tell your BIOS to boot from that drive instead of the IDE one.

The bios always assigns (hd0) to whichever drive it is trying to boot from since DOS/Windows can not boot from any other drive.

psusi
  • 37,551
  • Thanks. I already checked the boot order in BIOS and the IDE drive is not in the list. There isn't much I can do in BIOS to solve this. However, whtyger's solution works. – Bambino Jul 19 '13 at 14:40
  • About a broken Grub install, good hunch! There used to be one, but the drive is repartitioned and reformatted, so it should be gone. – Bambino Jul 19 '13 at 15:05
  • @Bambino, reformatting and repartitioning lead to the error you saw because the grub core is still on the disk, but it can't find the grub files in /boot ( since you blew them away ). – psusi Jul 19 '13 at 17:36
  • "The bios always assigns (hd0) to whichever drive it is trying to boot from" thanks, that helped me. I tried to boot from a secondary drive by pressing F8 during boot and selecting that one. Unfortunately grub looked for my encrypted LUKS partition on hd0 instead of the secondary drive. Changing the boot order and actually making it hd0 helped. – das Keks Sep 26 '20 at 11:22
0

I manage to solve the issue by changing boot flag on my partition it was pointing to wrong partition /dev/sda6 this happened after I remove Swap partition , and my partition table order changed so my boot partition become /dev/sda5 I use fdisk to fix this I type command as followed :-

fdisk /dev/sda
a
5
w

enter image description here

Salem F
  • 133
  • 8
0

I had the same issue and could not get it resolved using Grub-Rescue

Booting off the Ubuntu live media (DVD or USB) and installing the boot-repair-tool resolved it for me

How to install the Boot-Repair tool in an Ubuntu live disc?