EFI Edit / Boot Fix With Windows


EFI Partition Recovery


As I was trying to reinstall the windows system to recover some problems with hyperv environment, the “correct” efi partition was accidentally removed and the computer was not able to boot into new installed system.

Windows


For windows, if you can still access to the windows boot loader but not the right one. You can get into Windows Recovery Environment by booting the machine while keep pressing F11. (Or hold shift while restarting the system which is not suitable for this case) Then you can select “Troubleshoot” at the menu with advanced option at the submenu.

Firstly, you may want to try a automatic repair. There would be a “Start up setting” over there and follow the instructions to repair it.

If it doesnt work, you may need some command line work to bring your pc back. Follow the same instruction with previous steps until you reaches the “Advance Options”. This time selects “Command Prompt” instead.

diskpart
list disk

list_of_disks
The result would be similar to this pic above. For me, Disk 0 is the system drive, you need to determine which one is your’s while you are repairing.

select disk 0
list vol

list_of_Volumes

Things will be different here.

If you can find a partition with the FAT32 filesystem and a small size, like Volume 5 here, it should be an EFI partition.

select vol 5
Assign letter=X:
exit

If you can’t, select the volume with your system, and do following instructions.

select vol 
shrink desired=500

Right now, the space for new EFI partition is reserved. And we need to acutally create a new one now.

select disk 0
create partition primary size=500
Assign letter=X:
exit

For both situation, you can choose any other letter which are not using in your system to replace X here.

X:
bcdboot C:\windows /s X: /f UEFI
exit

You can try restarting your PC, and the problem should be solved.

If the drive labeled ‘X’ still exists, you can access “Disk Management” by searching for it. Once it is opened, right-click on the ‘X’ partition, select “Change Drive Letter and Paths,” and then click on “Remove.” That should take care of it.

Linux


If you got a linux system installed on the machine as well.

$ sudo os-prober
$ sudo update-grub

This may solve the problem by adding windows to Linux boot system.

If it doesnt work, you may try following.

Firstly, check which partition Windows locates

$ sudo blkid /dev/sda1

Replace it with sda1 here. It would show UUID over here after it finished.

$ sudo nano /etc/grub.d/40_custom

Add following to the end of the file and save it.

menuentry "Windows 10" --class windows --class os {
   insmod ntfs
   search --no-floppy --set=root --fs-uuid $your_uuid_here$
   ntldr /bootmgr
}

Update the grub and restart, problem should be solved

$ sudo update-grub
$ sudo reboot

  TOC