Recovering a Windows 10 EFI Image

The other day I installed linux on my computer and I accidentally deleted the EFI partition. This means that the previous efi images were wiped, and I could not boot to my existing Windows 10 installation. Here I will show you how to fix that.

Preparation

To cleanly restore the efi entry, you must first flash a windows 10 ISO to an external USB.

The way to do this can vary. If you’re in a windows installation, you can use the method provided by microsoft.

On linux you can use a utility named WoeUSB. In theory, regular flashers won't work. To install woeUSB you can use the AUR if you’re on arch. Otherwise follow the installation instructions on the GitHub page.

Firstly, delete any partitions in the USB stick you want to flash. To flash the windows image, type the following:

sudo woeusb --target-filesystem NTFS --device Path_To_Windows.iso /dev/sdX

Where X is a letter. To Find out said letter, you can use lsblk, for example.

Make sure you are flashing to the correct device, as it will destroy everything.

Note that the process will take a while.

Booting the Windows 10 installation

Insert the USB into your PC and boot it (you may have to change your BIOS settings). Then, on the installation screen, press SHIFT+F11, or select the options from the menu to launch a terminal.

Type the following:

diskpart
list disk
sel disk<number>
list vdol
sel vol<number>
assign letter=S
exit
bcdboot C:\Windows /s S: /f ALL

The disk number must be the one with the EFI partition. The volume selected must be the one with the EFI partition. Note that the letter C may not be where your windows installation is. In that case, replace it with the appropiate one.

If no error ocurred, you’re probably set.

Creating the bootloader entry

Reboot your machine into Linux.

First check you have the files in your efi partition. Mine was in /boot. If there’s a microsoft folder somewhere, the operation was successful.

Now you must make it so your bootloader detects said image.

I use GRUB with arch, so if that’s your case too, first run os-prober, and then regenerate your grub config with grub-mkconfig -o /boot/grub/grub.cfg.

If you use a different bootlader, search how you can do this part.

Reboot to your BIOS to check if there’s a windows option on your bootloader.

That should be all.