Tell me more ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I installed Windows 7, which ate Ubuntu's boot file. When starting up the computer, it now goes straight to Windows, without giving me the option of booting Ubuntu.

How can I get Ubuntu back?

share|improve this question
Related (when GRUB was installed to the wrong drive's MBR): Grub rescue problem after installing ubuntu – Eliah Kagan Jan 21 at 4:20

8 Answers

up vote 48 down vote accepted

When you install Windows, Windows assumes it's the only OS on the machine--or at least it doesn't account for Linux. So, it replaces grub with its own boot loader. What you have to do is replace the Windows boot loader with grub. I've seen various instructions for replacing grub by mucking around with grub commands or some such, but to me the easiest way is to simply chroot into your install and run update-grub. chroot is great because it allows you to work on your actual install, instead of trying to redirect things here and there. It's really clean.

Here's how:

  1. Boot from the live CD.
  2. Determine the partition number of your main partition. GParted can help you here. I'm going to assume in this answer that it's /dev/sda2, but make sure you use the correct partition number for your system!
  3. Mount your partition:

    sudo mount /dev/sda2 /mnt  # make sure that sda2 is correct!
    
  4. Bind mount some other necessary stuff:

    for i in /sys /proc /run /dev; do sudo mount --bind "$i" "/mnt$i"; done
    
  5. chroot into your Ubuntu install:

    sudo chroot /mnt
    
  6. At this point, you're in your install, not the live CD, and running as root. Update grub:

    update-grub
    

    If you get errors, go to step 7. (Otherwise, it is optional.)

  7. Depending on your situation, you might have to reinstall grub:

    grub-install /dev/sda
    update-grub # I'm not sure if this is necessary, but it doesn't hurt.
    
  8. If everything worked without errors, then you're all set:

    exit
    sudo reboot
    
  9. At this point, you should be able to boot normally.

If you cannot boot normally, and didn't do step 7 because there were no error messages, try again with step 7.

  • Sometimes giving GRUB2 the correct configuration for your partitions is not enough, and you must actually install it (or reinstall it) to the Master Boot Record, which step 7 does. Experience helping users in chat has shown that step 7 is sometimes necessary even when no error messages are shown.
share|improve this answer
yeah .. finally it does work .. would you please explain what happened? – Salahuddin Dec 17 '11 at 12:56
update-grub only generates the configuration file. To actually rewrite the boot sector, you need to run grub-install. – Mihai Capotă Dec 24 '11 at 10:59
@MihaiCapotă: From the documentation it seems as though that would be the case. grub-install is good to know about. However, in my experience so far, update-grub has been sufficient. YMMV. – Scott Severance Dec 24 '11 at 13:09
@ScottSeverance , i'm getting /usr/sbin/grub-probe: error while loading shared libraries: libdevmapper.so.1.02.1: wrong ELF class: ELFCLASS32 error on 6th step after executing update-grub command. – Eray Apr 18 '12 at 22:49
@Eray: Never heard of that problem. Is the live CD the same version of Ubuntu as your install? If not, that might be the problem. Or maybe you've got a 32-bit install and a 64-bit CD or vice-versa. The CD needs to match your install. – Scott Severance Apr 18 '12 at 23:26
show 8 more comments

If you have a Dell PC you also need to be aware of custom software like Dell DataSafe that comes bundled with Win 7. This will overwrite GRUB every time it runs and you'll need to use a Live CD to boot Ubuntu properly. I found that uninstalling Datasafe stopped any GRUB related problems I was having with dual-booting Ubuntu and Windows.

share|improve this answer
Dell is insane. – CravingSpirit Mar 19 at 15:15

The windows installer doesn't care about other OS in the system. So it writes own code over the master boot record. Its not a problem of windows installer, its intended. If you reinstall, upgrade windows you will face the issue. Fortunately the solution is easy too.

You need to repair the mbr. Do the following

Boot using a live usb/cd of ubuntu. Use boot-repair to fix the problem.

After booting with live usb/cd ,Run following command in terminal,

sudo add-apt-repository ppa:yannubuntu/boot-repair && sudo apt-get update
sudo apt-get install -y boot-repair && boot-repair

Use Recomended Repair.

enter image description here

More info - https://help.ubuntu.com/community/Boot-Repair

share|improve this answer
you mean to say its intentional by the Microsoft people?? Also dual booting did work with windows 7 so doesn't it contradict your first line that "The windows installer doesn't care about other OS in the system." – Shagun Sep 1 '12 at 7:04
Windows breaks grub all the time its a really common issue and one ive had to deal with myself. The answer is still good and should fix the problem. – damien Sep 1 '12 at 7:18
1  
you have installed windows 7 first then linux. So linux recognize windows not windows recognized linux. Ttry reinstalling windows7, you will see what I meant. – Web-E Sep 1 '12 at 7:26
ohk now I get what you meant :) – Shagun Sep 1 '12 at 7:46

I never got in trouble by using these instructions:
https://wiki.ubuntu.com/Grub2#Recover

First of all, you must start your system from a live cd. Then

"METHOD 3 - CHROOT

This method of installation uses the chroot command to gain access to the broken system's files. Once the chroot command is issued, the LiveCD treats the broken system's / as its own. Commands run in a chroot environment will affect the broken systems filesystems and not those of the LiveCD.

