How to reinstall Windows Boot Manager on EFI partition

So I've been trying to install Ubuntu on a second HDD on my desktop, which has W8 installed on a SSD (UEFI-only boot). Thing is, during Ubuntu installation I made the mistake of choosing to install the bootloader (GRUB) to the first disk (the SSD), and after install I could not boot into W8 (the entries in GRUB didn't work). Following these instructions, I managed to be able to get "Windows Boot Manager" back, however I lost GRUB in the process, and got a duplicate "Windows Boot Manager" entry in BIOS, along with the "Ubuntu" entry, which then I used to boot into Ubuntu.

Later, I decided to reinstall Ubuntu, and formatted the HDD from within windows, however, the entries in BIOS stayed the same, and, while I had the HDD connected to the motherboard, I could not boot into an Ubuntu Live USB (in order to reinstall Ubuntu).

I made another mistake by updating the BIOS, which cleared all of the EFI boot entries in BIOS, and, right now, I get an error when boot from the SSD:

grub: device not found (...)

So it seems that grub is still installed in the EFI partition of the SSD, and since I don't have the WBM entry in BIOS anymore, I cannot even boot into Windows, and the previous instructions don't work anymore. Is there another way to reset W8 EFI partition to the default?


Solution 1:

I am surprised that running manually bcdboot against the ESP did not perform the trick; in fact, it could even been seen as a bug of it (meaning to be reported to Microsoft.) Are you 200% sure that you identified correctly what your firmware believes is the system partition?

The EFI system partition is not the only place to clean, the EFI variables (controlled by the UEFI firmware) could also be corrupted, particularly since you mentioned the BIOS reinstall had adverse effects. bcdedit /storeP:\ath\to\BCD\file\on\mounted\efi\part/import /clean (from the command prompt of the advanced options of W8 recovery) is the Windows' way to clean its cached copy, which copy is what you are really seeing on Windows boot manager screen; Linux offers, through efivars, even more powerful tools over them.

While you are here, follow Rod's advice and check thoroughly the output of bcdedit /storeP:\ath\to\BCD/enum all for unneeded or misplaced entries, which you could try to dispose of after having made a backup of the BCD file.

If you consider only Windows, the organization of the ESP is straightforward: besides the mighty Bootx64.efi, everything is under the \EFI\Microsoft\Boot\ directory. The only file you might edit is the BCD, through bcdedit. To be able to boot, you need just \EFI\Boot\Bootx64.efi, \EFI\Microsoft\Boot\BCD, and \EFI\Microsoft\Boot\boot.stl on the ESP, assuming the former is a copy of \EFI\Microsoft\Boot\bootmgfw.efi; keeping this later is a good precaution, particularly since you are considering the installation of other boot managers which could replace the mighty Bootx64.efi (but should generally left untouched bootmgfw.efi.) During the boot process, some (hidden) BCD.log* and BOOTSTAT.DAT files will be automatically created in \EFI\Microsoft\Boot\. You might also see \EFI\Microsoft\Boot\bootmgr.efi, although nobody seems to know what it is good for... The ll-CC directories with the MUI resources help to be able to display non-English messages instead, depending of the settings in BCD; similarly, the fonts could be needed for non-Latin cases; I found out that removing all this i18n stuff for cleaning purposes, did not help on the long run, since I use to turn them back in place, to get back my own language while booting.

Solution 2:

It's hard to say what the best recovery method is without knowing precisely what boot loaders are installed on the hard disk; however, one tool that might help is my rEFInd boot manager. You can get a USB flash drive or CD-R image of rEFInd, prepare it, and then boot from it. The result should be a menu showing you all your boot loaders, which you can then try. With any luck, you'll be able to get into both Linux and Windows that way. Once you're into an OS, you can use its tools (efibootmgr for Linux, bcdedit for Windows) to re-set the default boot manager as you like it; or you could install rEFInd instead, if you like it.