Recovering GRUB after installing Windows 7 with boot repair
Recently I've reinstalled the Windows copy I had alongside Ubuntu, and after that the GRUB menu disappeared and the computer starts off on Windows automatically. The solution I found was to run boot repair, so I ran Ubuntu from a CD, and then installed and ran boot repair, and it said the repair had been successful. However, the GRUB didn't reappear. This is the log I got after running boot repair:
http://paste.ubuntu.com/6677448/
Thanks
Except that you formatted Linux partitions by error during Windows 7 installation wizard, there is no reason to think your Ubuntu files aren't there any more. I had to reinstall my Windows 7 on my dual boot machine a couple of times and faced this problem. Windows installation overwrite your MBR and put there its own code. GRUB boot directory is intact, as long as you had it in your Ubuntu partition, but the MBR code written by GRUB isn't there any more.
The following procedure has some risk. I will adapt the commands to your partition numbers according to the screenshot you uploaded, but please, review the partition numbers two times before using my commands. Also, I don't accept any responsibility if something go wrong and you end having to backup your files and reinstalling Ubuntu.
As I don't sure the following works on GPT partition tables, lets add extra security and only do it if your disk is MBR, the command sudo parted -l
must show your partition table as msdos
in line 3 or 4 of its output. If not, stop here.
- Boot into your Ubuntu Live CD, please, same version that the one that lives in your hard disk.
- Confirm first that the directory /boot, exists in your Ubuntu root partition. I assuming it is sda2 as it is formatted as ext2, so mount it and navigate to its root and see if you have a boot directory there. If it isn't there stop here.
- Dismount sda2. Use Nautilus or Unity laucher or umount command, doesn't matter. But dismount it.
- Launch Terminal.
- Use the following commands (note, if I remember correctly, when using sudo from the Live CD, just press ENTER when prompted for a password):
:
sudo -i
mount /dev/sda2 /mnt
grub-install --root-directory=/mnt/ /dev/sda
umount /mnt
exit
- Reboot your machine. Remove Live CD.
If the grub menu appears and show both, Windows 7 and Ubuntu, you are done. If not, you will have to do extra work. I'm updating this question right now to add the longer method, I had to use it in one occasion because the shorter method above leaved me in the GRUB console without any operating system to chose, if this happens to you don't panic, I'm writing the longer method right now.
Longer method: do it if, at boot, you end in a console with no operating system to select or if Windows 7 (or Ubuntu) does not show in the list
- Boot into your Ubuntu Live CD, please, same version that the one that lives in your hard disk.
- Launch Terminal.
- Use the following commands (note, if I remember correctly, when using sudo from the Live CD, just press ENTER when prompted for a password):
:
sudo -i
mount /dev/sda2 /mnt
mount --bind /proc /mnt/proc
mount --bind /dev /mnt/dev
mount --bind /sys /mnt/sys
chroot /mnt update-grub
umount /mnt/sys
umount /mnt/dev
umount /mnt/proc
exit
- Reboot your machine. Remove Live CD.
You should see now both, Windows 7 and Ubuntu, as options in the GRUB boot menu.
Credits: http://www.ubuntugeek.com/how-to-restore-grub-boot-loader-after-installing-windows.html
Both methods were tested by me in my own machine and I confirm they work.
There is a third variation, in the case you had the boot directory in another partition that is not where the Ubuntu root is mounted, but as you formatted the other partition if this were the case you already lost it anyway so there is no point in it.