1) Boot to the LiveCD Desktop (Ubuntu 9.10 or later). Please note that the Live CD must be the same as the system you are fixing - either 32-bit or 64-bit (if not then the chroot will fail).

2) Open a terminal (Applications > Accessories > Terminal).

3) Determine your normal system partition - (the switch is a lowercase "L")

sudo fdisk -l

If you aren't sure, run

df -Th  

Look for the correct disk size and ext3 or ext4 format.

4) Mount your normal system partition:

Substitute the correct partition: sda1, sdb5, etc.

sudo mount /dev/sdXX /mnt  

Example: sudo mount /dev/sda1 /mnt

5) Only if you have a separate boot partition: sdYY is the /boot partition designation (for example sdb3)

sudo mount /dev/sdYY /mnt/boot 
6) Mount the critical virtual filesystems:
sudo mount --bind /dev  /mnt/dev
sudo mount --bind /dev/pts  /mnt/dev/pts
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys  /mnt/sys 
7) Chroot into your normal system device:

sudo chroot /mnt 

8) If there is no /boot/grub/grub.cfg or it's not correct, create one using

update-grub 

9) Reinstall GRUB 2:

Substitute the correct device - sda, sdb, etc. Do not specify a partition number.

grub-install /dev/sdX 

10) Verify the install (use the correct device, for example sda. Do not specify a partition):

sudo grub-install --recheck /dev/sdX 

11) Exit chroot: CTRL-D on keyboard

12) Unmount virtual filesystems:

sudo umount /mnt/dev/pts
sudo umount /mnt/dev
sudo umount /mnt/proc
sudo umount /mnt/sys 

13) If you mounted a separate /boot partition:

sudo umount /mnt/boot 

14) Unmount the LiveCD's /usr directory:

sudo umount /mnt/usr 

15) Unmount last device:

sudo umount /mnt 

16) Reboot.

sudo reboot 
"

share|improve this answer
1  
Just a note that it isn't necessary to worry about unmounting stuff, because the reboot will take care of that automatically. Sending umount commands wastes time. – Scott Severance Oct 1 '12 at 8:44
1  
sudo umount -a should take care of them, as well. It's not a bad practice if you've got the few moments. At least reminds you of what's going on, and in some (corner/marginal) cases it can keep the reboot from stopping to warn you or wait for input. – belacqua Nov 3 '12 at 20:25
+1 for cautioning on the separated /boot partition. – CravingSpirit Mar 19 at 15:27

Just install easyBCD in Windows 7 and do

Add New Entry > Linux/BSD > (select ) Grub2 > (push) Add Entry

Then you can choose Ubuntu on the Windows 7 bootloader to go to Grub2 (previous bootloader).

share|improve this answer

Boot-Repair worked for me. It's very very easy to use graphical application, you do not need to use the command line, you only have to click a button :)

All the available repair options are described in the Ubuntu documentation and there is a separate page explaining how to start Boot-Repair (by creating a bootable disk or installing it in an existing Ubuntu live disk) and how to use it.

Just boot a Ubuntu live CD, install Boot-Repair and run it.

share|improve this answer
It would be nice if there were an easier way to get Boot Repair, though. It's faster to just set up a chroot repair than to Google around for some other tool to install. – Scott Severance Dec 18 '11 at 1:51

I think it is a common task, I also have two HDDs, and Ubuntu+Windows. I hope you can repair it with the right way. Try to follow this tutorial. Any questions, ask me!

share|improve this answer
1  
Thanks for your reply I had already followed that tutorial 1-logged on ubuntu usind live cd 2-open terminal 3-writing the commands mentioned above 4-restart but the black screen appeared finished with GRUB> and waiting for something to be written *Note that i have used these commands before (a month ago) and i worked very well with me .. but i don't know what is the matter – Salahuddin Dec 17 '11 at 7:25
Any suggestions? – Salahuddin Dec 17 '11 at 7:32
1  
Have you tried the mentioned Boot-repair? help.ubuntu.com/community/Boot-Repair – B. Roland Dec 17 '11 at 7:40
i think that the removal of the grub of windows was because of this software ( i tried it but doesn't work) i'll try it again – Salahuddin Dec 17 '11 at 8:21
I'm fully upset .. it doesn't work – Salahuddin Dec 17 '11 at 8:32
show 4 more comments

When GRUB is broken, the user generally does not have access to systems, so repair must be performed from a live-session (live-CD or live-USB).

There are many possible causes to a GRUB break: Windows writing on the MBR, DRM preventing GRUB from installing correctly, installer bug, hardware change... Updating GRUB as proposed initially by Scott is generally not sufficient, reinstalling GRUB as proposed by Marco is more efficient, but still there are various situations requiring other tweaks (adding options to kernel, unhiding GRUB menu, changing GRUB options, choosing the right host architecture...). Other difficulties for repairing GRUB is the use of chroot, and the choice of the right partitions /disks.

All of this has been made easy in a little graphical tool: Boot-Repair. It shall be integrated in Ubuntu 12.04 CD for easier use, but for people needing it now, there are already some distros integrating it: Ubuntu-Secured-Remix (Ubuntu CD integrating Boot-Repair), Boot-Repair-Disk (CD running Boot-Repair at start-up), ...

Hope this helps.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.