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.
Best Answer
You can re-install grub in the Master Boot Record using the LiveCD for you distribution version,
It goes like this:
Boot from LiveCD ⋯ please try to use a LiveCD that has the same version of Grub2 as the installed version
Mount the root of the installed Ubuntu at /mnt
Change root
Update grub
Install grub
Reboot
The above steps are from near the bottom of the Ubuntu Community Documentation of Grub2
After booting from the liveCD ( select "Try Ubuntu" on the opening screen)
Then start up a terminal (dash, type-in terminal, … )…
Type in the terminal
sudo fdisk -l
- and enter your password if asked. That's a lower case L. Find the installed Ubuntu partitions, (from mine with other disks snipped ― here):Find your Linux installation (Id=83, System=Linux0 then type in
but use your partition instead of
/dev/sde3
(my root partition is sde3, sde7 is my home partition).This is assuming that you do not have a separate
/boot
partition. If you do, you will need to also mount it by typingwhere
sd··
is the partition where you installed the separate boot directory.ls /mnt
- just checking to see if I got it right:You should test to see if the boot directory is properly installed. Type in
ls /mnt/boot
and if it is empty, the boot directory is not installed. It should look something like this:Then:
Example:
Now to re-install grub in the MBR. You will need to know which disk your system boots from, and find it in the
fdisk -l
listing you have already done. Then type insudo grub-install /dev/sd
replacingsd·
with the disk you will boot from.Then type in
Crtl-D
to exit chroot.Then type in
sudo for i in /sys /proc /dev/pts /dev; do sudo umount /mnt$i; done
- as one lineIf you mounted a separate /boot partition, type in
sudo umount /mnt/boot
Then type in
sudo umount /mnt
Then type in
sudo reboot
to restart he system (remember to remove the LiveCD).Hopefully, grub will be installed.