Take the 2-minute tour ×
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
    
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! –  B. Roland Dec 17 '11 at 7:24
1  
Related (when GRUB was installed to the wrong drive's MBR): Grub rescue problem after installing ubuntu –  Eliah Kagan Jan 21 '13 at 4:20
    
Yes you can, you would just have to do a normal boot and install with windows and then it should show up in the Grub boot menu at the start-up of the computer. –  Rampoo1208 Jul 30 '13 at 18:51
    
I know this is an old thread but I fixed the problem by changing the boot mode in the bios from UEFI to Legacy. –  user183708 Aug 13 '13 at 11:32
    
NOTE: the accepted answer is a general instruction on how to repair grub. It is also applicable to the wide variety of circumstances when GRUB is written incorrectly by the installer (ubiquity). –  Danatela May 14 at 5:14

9 Answers 9

up vote 123 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
1  
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

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

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

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
    
These instructions alone do not restore the Grub Bootloader - when I tried them, they added an extra boot option in Windows which on selection, restarted my machine and then took me to a grub> prompt. So one would need further steps as to what to do next. –  therobyouknow Jun 15 at 20: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
3  
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. –  belacq Nov 3 '12 at 20:25
    
+1 for cautioning on the separated /boot partition. –  qed Mar 19 '13 at 15:27

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
4  
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
    
Don't do this when you have encrypted partitions (luks), it messed it up. It also reinstalls GRUB with apt-get - no idea why it's doing that. –  Meng Tian Jan 5 at 16:14

Boot from a live Ubuntu USB pendrive or CD and
Install Boot-Repair on ubuntu by following steps

Open the terminal and run the following commands

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

After completing the installation you can launch it from System->Administration->Boot-Repair menu if you use Gnome, or search "boot-repair" in the dash if you use Unity. Then follow the following screenshots:

Method 1

  • Click on the advanced options

Initial screen

  • Tick the options shown below

advanced option

  • Change the tab to Grub Location Tab and Tick The options Shown in the figure

enter image description here

Press Apply and Reboot the system

Method 2

  • Select the recommended Boot repair options as shown in the first screenshot

Documentation :

share|improve this answer

Windows does not see Linux formatted partitions. You need to use gparted from a liveCD and create a primary partition formatted NTFS with the boot flag.

Some have had issues if the new primary partition is after the extended partition as Windows does not always reset partition table correctly. Best to have good backups and a separate backup of partition table.

Backup partition table to text file & save to external device. sudo sfdisk -d /dev/sda > PTsda.txt

This is only for MBR(msdos) systems. If your Ubuntu install is in gpt partition drive you can only install Windows in UEFI mode or convert drive back to MBR(msdos).

share|improve this answer

There is now a simpler solution:

  1. Reboot, and enter your computer's BIOS options (F2, or sometimes F11).
  2. Go to the Boot menu, and select Boot Device Priority
  3. Check if Windows Boot Manager is above the main boot drive (usually SATA HDD … or IDE HDD …). If it is, move the boot disk priority above that of Windows Boot Manager.
  4. Save your BIOS options, and exit (usually F10).

This has been tested on a Samsung Series 7 Chronos laptop dual booting Windows 8 and Ubuntu 13.10, secure boot disabled, UEFI and legacy boot enabled.

share|improve this answer

protected by jokerdino Dec 2 '13 at 17:55

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

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