Wednesday, April 20, 2011

GRUB bootloader


Don't bother people for help without first trying to solve the problem yourself. -- Colin Powell
Source (of most of info in this post): http://bytes.com/topic/unix/answers/800560-wheres-my-grub (Reply #2, #5, #7). Thanks 'micmast'.

If GRUB bootloader was overwritten with Windows bootloader when trying to repair some Windows OS, you may reinstall it without the need of reinstalling your linux distro from scratch. Follow these instructions:

  1. Boot into a linux *live* CD. Choose your favourite distribution. I personally prefer Debian. All the steps after this step should be done as root user in terminal.
  2. Mount the partition on which linux is installed (here /dev/sda1) using something like:
    # mount /dev/sda1 /mnt/sda1
    
    Use 'fdisk -l', cfdisk or gparted to find your linux partition. Or, you can also try mounting using a graphical file manager and then typing 'mount' to know partition and it's mount location.
  3. Next mount /dev, /proc and /sys:
    # mount --bind /dev /mnt/sda1/dev
    # mount --bind /proc /mnt/sda1/proc
    # mount --bind /sys /mnt/sda1/sys
    
  4. Now you need to chroot to your linux installation:
    # chroot /mnt/sda1
    
    From now on, whatever you'll do will be applied to linux installed on partition /dev/sda1. You have got access to your installed linux using a live CD.
  5. Let's install GRUB now:
    # grub-install /dev/sda
    
    Note that you need to type the name of your hardrive in the above command (and *not* the partition on which linux is installed).
  6. To close chroot environment (not sure about some of steps below):
    # umount /proc
    Now, press CTRL+D (i.e. the keycombination). Then:
    # umount /mnt/sda1/dev
    # umount /mnt/sda1/proc
    # umount /mnt/sda1/sys
    
That's it. Reboot and remove your live CD. You'll be greeted with your GRUB.
You can also try using AutoSuperGrubDisk or Super Grub Disk.


Note: Also, sometimes GRUB cannot correctly find the OS or kernel version (in case multiple kernel versions are installed) on your computer. If you find any of installed operating system missing from GRUB boot menu, login to your linux installation and run following as root:
# update-grub
Ideally, this will find all installed operating systems and update your GRUB menu accordingly.

No comments:

Post a Comment