Rebuilding Grub2 grub.cfg from Ubuntu Live CD

After installing Windows 7 the other day I lost my Grub install. Not a problem, in the past I’ve used my Super Grub Disc to repair it.

This didn’t work for me though (may be my disc is a bit dated, or maybe it doesn’t support grub 2 just yet). Instead I booted up using my Ubuntu 9.10 Live CD. I could easily re-install grub using the “grub-install” command.

  1. Open up a terminal
  2. sudo apt-get install grub-pc (install grub2 incase the live version doesn’t have it)
  3. sudo fdisk -l (Find the partition you want)
  4. sudo mount /dev/sda5 /mnt (Mount the partition)
  5. sudo grub-install --root-directory=/mnt /dev/sda

I’ve used the drive /dev/sda and partition /dev/sda5 in my example. Notice the exact spelling.

This all went ok, but I was left with a screwed up grub menu (I messed it up myself). There’s a “update-grub” command you can do from within Ubuntu, but I couldn’t actually boot in. I only had the Live CD. Hence updating it proved to be quite difficult, and there’s nothing on the Live CD to help. I eventually found a solution, these are the commands I had to run in order to regenerate it (you can copy and paste the whole lot to run them all at once).

sudo mkdir /mnt &&
sudo mount /dev/sda5 /mnt &&
sudo mount -o bind /dev /mnt/dev &&
sudo mount -o bind /proc /mnt/proc &&
sudo mount -o bind /sys /mnt/sys &&
sudo chroot /mnt bash &&
sudo update-grub &&
reboot;

Without binding the /dev and /proc it would throw an error.

All credit goes to seeker5528′s post for the above solution.

If you simply want to update grub2, and you are able to boot into linux, then you can run the command:

sudo update-grub

It will rebuild your grub config, finding all the available bootable partitions.

Related Posts

  • midnightcarousel

    Thank you so much. I had this exact same problem and your tips worked. I was pretty scared there for a minute (thank god for google :)

    I will now learn more about the mount command and the -o bind option…

  • Ravi Gehlot

    Thanks to this post, I was able to get my distro back to booting! Thanks!

  • tooman

    thx for tutorial, very helping me :)

  • http://www.facebook.com/people/Barry-Van-Tassell/656798336 Barry Van Tassell

    You saved my box. Thank you.

  • http://blog.omega-prime.co.uk Max

    I tried this and got an error like “Cannot find list of partitions”. Based on http://www.linuxquestions.org/questions/linux-general-1/altered-partition-table-grub2-will-not-load-how-to-chroot-699424/, I fixed it by doing this additional bind operation:

    mount -o bind /sys /mnt/sys

    After this update-grub worked perfectly.

    • http://robertbeal.com Rob

      Had to google my own post as I ran into this problem again, and I need the line you mention. Added it to the article, thanks!

  • Arpit

    sorry these commands doesn’t work accurately.
    after reboot no grub list appear , it directly takes to me grub promt.
    when i search for menu.lst or grub.cnf file in grub promt it displays file not file.

    • http://robertbeal.com Rob

      Hmm, that is odd. What distro are you running? Ubuntu? And also what version?

  • http://tuxnetworks.blogspot.com/ Brettg

    HI Robert, I found your post on google but the result that was returned was strange to say the least.

    I don’t want to put the exact phrase in but suffice to say that the title of your page in the google results list was like this:

    Buy A Prescription Drug | Robert Beal

    Along with that the text snippet that was displayed was text from your site interspersed with the name of the drug they are flogging.

    I come to your page and there is no sign of the stuff that shows up in the google results.

    The search I did was “rebuild grub” and the result was third in the list.

    If you look at the google cached version of your page it is littered with references to the drug.

    http://webcache.googleusercontent.com/search?q=cache:2RQSdoU4JSEJ:www.robertbeal.com/562/rebuilding-grub2-grub-cfg-from-ubuntu-live-cd+&cd=3&hl=en&ct=clnk&client=ubuntu

    Somehow your google results have been poisoned, but I don’t know how.

    Thought you might like to know

    brettg-AT-tuxnetworks_DOT_com
     

    • http://robertbeal.com Rob

      Thanks for the heads up. Had actually spotted it the other day when I noticed my traffic dipping. It’s the infamous Pharm Hack that has hit many WordPress sites. I think I’ve cleared it out now, am just waiting for Google to re-index my site.

  • http://neoretro.net Daryl Tucker

    Binding your /sys environment will also help in situations where you’re trying to load many different OS’s (especially Windows)

    sudo mount -o bind /sys /mnt/sys

  • Sazzad

    ubuntu@ubuntu:~$ sudo update-grub
    /usr/sbin/grub-probe: error: cannot find a device for / (is /dev mounted?).
    ubuntu@ubuntu:~$

    what can I do. am usine Ubuntu 11.10 x86 Live CD

    • http://robertbeal.com Rob

      Did you definitely mount “dev”? ie the line:
      sudo mount -o bind /dev /mnt/dev

  • Max

    Thank you a lot for this tip. It was just exactly what I needed to restore my Ubuntu back. 

  • Zarinfam S

    Thank you. You helped me when i was in bad situation !

  • Pingback: How to update-grub in case you did mistake on your grub? « Hyon Lim

  • Robert Vila

    What does “I lost my Grub install.” mean??
    If I grub-install, as you explain, in /dev/sda will I ruin my system if I have refit to choose between macOS and Linux, and then use grub2? Or that instruction affects only the given partition. It is not clear, so I am afraid to ruin all.

    • http://robertbeal.com Rob

      Hi, when I say “lost my Grub install” what happened was Grub had been removed from the Master Boot Record (MBR) and overwritten with Windows own bootloader. So I could only boot Windows.

      Hmmm, I don’t use OSX so can’t really say with any certainty if it would work. There are articles on booting OSX with Grub2, so you could have just the one bootloader. I’m willing to bet, knowing Apple, that it’s much happier using its own bootloader.