414

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?

Mattlinux1
  • 690
  • 2
  • 7
  • 23
Salahuddin
  • 4,681
  • 7
  • 20
  • 19
  • 2
    Related (when GRUB was installed to the *wrong drive's MBR*): [Grub rescue problem after installing ubuntu](http://askubuntu.com/questions/229552/grub-rescue-problem-after-installing-ubuntu) – Eliah Kagan Jan 21 '13 at 04:20
  • I know this is an old thread but I fixed the problem by changing the boot mode in the bios from UEFI to Legacy. –  Aug 13 '13 at 11:32
  • 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](https://help.ubuntu.com/community/RecoveringUbuntuAfterInstallingWindows) tutorial. Any questions, ask me! – antivirtel Dec 17 '11 at 07:24
  • 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
  • 1
    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 '14 at 05:14

14 Answers14

445

When you install Windows, Windows assumes it is the only operating system (OS) on the machine, or at least it does not 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 is really clean.

Here's how:

  1. Boot from the live CD or live USB, in "Try Ubuntu" mode.

  2. Determine the partition number of your main partition. sudo fdisk -l, sudo blkid or GParted (which should already be installed, by default, on the live session) 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!

    If your main partition is in an LVM, the device will instead be located in /dev/mapper/, most likely, /dev/mapper/{volume}--{os}-root where {volume} is the LVM volume name and {os} is the operating system. Execute ls /dev/mapper for the exact name.

  3. Mount your partition:

     sudo mount /dev/sda2 /mnt  #Replace sda2 with the partition from step 2
    

    If you have a separate /boot, /var or /usr partitions, repeat steps 2 and 3 to mount these partitions to /mnt/boot, /mnt/var and /mnt/usr respectively. For example,

     sudo mount /dev/sdXW /mnt/boot
     sudo mount /dev/sdXY /mnt/var
     sudo mount /dev/sdXZ /mnt/usr
    

    replacing sdXW, sdXY, and sdXZ with the respective partition numbers.

  4. Bind mount some other necessary stuff:

     for i in /sys /proc /run /dev; do sudo mount --rbind "$i" "/mnt$i"; done
    
  5. If Ubuntu is installed in EFI mode (see this answer if you're unsure), use sudo fdisk -l | grep -i efi or GParted to find your EFI partition. It will have a label of EFI. Mount this partition, replacing sdXY with the actual partition number for your system:

     sudo mount /dev/sdXY /mnt/boot/efi
    
  6. chroot into your Ubuntu install:

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

     update-grub
    

    If you get errors or if going up to step 7 didn't fix your problem, go to step 8. (Otherwise, it is optional.)

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

     grub-install /dev/sda
     update-grub # In order to find and add windows to grub menu.
    
  9. If Ubuntu is installed in EFI mode, and EFI partition UUID has changed, you may need to update it in /etc/fstab. Compare it:

     blkid | grep -i efi
     grep -i efi /etc/fstab
    

    If current EFI partition UUID (from blkid) differs from the one in /etc/fstab, update /etc/fstab with current UUID.

  10. If everything worked without errors, then you're all set:

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

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

  • 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 8 does. Experience helping users in chat has shown that step 8 is sometimes necessary even when no error messages are shown.
Scott Severance
  • 13,776
  • 9
  • 52
  • 76
  • 2
    Comments are not for extended discussion; this conversation has been [moved to chat](http://chat.stackexchange.com/rooms/56694/discussion-on-answer-by-scott-severance-how-can-i-repair-grub-how-to-get-ubunt). – Thomas Ward Apr 07 '17 at 00:43
  • I still want Windows to be my primary boot OS. Is this still the right fix? How do I choose which OS to boot to? F11? – Jeff Jul 28 '17 at 16:34
  • This has no effect on which OS is primary. That's controlled in GRUB's settings, which is beyond the scope of this answer. This answer is concerned solely with restoring a borked GRUB. – Scott Severance Jul 28 '17 at 19:35
  • @ScottSeverance Unfortunately for me, there are other questions where that answer WOULD be in scope but are closed because they are a flagged as duplicate of this question. Over-ambitious moderation, I guess. – Jeff Jul 28 '17 at 21:27
  • @Jeff: I haven't dual booted for a number of years now, so I don't know too many details, but there is most definitely a way to configure which OS GRUB boots by default. Google for GRUB configuration for details, which I've long forgotten. I believe that you can also configure the Windows bootloader to chain load GRUB. You'll have to Google that as well as I've never attempted anything like that. – Scott Severance Jul 28 '17 at 21:33
  • @ScottSeverance Thanks. I'm already doing that now. I just wanted to vent about the overly ambitious moderation. – Jeff Jul 28 '17 at 21:36
  • @Jeff [How do I set Windows to boot as the default in the boot loader?](https://askubuntu.com/questions/52963/how-do-i-set-windows-to-boot-as-the-default-in-the-boot-loader) – bain Aug 05 '17 at 11:35
  • 3
    @ScottSeverance I saw from your profile that you live in DFW. Have you considered giving classes or live tutorials to get people deep into Linux? – M J Sep 26 '17 at 01:06
  • I would enjoy doing so, but I don't know any Linux people in DFW, and don't really have the time to try to start a group from scratch. I've never researched what may already be available in this area. – Scott Severance Sep 26 '17 at 03:04
  • 3
    These problems don't get old :D – Not that when dealing with EFI, you might need to install `grub-efi-amd64` and if you are using secure boot you'd want to use `grub-install --uefi-secure-boot`. This is also detailed in https://superuser.com/a/376471/197980 – Raffael Dec 01 '17 at 01:12
  • Hi, are you still there? I've tried this three times and lost about an hour and a half to this process and still can't get my Ubuntu back; it just defaults to Windows and when I hold F12 the only options are my USB stick and the Windows Bootloader. What else can I do? It's driving me mad. – jdc Mar 26 '18 at 05:22
  • @jdc, I suggest that you ask a new question, referencing this one, and giving specific details about your setup and what you've tried. Maybe someone here knows modern UEFI systems well enough to be able to help. – Scott Severance Mar 26 '18 at 13:10
  • I figured that would get closed as an exact duplicate, but I suppose it's the next step. Thank you for your response. – jdc Mar 26 '18 at 16:26
  • @jdc: These instructions have worked for lots of people, so assuming you've followed them correctly, you must be having a different underlying problem. – Scott Severance Mar 26 '18 at 16:33
  • @ScottSeverance: That's what I'm afraid of, that somehow my real problem doesn't have a solution. I saw the huge upvote count and thought I was saved, but I've gone through your process three times now with no luck. – jdc Mar 26 '18 at 16:54
  • This solution gave me : error file /boot/grub/../normal.mod not found, entering rescue mode, so I've tried the repair tool below instead . – user10089632 Mar 30 '18 at 11:50
  • 3
    This solution is applicable also for Windows 10 on computer with BIOS (i.e. not UEFI). The question about which one you have can be answered with this tip - https://www.thewindowsclub.com/check-if-uefi-or-bios. – okolnost Jun 27 '18 at 04:20
  • at least for me, the chroot to /mnt failed because /bin/bash wasn't available. The underlying problem, to which I don't see a solution, is that the system rooted at /mnt has to include /bin/bash, /lib, and /lib64. But the binds to these filesystems fail because there's no space available on the device. – Paul A. Sep 30 '19 at 10:55
  • 1
    @PaulA.: If you're missing `/bin`, `/lib`, or `/lib64`, just bind mount them, as well: `mount --bind /bin /mnt/bin`, etc. or better yet, figure out where they live on your system and mount the proper ones. – Scott Severance Oct 03 '19 at 02:07
  • 1
    I just want to say that as of may 2021 this still works. old dell laptop wit dual boot w10 ubuntu 20.04. windows update killed grub. this help me to restore the grub menu. steps 8 onwards were necessary – Nicolas Molano May 18 '21 at 16:11
  • Its 2021 and this answer is still helping me :) Which is both good and bad, bad that the problem persists ... – minisaurus Sep 25 '21 at 11:43
  • **If you have deleted EFI partition**, you should just create it again: https://askubuntu.com/a/743098/933016 Then you can install grub and load. – James Bond Dec 07 '21 at 17:40
  • I get "/mnt/sys: mount point does not exist". (also for proc, run ,dev). Does this indicate something has gone wrong? – Kvothe Jan 31 '22 at 11:38
  • @Kvothe: It sounds like something is wrong, but without more context it's hard to say what. – Scott Severance Jan 31 '22 at 11:51
  • @ScottSeverance, `/dev/sda2` contains the folders `boot-sav`, `lost+found`, `upper` `work`. Is that what it should contain? – Kvothe Jan 31 '22 at 11:57
  • Sounds like sda2 isn't the partition you need. You'll need to figure out which one you need. See step 2. – Scott Severance Jan 31 '22 at 12:03
  • 2
    This almost worked for me after cloning my disk to a new replacement device. I was under dual boot as well, using EFI. During grub-install a warning was issued: `grub-install: warning: EFI variables are not supported on this system..`. Based on this answer https://unix.stackexchange.com/a/693111 I had to use the --rbind flag instead of --bind in step no. 4, so it was `for i in /sys /proc /run /dev; do sudo mount --rbind "$i" "/mnt$i"; done`. – kprist Aug 31 '22 at 13:08
  • Excellent tutorial, needed step 8. and @kprist comment was useful too! Managed to restore LUKS encrypted LM boot. Scott Severance can you please add kprist reply ? I also got "EFI variables are not supported", also for LUKS we need to decrypt partition first (obvious but still) so that we can display encrypted volumes. – Aubergine Mar 26 '23 at 23:48
  • 1
    Just want to say thanks to both @ScottSeverance and @kprist . This saved my day. I also had to use `--rbind` in my case and running step 8 was mandatory. – SergioLeone Apr 14 '23 at 16:27
145

The Windows installer doesn't care about other OS in the system. So it writes own code over the master boot record. 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

Mikel
  • 6,478
  • 3
  • 29
  • 29
Web-E
  • 21,338
  • 12
  • 52
  • 93
  • 2
    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 Sodhani Sep 01 '12 at 07:04
  • 4
    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 01 '12 at 07:18
  • 11
    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 01 '12 at 07:26
  • 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 05 '14 at 16:14
  • it does not act on luks partitions at all, so it cannot mess them up. And it uses apt-get only when GRUB purge is needed. – LovinBuntu Jan 08 '14 at 02:53
  • + for this. Both solutions worked form but this is pretty useful for any newbie with no knowledge who could possibly get the issue fixed. I didn't loose any DATA's performing but, **Pre-Tip: Make sure you back-up all your DATA's before performing. It is always a good practice to do so.** – AzkerM Jan 31 '14 at 13:13
  • It's worth noting the Boot-Repair only works with systems booted in EFI/UEFI mode, which is set in your machine's BIOS. If you are set up to boot your Ubuntu/Linux in Legacy mode, Boot-Repair won't work. – Fuzzy Analysis Dec 30 '14 at 12:09
  • 2
    boot repair supports legacy mode very well, perhaps you need to boot the live cd/usb in legacy mode as well @fuzzyanalysis :) – Web-E Jan 01 '15 at 14:08
  • @Shagun I agree. I removed it, since it's completely irrelevant to the otherwise correct answer. – Mikel Oct 05 '15 at 16:34
  • Just tried this in 14.10. `apt-get update` shows a bunch of 404 Not Found errors and the installation fails with `Unable to locate package boot-repair`. – Dan Dascalescu Feb 02 '16 at 16:51
  • No available for 14.10 See https://launchpad.net/~yannubuntu/+archive/ubuntu/boot-repair – Web-E Feb 04 '16 at 10:29
  • "Recommended repair" worked just fine when using an Ubuntu 16.04 bootable USB for saving an Ubuntu 14.04 installation from an eternity of fire and despair. – Krøllebølle Jun 29 '16 at 16:28
  • to be precise "Windows installer doesn't care about other non-Microsoft OSes in the system", because it will detect and list any DOS and Windows OSes available – phuclv Dec 31 '16 at 05:45
34

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 :

Stormvirux
  • 4,446
  • 29
  • 35
  • Web-E already gave this [answer](http://askubuntu.com/a/182863/116961). Maybe improve that one instead? I left a comment on why it didn't work. – Dan Dascalescu Feb 02 '16 at 16:59
  • 2
    This method worked for me after a particularly nasty case of a Windows 10 update overwriting GRUB and then breaking its own boot loader. Following this procedure got both Windows and Linux back. In my case it was Linux Mint 18.1, and the boot-repair menus looked slightly different, but it all worked fine. Thanks! – TheBigH May 28 '17 at 22:53
15

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).

Zanna
  • 69,223
  • 56
  • 216
  • 327
Hamed
  • 514
  • 1
  • 9
  • 19
  • 3
    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 '14 at 20:46
  • 1
    easyBCD allowed me to add and remove boot options that I could see in both Windows Boot Loader and BIOS, but they never worked because easyBCD relies on some sort of automated magic to find Linux partitions... it didn't work when my Linux partition was on a separate harddrive. – Fuzzy Analysis Dec 30 '14 at 12:14
  • is this can handle win 11? – toha Nov 12 '22 at 07:11
  • It doesn't work for Windows 11 that is installed in the EFI mode – Amin Ya Feb 13 '23 at 09:44
15

On EFI-based systems (such as most systems that shipped with Windows 8 or later), Windows will sometimes update its boot loader or reset it to be the default boot loader. This is particularly common when re-installing the OS or performing a major system update (upgrading to the latest Windows release, for instance). Note that Windows is unlikely to actually erase any GRUB files on an EFI-based computer. Everything needed to boot Ubuntu is still in place; it's just being bypassed. In these cases, a complete re-installation of GRUB is overkill, and in fact that carries a (small) chance that it will create new problems.

Thus, instead of re-installing GRUB in these cases, I recommend resetting GRUB (or whatever boot loader or boot manager you prefer) to be the default. There are several ways to do this, including:

  • EasyUEFI -- The easiest way to adjust the boot order, if the system is booting straight to Windows, is to use EasyUEFI, which is a free (for the basic version) third-party GUI tool for managing the EFI boot order. It's pretty self-explanatory -- locate the ubuntu entry in the list of boot options and move it to the top of the list. The next time you reboot, GRUB should come up. (If you use something other than GRUB, you'll need to locate its entry.)
  • bcdedit -- The Windows bcdedit tool can be used to set GRUB to the default boot order. The command bcdedit /set {bootmgr} path \EFI\ubuntu\grubx64.efi, typed in an Administrator Command Prompt window, will do this; however, if your computer boots with Secure Boot active, bcdedit /set {bootmgr} path \EFI\ubuntu\shimx64.efi will be required instead. In fact, the latter command will usually work even if Secure Boot is not in use, so I'd use that command first. Note that there's a more advanced Windows shell tool that requires a slightly different syntax than I've presented, but I don't recall the details.
  • One-time boot to Ubuntu -- Most EFIs provide a built-in boot manager, accessed by hitting a function key, Esc, or Enter early in the system start process. Chances are the ubuntu entry to boot Ubuntu will show up in this boot manager menu, enabling you to boot to Ubuntu. Alternatively, you could boot to an Ubuntu emergency medium, like the installer booted in "try before installing" mode. Either way, you can then use efibootmgr to adjust the boot order:
    1. Type sudo efibootmgr to see the boot entries.
    2. Note the current BootOrder line.
    3. Locate the entry for ubuntu and note its Boot#### number.
    4. Type sudo efibootmgr -o xxxx[,yyyy,zzzz,....] to change the boot order, making xxxx the number for Ubuntu. What comes after that is most likely not very important, although I've noted that Windows seems to be likely to add itself back to the start of the boot order if it's not in the list. Thus, you should probably ensure that Windows is in the list, and it may be safest to re-order the list so that all the original entries are there, just with the ubuntu entry moved to the top of the list.
  • Firmware setup utility -- Some EFIs' setup utilities enable you to adjust the boot order. Details vary greatly from one EFI to another, so I won't go into specifics, but you could look for such an option in your setup utility.

There are other variants on these procedures, such as using bcfg in an EFI shell, using bless in macOS, using my rEFInd to do a one-time boot, etc. I'd start with EasyUEFI, though; it's likely to be the simplest solution. Sometimes Windows insists on making itself the default every time it starts up, though, and reports indicate that bcdedit may do a better job of dealing with that problem.

Note that none of the preceding applies to BIOS-mode installations; however, as most computers that shipped with Windows 8 or later boot in EFI mode, BIOS-mode installations are becoming increasingly rare, so in many cases it's better to deal with the issue in the EFI way rather than by blindly re-installing GRUB.

Rod Smith
  • 43,599
  • 7
  • 62
  • 102
  • 4
    manually one-time booting into linux (fedora28 in my case) through the EFIs build-in boot manager allowed me to use `efibootmgr` to re-order the boot-order (as described by Rod -> thanks!) which was messed with by a win10 update. Afterwards the GRUB-bootmanager appears as it used to before the update, so I can confirm the provided solution worked for me. I could not find the basic version of EasyUEFI but only a trial version of the non-free pro-version offered. – antiplex Aug 22 '18 at 08:31
  • This should be the accepted answer. – Déjà vu Aug 05 '21 at 15:13
11

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.

scruss
  • 1,234
  • 3
  • 14
  • 28
6

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.

metakermit
  • 2,600
  • 3
  • 28
  • 34
lorenzo-s
  • 485
  • 3
  • 8
  • 17
  • 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 01:51
5

Answers given by Scott and Web-E are good enough and have helped a lot many times. But many a times, the boot-repair tool is not able to repair grub due to problems related to i386 and amd64 platform or one where grub can't find efi directory.
What has solved my problem like more than 10 times is to manually purge the old grub installations and install a new one.

So first perform the first 6 steps from Scott's answer where you can skip the 5th step if it gives an error:

  1. Boot from the live CD or live USB, in "Try Ubuntu" mode.
  2. Determine the partition number of your main partition. sudo fdisk -l, sudo blkid or GParted (which should already be installed, by default, on the live session) 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!

    If your main partition is in an LVM, the device will instead be located in /dev/mapper/, most likely, /dev/mapper/{volume}--{os}-root where {volume} is the LVM volume name and {os} is the operating system. Execute ls /dev/mapper for the exact name.

  3. Mount your partition:

    sudo mount /dev/sda2 /mnt  #Replace sda2 with the partition from step 2
    

    If you have a separate /boot, /var or /usr partitions, repeat steps 2 and 3 to mount these partitions to /mnt/boot, /mnt/var and /mnt/usr respectively. For example,

    sudo mount /dev/sdXW /mnt/boot
    sudo mount /dev/sdXY /mnt/var
    sudo mount /dev/sdXZ /mnt/usr
    

    replacing sdXW, sdXY, and sdXZ with the respective partition numbers.

  4. Bind mount some other necessary stuff:

    for i in /sys /proc /run /dev; do sudo mount --bind "$i" "/mnt$i"; done
    
  5. If Ubuntu is installed in EFI mode ([see this answer if you're unsure][efi]), use sudo fdisk -l | grep -i efi or GParted to find your EFI partition. It will have a label of EFI. Mount this partition, replacing sdXY with the actual partition number for your system:

    sudo mount /dev/sdXY /mnt/boot/efi
    
  6. chroot into your Ubuntu install:

    sudo chroot /mnt
    

Then do these steps:

  1. Configure all the pending packages.
    sudo dpkg --configure -a
  2. Fix the broken packages.
    sudo apt install -fy
  3. Remove the current grub.
    sudo apt purge -y grub*-common grub-common:i386 shim-signed
    This may give you a warning that your device will have no bootloader and may be unable to boot the next time. Go ahead and accept it.
  4. sudo apt install -y grub-pc
    After running this command, it will ask you to point the current sdXY to install the bootloader. Find where your current OS is installed using sudo fdisk -l command. It will be labelled as Linux. Navigate that window using Tab key and select an option using Space key.
  5. If everything goes right, grub will be installed correctly. You can also do sudo grub-update for a double check.

If the problem still persists, you can read Arch's wiki to actually understand about grub to tackle many other varieties of problems. (Yes, also helps for Ubuntu!).

subtleseeker
  • 501
  • 7
  • 19
5

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.

LovinBuntu
  • 3,605
  • 2
  • 19
  • 21
4

Scott Severance's answer is valid and detailed but there is a resolution that requires no external boot device and so no need to identify and manually mount all of your Ubuntu partitions leading up to the chroot.

In Windows 10, you can use Advanced Recovery to select a device (partition?) to boot from.

Go to Settings and choose Update & Security:

enter image description here

Go to Recovery:

enter image description here

From Advanced Startup choose Restart Now

enter image description here

Then choose Use a Device and all the boot options should be presented to you. Choose the 'ubuntu' partition and your PC should then boot from that partition.

Once booted into my usual Ubuntu environment, I have tried just running grub-update but that made no change.

I then found my /boot/efi partition which was /dev/nvme0n1p1 and ran sudo grub-install /dev/nvme0n1p1 and then sudo update-grub.

This has restored my master boot record multiple times now as there seems to be a new Windows 10 policy of overwriting boot info on minor updates.

timbo
  • 323
  • 1
  • 4
  • 14
  • I'm confused. You mention both MBR and UEFI: which one was used for the installations? I supposed UEFI because otherwise it probably wouldn't have shown the Linux boot options. But then it shouldn't even need to touch the MBR. Probably also only works, if Grub2 was installed on your Ubuntu partition instead of the MBR. – DanMan Jan 11 '20 at 02:24
  • Sorry my bad. I was using MBR and I really mean generic boot info. I've removed MBR from the description. – timbo Mar 29 '20 at 22:16
3

It turns out grub can be fixed from Windows too. Running the following (as administrator) from CMD brought the grub menu back for me.

bcdedit /set {bootmgr} path \EFI\ubuntu\grubx64.efi
mindlessgreen
  • 233
  • 2
  • 11
  • Worked like a charm on Windows 10 to show the Grub menu again, allowing me back to Ubuntu 20.04! I also found a [more detailed guide here](https://itsfoss.com/no-grub-windows-linux/) that shows how to revert if this does not work. – gMale Jul 14 '21 at 01:10
2

Only fsck command fixed the grub-rescue screen for me.

Use Boot-Repair to boot from Live-CD, then open Terminal

Get the correct device:

sudo fdisk -l

Need to find the boot device, the boot device has * under Boot category like here:

Device     Boot   Start       End   Sectors  Size Id Type
/dev/sda1          2048   2000895   1998848  976M 82 Linux swap / Solaris
/dev/sda2  *    2000896 943716351 941715456  449G 83 Linux

Now repair the disk by using:

sudo fsck /dev/sda2 -y

Note: /dev/sda2 is the boot device in this example.

Reboot when completed. Done.

Benny
  • 4,790
  • 2
  • 18
  • 33
2

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).

wjandrea
  • 14,109
  • 4
  • 48
  • 98
oldfred
  • 11,747
  • 3
  • 23
  • 33
  • The new versions of sfdisk & fdisk that work with gpt partitioned drives in 16.04 or later, will also backup the gpt partitioned drives with above command. oldfred does not remember what he ate for dinner last night, so not sure what he posted back in 2013. :) – oldfred Apr 07 '17 at 13:40
  • Hi Fred when I'm cooking forgetting dinner last night is a blessing. We deleted our previous comments. – WinEunuuchs2Unix Apr 07 '17 at 14:49
1

I had a different issue, caused (probably) by boot-repair wiping my /etc/grub.d/ templates, outlined in my question here: Ubuntu 18.04 not booting after Windows 10 install

As pointed out by @karels comment, the grub config is generated using the files in /etc/grub.d. My directory only contained /etc/grub.d/25_custom, which contained strange menu entries pointing to non-existent .efi images. It looked like my /etc/grub.d templates were maybe hosed by boot-repair.

I fixed this by:

  1. Boot with Live CD (probably important to use same Ubuntu version)
  2. sudo mount /dev/sdxx /mnt
  3. sudo cp /etc/grub.d/* /mnt/etc/grub.d/
  4. sudo update-grub
  5. Reboot & relax after 48 hours of pain
Adam Moore
  • 179
  • 7