How to recover the Windows 10 MBR after w Linux install?

28,693

Solution 1

You need to understand something first. Windows 10 doesn't use the master boot sector by default. Neither do modern distributions of Linux. In any normal circumstance the Grub 2 bootloader does not overwrite the Windows 10 bootloader. They can coexist perfectly fine on the EFI partition. In which case it is your BIOS's boot order that decides which bootloader is launched.

I'm afraid Keltari's answer presumes you are using a MBR partition table... which is rather unlikely. In fairness, your question seems to make the same assumption. Thus, before doing anything else, I suggest you check your boot options in your BIOS and see if Windows 10 isn't still listed as an option. If not... then yeah... bad things happened.

There are a few circumstances where access to the Windows 10 bootloader would be cut off.

  1. Window 10 was installed in MBR mode. Then Linux was installed.
    • If Windows 10 came on your computer from the manufacturer, then this is not the case.
    • This would only reasonably happen in two ways...
      1. You installed Windows 10 as an upgrade to a previous windows install which was in turn installed on top of a previous windows install going back to at least Windows Vista. If you've done this, you really need to reinstall Windows 10 fresh anyway.
      2. The hard drive was configured for MBR/DOS style partitions (instead of GPT) and you chose not to wipe the drive off and start fresh when Windows 10 was installed. This would typically happen if the hard drive was migrated from an older computer to your current one.
  2. You deleted/formatted the EFI partition during the Linux installation. This would be a mistake. There's no benefit for doing so, and you lose the existing bootloaders stored there.
  3. The partition scheme was converted to from GPT to MBR during the installation of Linux. In which case your Windows 10 boot loader is still right where you left it on the EFI partition.

In the case of #1 or #2:

You will need to restore the bootloader from the Windows 10 installation disk. If your computer didn't come with a Windows 10 installation disk, then you will need to acquire one. A Windows 10 ISO can be legitimately downloaded from the Microsoft website. You can then use the burning utilities in Linux to apply the ISO image to a blank DVD-R. If your computer is in warranty you may be able to acquire a Windows 10 install dvd from your manufacturer... but make sure you are clear that you want the Windows 10 installation disk not system recovery disks.

Boot from the Windows 10 DVD (either via "legacy" boot or "UEFI" boot... for MBR partition tables or GTP partition tables respectively). When you get to the Installation welcome screen where is says Install Now go ahead and ignore the Install Now button and click on Repair your computer instead.

  • From the Choose An Option menu select Troubleshoot
  • From the Troubleshoot menu select Advanced
  • From the Advanced menu select Startup Repair

You then may or may not be asked for a user and password to login. This is a good thing if it does show up... it means Windows Repair definitely found your Windows 10 installation. If it doesn't show up it's no big deal. Either way it should begin attempting various automated diagnostic and repair routines. In a perfect world, this will restore the Windows 10 bootloader.

If your system is using MBR then it will replace the Grub 2 bootloader. If your system is still using EFI boot it will not remove the Grub 2 bootloader... it will install itself along side it. In the latter case you will still likely need to enter your BIOS and change the boot order so that your BIOS starts the Windows 10 bootloader.

If that does not work then the solution is, invariably, going to be much more involved. You can either take your computer to a professional tech or wipe it off and reinstall Windows 10 from scratch.

In the case of #3:

You need to be extra sure this is what happened before you convert to GPT. You also need to backup any important data first, as this is the realm of evil monsters named Data Loss and Corruption. Take your time with this... it takes just two wrong keystrokes to wipe out your data.

First you need to identify the device name of the disk drive. Find and open your distro's terminal app. It's probably called something like xTerm or gTerm. Once you are at the terminal prompt type lsblk. This will display something like this:

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0  28.3G  0 disk
├─sda1   8:1    0   953M  0 part /boot
├─sda2   8:2    0     1K  0 part
├─sda3   8:3    0  23.4G  0 part /
└─sda5   8:5    0     4G  0 part [SWAP]
sdb      8:16   0 149.1G  0 disk
└─sdb1   8:17   0 149.1G  0 part /mnt/storage

Find the mount point for / and/or /boot. The mount points correspond to partitions (or some other form of logical division of disk resources). If you look under the Name heading for each mount point you will see that logical disk's device-name. And if you follow the connecting line to the listing above that with Type disk you find the device-name for the physical disk. The device-name for the physical disk is what we need. It doesn't matter what it is or whether looks remotely like the one above, just remember it.

Now, on the same terminal type gdisk/dev/device-name where you replace device-name with the one we found using the lsblk command and type /dev/ before it. Given the example above you would type gdisk /dev/sda. If you get an error about permissions or access, you need to run the command as a super user (likely "root"). How that is done also differs from distro to distro... but you can try putting sudo or su in front of the gdisk command. Like sudo gdisk /dev/sda. from here on I'll assume you use sudo but just substitute the tools appropriate to your distro.

After running gdisk you should see this:

GPT fdisk (gdisk) version 0.6.14

Partition table scan:
  MBR: MBR only
  BSD: not present
  APM: not present
  GPT: not present


***************************************************************
Found invalid GPT and valid MBR; converting MBR to GPT format.
THIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit by typing 'q' if
you don't want to convert your MBR partitions to GPT format!
***************************************************************


Command (? for help): 

This is important. If you do not see the message about invalid GTP and valid MBR stop here. This isn't the guide for you. Reconsider #1 and #2 instead.

If you do see this message and you are certain Windows 10 was installed in UEFI mode, then press the p key and then press Enter to print out the partition table. You're looking for a partition with the type EFI System.

If there isn't one, well... that sucks and things just got a lot less simple. You'll need to resize your partitions to make room for a new EFI partition then create the EFI partition, format it Fat32, then set the partition type to EFI System. And then you'll need to follow the previous section as well. I'm not going to walk you through using something like gdisk to resize partitions... that's scary stuff at the best of times and I would want to be the one at the keyboard. You can use gui tools like gparted to accomplish it easily and relatively safely, however.

Either way, first you need to convert the partition table back to GPT. Press the w key and then the Enter key to write changes to the hard drive.

This is the point of no return. You should see the following:

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed, possibly destroying your data? (Y/N): 

Press the y key and then Enter to re-write the partition table. Your data shouldn't be harmed. If you saw the EFI partition before then you should be able to simply reboot into Windows at this point. If not, you have more work to do.

Solution 2

You can reinstall the Windows boot manager by booting off Windows bootable media.

  • Press F8 while booting the system to go into the Windows Recovery Menu. Unlike other version Windows 8’s recovery menu has the Metro UI style.
  • Click on Troubleshoot.
  • Click on Advanced options to get into Automatic Repair menu.
  • Click Startup Repair

This will return the Windows bootloader, but remove the ability to boot Linux. You can add Linux to the boot menu by following these directions.

Share:
28,693

Related videos on Youtube

WoJ
Author by

WoJ

Updated on September 18, 2022

Comments

  • WoJ
    WoJ over 1 year

    I had an initial installation of Windows 10

    I then installed Linux in dual-boot, with grub managing the boot choices (Ubuntu, Windows 10).

    Everything works as expected.

    Is there a way to recover the Windows Boot Manager so that it is the one used to decide upon the boot choices (and boot Windows by default)? I would then look at extending it to boot Ubuntu.

    Note: I am not looking at simply setting Windows 10 as the boot default via grub - I would like ultimately to swap grub with the Windows Boot Manager.

    • fixer1234
      fixer1234 over 6 years
      @Keltari, can you confirm that the proposed duplicate applies to Win 10?