Restore/Re-install grub in Elementary/Ubuntu [Luna/12.04]


There are some cases, where we play with the system and suddenly realizes that we messed up some thing. This post is about grub in Elementary Luna based on Ubuntu 12.04. So the process is the same for both. Lets a take a simple scenario that you have messed up your grub and now when you boot your system you see this error:

error: no file found: …
grub rescue>

This can be different, like: error: no device found. So now the questions is how to restore it. Well, this is simple. Yes, i know there are many tuts and threads about this issue over the net, but i did not find most of them very easy to follow OR is confusing. I will follow the easy way. So lets begin, shall we?.

Boot your system from Live CD of Elementary/Ubuntu. Open terminal and type:

sudo fdisk -l

Sample output:

Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x4f431832

Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048    83970047    41984000    7  HPFS/NTFS/exFAT
/dev/sda2        83970048    84174847      102400    7  HPFS/NTFS/exFAT
/dev/sda3   *    84174848   190670847    53248000   83  Linux
/dev/sda4       190672894   976773119   393050113    5  Extended
/dev/sda5       190672896   317648895    63488000    7  HPFS/NTFS/exFAT
/dev/sda6       317650944   968376319   325362688   83  Linux
/dev/sda7       968378368   976773119     4197376   82  Linux swap / Solaris

From the above command, note the partition where your OS is installed. Now lets create a directory to mount the root partition in it.

sudo mkdir /media/sda3

You can create this directory anywhere you want, like in your home directory etc. sda3 is the partition where your system is installed. Not necessary, you use sda3, can be any named directory, like /media/temp etc. Now lets mount the partition in the directory we created:

sudo mount /dev/sda3 /media/sda3

After mounting, we will install the grub by running this command:

sudo grub-install --root-directory=/media/sda3 /dev/sda

The /dev/sda  is your hard disk name, which is shown from the output of fdisk -l. And that’s it, grub is installed. Reboot and things will be normal this time.

If every thing is cool, skip the following lines. The following are just extra steps in case some one face it.

——————————————————————————————

If you see the following error after booting:

Error: unknown command ‘gfxmode’

No worries, in latest Ubuntu 12.04, grub relies on a function in linux script which is in /etc/grub.d/ProxifiedScripts. BTW, this error is not a show stopper, you can still boot to your OS. The best way to avoid is install grub-customizer and enable ‘script code’.

sudo add-apt-repository ppa:danielrichter2007/grub-customizer
sudo apt-get update
sudo apt-get install grub-customizer

Open grub customizer and tick the check box in front of ‘script code‘. And that will do it.

grub-customizer

——————————————————————————————

Good luck!

  • Hello!

    I installed the daily build from 7/29. The live CD booted fine, but after installing it, the machine would not boot after GRUB menu. It just shows lines of increasing numbers with long commands behind them. Do you know what the problem is?

    • Hi,
      There was a kernel panic issue from the latest updates of kernel on 12.04, not sure if it is the case for this build[Ubuntu devs said, a patch will be soon pushed]. Would suggest to download an earlier build than 7/29 and try it. After successful installation you can update to latest packages.

  • Wouter

    Thanks a lot! Really helped me out!

  • Passerby

    I know this is an old post, but I want to express my thanks to you. I was having trouble with grub for 3 days. I have been installing windows and elementary os for at least 5 times each. My problem is that the grub screen for some reason doesn’t show when boot, so I can’t choose which os I want to boot(I want to dual boot). This fix my problem so beautifully that I want to cry. Now I can see grub screen. Thank you. Thank you so much.

    • Glad to hear, it worked for you.

  • Kuzirashi

    I’ve installed elementary OS and, after reboot, Windows 7 was starting and there wasn’t any menu to choose OS but you have provided great fix. Thanks a lot!

  • Kevin Alvarado

    how I can know which is the system partition? In system i have sda1 dell utility, sda2 and sda3 HPFS/ NTFS/ exFAT, sda 4 extend, sda5 unknown

    • If i get you right you want to know on which partition Linux(root) is installed, try this in terminal:
      df -k /
      Good luck.

  • Guigdeb

    Thanks a Lot

  • John

    Thanks a lot man. I Had same prob as Kuzirashi.

  • Frank

    Thank you so much!!!!!!!!! I had big problems with booting elementary os after moving / resizing partitions after cloning my disk to a bigger one, Windows ran elementary did not. Editing/changing grub.cfg out of a puppy live did not help for all kernels (change UUID to /dev/sda6), now, with the help of your tool, by copying the NEW UUID (which was not generated for the 74 kernel) from the old kernel entry to the new 74 and changing …72 to …74 EVERYTHING IS FINE AGAIN!!!! Thank you so much!!!!!!!!!!!!!! I was close to a new install, thank you!!!!!!!!!!

Search

Articles

What's Hot

Recent Comments