grub2 - Stuck in grub rescue after Windows install

  • Kevin Dolan

    I used to have a dual boot between Ubuntu (lucid) and Windows 7, but wanted to upgrade my Windows to 64 bit, so I installed the new Windows, which naturally wrote over the MBR, and so I attempted to repair it using the following guide:

    I had a lot of trouble following it, but managed to get the system to boot to some grub command line, instead of Windows, which I thought was useful. Then I did something screwy and now when I boot I get a grub rescue command line.

    So I follow the instructions on that same page related to rescue mode, but am a bit confused. If I do ls, I get:

    (hd0) (hd0,msdos1) (hd1) (hd1,msdos5) (hd1,msdos1)

    If I attempt to list the contents of these partitions, the only one that works is (hd1,msdos1), all of the others say "unknown filesystem." Examining the contents of this partition, it appears to contain my Ubuntu home directory.

    In any case, I found some combination of commands that do something:

    set prefix=(hd1,msdos1)/boot/grub
    set root=(hd1,msdos1)
    insmod /boot/grub/linux.mod
    linux /vmlinuz root=/dev/sdb1 ro
    initrd /initrd.img

    It then looks like it's going to work, but I find myself in some kind of prompt which calls itself busybox initramfs. I try various things, but can't figure out how to run the command update-grub as recommended.

  • Answers
  • Joni Nevalainen

    This is a quick and simple method of restoring a broken system's GRUB 2 files. The terminal is used for entering commands and the user must know the device name/partition of the installed system (sda1, sdb5, etc). The problem partition is located and mounted from the LiveCD. The files are then copied from the LiveCD libraries to the proper locations and MBR. It requires the least steps and fewer command line entries than the following methods.

    1. Boot to the LiveCD Desktop (Ubuntu 9.10 or later).
    2. Open a terminal by selecting Applications, Accessories, Terminal from the menu bar.
    3. Determine the partition with the Ubuntu installation. The fdisk option "-l" is a lowercase "L".

    sudo fdisk -l

    If the user isn't sure of the partition, look for one of the appropriate size or formatting.

    Running sudo blkid may provide more information to help locate the proper partition, especially if the partitions are labeled. The device/drive is designated by sdX, with X being the device designation. sda is the first device, sdb is the second, etc. For most users the MBR will be installed to sda, the first drive on their system. The partition is designated by the Y. The first partition is 1, the second is 2. Note the devices and partitions are counted differently.

    1. Mount the partition containing the Ubuntu installation.

    sudo mount /dev/sdXY /mnt

    Example: sudo mount /dev/sda1 Note: If the user has a separate /boot partition, this must be mounted to /mnt/boot

    1. Run the grub-install command as described below. This will reinstall the GRUB 2 files on the mounted partition to the proper location and to the MBR of the designated device.

    sudo grub-install --root-directory=/mnt/ /dev/sdX

    Example: sudo grub-install --root-directory=/mnt/ /dev/sda 6. Reboot 7. Refresh the GRUB 2 menu with sudo update-grub


  • Related Question

    boot - Grub rescue - error: unknown filesystem
  • user53817

    I have a multiboot system set up. The system has three drives. Multiboot is configured with Windows XP, Windows 7, and Ubuntu - all on the first drive. I had a lot of unpartitioned space left on the drive and was reserving it for adding other OSes and for storing files there in the future.

    One day I went ahead and downloaded Partition Wizard and created a logical NTFS partition from within Windows 7, still some unpartitioned space left over. Everything worked fine, until I rebooted the computer a few days later.

    Now I'm getting:
    error: unknown filesystem.
    grub rescue>

    First of all I was surprised not to find any kind of help command, by trying:
    help, ?, man, --help, -h, bash, cmd, etc.

    Now I'm stuck with non-bootable system. I have started researching the issue and finding that people usually recommend to boot to a Live CD and fix the issue from there. Is there a way to fix this issue from within grub rescue without the need for Live CD?


    By following the steps from persist commands typed to grub rescue, I was able to boot to initramfs prompt. But not anywhere further than that.

    So far from reading the manual on grub rescue, I was able to see my drives and partitions using ls command. For the first hard drive I see the following:
    (hd0) (hd0,msdos6) (hd0,msdos5) (hd0,msdos2) (hd0,msdos1)

    I now know that (hd0,msdos6) contains Linux on it, since ls (hd0,msdos6)/ lists directories. Others will give "error: unknown filesystem."

    UPDATE 2

    After the following commands I am now getting to the boot menu and can boot into Windows 7 and Ubuntu, but upon reboot I have to repeat these steps.

    ls (hd0,msdos6)/
    set root=(hd0,msdos6)
    ls /
    set prefix=(hd0,msdos6)/boot/grub
    insmod /boot/grub/linux.mod

    UPDATE 3

    Thanks Shashank Singh, with your instructions I have simplified my steps to the following. I have learned from you that I can replace msdos6 with just a 6 and that I can just do insmod normal instead of insmod /boot/grub/linux.mod. Now I just need to figure out how to save this settings from within grub itself, without booting into any OS.

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

    UPDATE 4

    Well, it seems like it is a requirement to boot into Linux. After booting into Ubuntu I have performed the following steps described in the manual:

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

    This did not resolve the issue. I still get the grub rescue prompt. What do I need to do to permanently fix it?

    I have also learned that drive numbers as in hd0 need to be translated to drive letters as in /dev/sda for some commands. hd1 would be sdb, hd2 would be sdc, and so on. Partitions listed in grub as (hd0,msdos6) would be translated to /dev/sda6.

    UPDATE 5

    I could not figure out why the following did not fix grub:

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

    So I downloaded boot-repair based on an answer from post. That seemed to do the trick after I picked the "Recommended Repair (repairs most frequent problems)" option.

  • Related Answers
  • user53817

    I could not figure out why the following did not fix grub:

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

    So I downloaded boot-repair based on an answer from persist commands typed to grub rescue post. That seemed to do the trick after I picked the "Recommended Repair (repairs most frequent problems)" option.

    I have also used Grub Customizer to customize the order of boot entries.

  • Shashank Singh

    1. set prefix=(hdX,Y)/boot/grub Use the values determined earlier. Example: If the Ubuntu system is on sda5, enter: set prefix=(hd0,5)/boot/grub 2.* set root=(hdX,Y) Example: set root=(hd0,5) 3. insmod normal Attempt to load the normal module. 4. normal

    I have never tried a grub rescue, but since I have read about it, just curious. what did you get when you tried set root=(hd0,6)/boot/grub and the following insmod normal?

    We basically need grub to know where the /boot/grub folder is. If this is not working, I guess doing a grub install from a boot cd is a good option

    Glad it worked for you. I came to know about the Boot-repair disk from this. May come handy. However, the grub-install should have worked. Did the terminal say anything particular after that command?

  • Nil

    There is an alternative cause of this problem. In this particular case, grub was somehow corrupted and needed to be repaired or reinstalled. However, as shown on this thread, it's also possible that the root partition on which grub is installed could be corrupted. To fix this:

    This is a possible solution, but it should not be used likely lest your root partition become further corrupted. Running the command: fsck -t ext4 /dev/sda1 This program attempts to search and repair errors on a corrupted filesystem. Replaced sda1 with your actual root partition. Replace ext4 with the actual filesystem, you have to know the file system or else the partition will be more corrupted. See this thread for more information.

    Even though this question has an answer, there is an alternative way to fix the problem that worked for me. The steps are explained in this painful video: . In short, it will reinstall Grub2 altogether instead of repairing it.

    Because this video is so painful to watch, I'll list the steps below (as I should regardless of how painful it is to watch the video)

    1. Launch a live session of Ubuntu. The video uses a live CD where as I used a live-usb. I made sure that the live-usb has the same version of Ubuntu that I had on my harddrive.
    2. Find where your root partition was mounted. In the video, the user uses nautilus to navigate through each drive that was mounted. It was mounted with a long string of numbers and characters. If this is the case, follow the following steps to remount the partition. Else, procede to step 5.
    3. Bring up the terminal with ctrl+alt+T and use the mount command to find the name of the partition.
    4. Mount the partition. Create a new folder in your media folder. sudo mkdir /media/ubuntu. Then simple mount your partition to that folder. sudo mount /dev/sdxx /media/ubuntu where xx of sdxx is determined in step 3.
    5. Bind the following directories from the root directory of your live cd/usb to that of your root directory on your version of Ubuntu. The directories are the dev proc and sys. Do so with the following commands:

      sudo mount --bind /dev /media/ubuntu/dev
      sudo mount --bind /sys /media/ubuntu/sys
      sudo mount --bind /proc /media/ubuntu/proc
    6. Change the root directory to the one on your ubuntu partition. sudo chroot /media/ubuntu/

    7. Having done the above, installing Grub2 again will install it to the root directory of your distribution of ubuntu and not that of the live cd/usb's. So go ahead and run sudo grub-install /dev/sdx

    And that's how to fix grub using a live-cd/usb. This method was developed by youtube user crazytechzone.

  • Braiam

    Funny, I also had the same problem an hour ago!

    Anyway, this is what I did.

    1. Load ubuntu:

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

      since your ubuntu is installed in 6 right?

    2. run terminal:

      sudo -i *to access root*
      grub-install --root-directory=/mnt/ /dev/sda
      sudo update-grub
      sudo grub-install /dev/sda