Pages

Monday, December 19, 2011

How to restore grub in Ubuntu 11.04

If we have a dual-boot computers, especially Windows and Linux, we often get grub bootloader strucked by Windows bootloader when we reinstall windows. To restore GRUB from Linux, especially Ubuntu 11.04(Natty Narwhal), we can do the following steps :
  1. Prepare Ubuntu 11.04 live CD or live usb
  2. Set first boot on BIOS, to CD or Flashdrive
  3. Wait until the screen Boot Ubuntu appear, choose Try Ubuntu
  4. Once inside the Ubuntu Desktop, open the Terminal or press the key combination Ctrl+Alt+F2 to run terminal
  5. Check your Linux partition
    sudo fdisk -l 
  6. Once you know the Linux root partition, for example as on my laptop there are 2 partitions sda6 mounted as / and sda7 mounted as /home, Then do the following scripting :
    sudo mount -t ext4 /dev/sda6 /mnt
    sudo mount -t proc proc /mnt/proc
    sudo mount -t sysfs sys /mnt/sys
    sudo mount -o bind /dev/ /mnt/dev
    sudo chroot /mnt/ /bin/bash
  7. Now we will restore GRUB to the MBR, here is the command :
    grub-install /dev/sda
  8. Then comes a message as below:
    Installation finished. No error reported.
    This is the contents of the device map /boot/grub/device.map.
    Check if this is correct or not. If any of the lines is incorrect,
    fix it and re-run the script `grub-install
    (hd0) /dev/sda
    (hd1) /dev/sdb
    
  9. Now we will install it into the Linux root partition, in this case my linux partition is on sda6, here is the command:
    grub-install /dev/sda6
  10. Then comes a message like this:
    grub-setup: warn: Attempting to install GRUB to a partition instead of the MBR. This is a BAD idea.
    grub-setup: warn: Embedding is not possible. GRUB can only be installed in this setup by using blocklists. However, blocklists are UNRELIABLE and its use is discouraged.
    Installation finished. No error reported.
    This is the contents of the device map /boot/grub/device.map.
    Check if this is correct or not. If any of the lines is incorrect,
    fix it and re-run the script `grub-install
    (hd0) /dev/sda
    (hd1) /dev/sdb
  11. Now we need to update grub by typing this command:
    update-grub
  12. The message below will appear:
    Generating grub.cfg …
    Found linux image: /boot/vmlinuz-2.6.31-14-generic
    Found initrd image: /boot/initrd.img-2.6.31-14-generic
    Found memtest86+ image: /boot/memtest86+.bin
    Found Microsoft Windows 7 Loader on /dev/sda1
    done
  13. Reboot your computer

No comments:

Post a Comment

Don't Forget To Join Our Community
×
Widget