Reconstructing Windows EFI files in /boot partition (Linux+Windows dual boot)

15

9

I'm dual booting Windows 10 (pre-Anniversary Update) and Fedora 24 on a Lenovo IdeaPad N580 (Intel Pentium B960 2.2GHz, 4GB RAM, UEFI with Secure Boot disabled). I originally had just Windows 10 and then installed Fedora 23 alongside it and everything worked fine - it worked as well when I upgraded to Fedora 24. A while back, I decided I wanted to try out Ubuntu, and installed it only overwriting the root, /boot and SWAP partitions and keeping my home partition. Windows 10 can still boot here. Then I decided I didn't like Ubuntu and reinstalled Fedora, with the 24 installer, trying to do exactly what I did with Ubuntu. The interface was a bit different, but I'm sure I did it correctly: after I did all the partition configuring, it gave me a popup saying "We will only touch these partitions," and the partitions it listed were root, /boot and SWAP. Nothing else.

Then, when it finished installing, I rebooted. The only options in the GRUB menu were Fedora and Fedora Recovery - nothing else. No Windows.

I tried installing rEFInd, which has worked for me in the past. But it didn't help, it gave me those same two options.

The Windows partition still exists and I can access it from Fedora - important files such as /bootmgr and /Boot/BCD seem intact. The Windows partition is at /dev/sda5.

As well, in the BIOS settings where Windows Boot Manager used to appear, it doesn't. It just has rEFInd and an entry with the model number of my hard drive - which I'm assuming just brings me to the GRUB menu. (I haven't actually tried bringing it to the top of the list and rebooting though - I'm a bit lazy :P)

Can someone help?

UPDATE: Manoj Sawai identified the issue: by formatting the /boot partition I was getting rid of the Windows EFI files. So I need to reconstruct the files at /boot/efi/EFI/Microsoft. I think I've reconstructed the directory /boot/efi/EFI/Microsoft/Boot, but I need the other files in Microsoft. Could someone tell me what files I need there?

TheInitializer

Posted 2016-08-06T21:56:56.790

Reputation: 231

2is there a Microsoft folder in your /boot/efi/EFI? There is a chance that you may have formatted /boot which also removed the windows 10 efi files. – Manoj – 2016-08-09T14:20:34.650

@ManojSawai No there isn't. Could that be the problem? (I did format /boot) – TheInitializer – 2016-08-09T14:41:49.780

/boot/efi/EFI/Microsoft/Boot contains some efi ( see here : http://imgur.com/a/5ZZnc ) which are required for booting up windows. I will do some more research and let you know if it is possible to get the original contents of /boot back. – Manoj – 2016-08-09T15:07:26.873

@ManojSawai That looks exactly like what I have in my Windows partition/Boot folder! http://storage9.static.itmages.com/i/16/0809/h_1470755614_2146806_f9d292f7e1.png (left is my Windows partition/Boot, right is your screenshot) Do you think I could just copy all those files over?

– TheInitializer – 2016-08-09T15:14:22.097

oh, the bootmgfw.efi, bootmgr.efi and memtest.efi aren't there... – TheInitializer – 2016-08-09T15:20:56.473

THOSE FILES ARE IN windows partition/Windows/Boot/EFI!!! – TheInitializer – 2016-08-09T15:24:28.207

Since you didn't do a backup (why?), you should modify your question. "How do I recreate windows UEFI boot files?" – Xalorous – 2016-08-09T15:32:01.383

@TheInitializer - Do you have a windows bootable usb or dvd ? – Manoj – 2016-08-09T15:34:50.207

I made up an EFI folder from files I found on my windows partition, think it'll work? http://storage2.static.itmages.com/i/16/0809/h_1470756878_5524420_291ca42dab.png

– TheInitializer – 2016-08-09T15:44:40.837

@Xalorous I did do a backup, but only of my home folder because a full backup was taking too long and too much space – TheInitializer – 2016-08-09T15:45:32.277

@ManojSawai no, I might be able to make one though, but I want to try my homemade folder first :D – TheInitializer – 2016-08-09T15:47:00.683

@ManojSawai are there any other files inside /boot/efi/EFI/Microsoft other than the Boot folder? – TheInitializer – 2016-08-09T15:53:16.010

@ManojSawai Before overwriting /boot on any system that you are not wiping, I would advise to back up the whole partition. They're generally tiny, and a backup would take just moments. Best results using an offline method. E.g. boot to a live disk and make a tarfile copy of the /boot partition. You may even be able to recreate the files you need by creating this tarfile from a working computer with the same setup you had, or with the setup you want. – Xalorous – 2016-08-09T15:57:14.327

@Xalorous my backup took about 20 hours to get to about 50%, so... – TheInitializer – 2016-08-09T16:00:23.197

@ManojSawai was suggesting you copy the files from a bootable source. I saw that your backup did not work. The problem is that there's always more than one way to achieve a goal. Your description leads me to believe you're using a backup software which is probably doing a block storage backup. This copies every bit in every used block. /boot has, at most, a few megabytes in it. The simplest way of backing it up is to copy the files and structure to another location. The most practical way of doing it is creating a tarfile in a different location. More than a minute and something is broken. – Xalorous – 2016-08-09T16:09:04.817

Answers

18

Since you have copied all the required files to boot/efi/EFI/Microsoft/Boot, you need to rebuild windows loader configuration. You will need a windows bootable usb or dvd (64 bit will be preferable).

1 : Boot from your bootable medium. Make sure that you are booting in UEFI mode.

2 : At the first screen (where it asks you to choose language and keyboard), press Shift + F10. This will give you a command prompt.

3 : Type diskpartand then list disk (to list all available disks). Select appropriate hard drive by typing select disk #.

4 : Now type list partition and make sure that there is a partition of type system (the efi partition). Select this partition by typing select partition # and assign a temporary drive letter to it, say G by typing assign letter=G.

5 : Just to make sure that drive letter is correctly assigned, type list vol. You should see a volume with drive letter (Ltr) as G & file system (Fs) as FAT32

6 : Close diskpart by typing exit. Make sure that you are in X:\Sources.

7 : Type cd /d G:\EFI\Microsoft\Boot\. Now run these commands one by one.

bootrec /scanos     
bootrec /fixmbr    
bootrec /fixboot
bootrec /rebuildbcd    
bcdboot C:\Windows /l en-us /s G: /f ALL

8 : Close the command prompt and restart the system. You should now be booting into windows.

9 : Of course you may not or don't have the grub menu now. But installing grub is far more easy. Follow any one of these links for more info.

link1, link2, link3

Sources : 1, 2, 3, 4.

EDIT - Make sure that you remove the drive letter G assigned to efi partition as soon as possible to keep it from showing up in My Computer.

Manoj

Posted 2016-08-06T21:56:56.790

Reputation: 642

Thank you, but I don't have a recovery USB (kinda stupid of me) and I can't create one without access to Windows. I'll try to find a way to make one – TheInitializer – 2016-08-09T17:12:49.910

1Thanks you so much, this worked!! Posting from Windows :D – TheInitializer – 2016-08-15T00:33:34.320

1bootrec /rebuildbcd failed for me but it worked anyway after I skipped it. – en4bz – 2016-11-05T02:34:32.907

1

Thanks for the Source links, helped understand and apply only the necessary. Afterwards to get rEFInd bootloader loading again I used bcdedit as described here : bcdedit /set "{bootmgr}" path \EFI\refind\refind_x64.efi

– Pau Coma Ramirez – 2018-09-04T16:05:45.727

What can you do if your partition isn't listed by list disk? – Harsha Goli – 2019-06-13T05:32:19.893

@HarshaGoli - I don't know. Can you share a photo of the output where list disk doesn't list any partition? – Manoj – 2019-06-13T14:12:20.240

As a remark to anyone who has issues with creating a bootable windows stick under linux: Download the official iso from the microsoft site and copy it onto your usb stick using the tool woeusb. I was trying dd and other things but only this approach has worked. Following the above steps afterwards helped to reconstruct the dual boot. – apparat – 2020-01-29T10:10:40.870

0

Before starting back up your boot partition using mkdir $HOME/backup && sudo cp -R /boot $HOME/backup. Boot partition is usually limited to 100MB so it should be really small.

If you still have a Windows 10 bootable medium (like a USB stick or a DVD), you will be able to find the EFI files over there.

If you don't have a Windows bootable medium you can mount the ISO (download if necessary) using the command sudo mkdir /tmp/win10iso && sudo mount -o loop /location/of/win10.iso /tmp/win10iso.

When you successfully copied those EFI files to the Windows partition add an entry to the file /etc/grub.d/40_custom.

The entry would look like this:

menuentry 'Windows 10' {
set root='(hd0,msdos5)'
chainloader +1
}

In GRUB configuration the hdX stands for /dev/sdX and msdosY stands for /dev/sdXY. Note that hdX starts at 0 and /dev/sdX starts at A.

After that's done, update your GRUB with sudo update-grub2. Windows boot entry should now be there.

Condor

Posted 2016-08-06T21:56:56.790

Reputation: 55

Thanks, I'm downloading the ISO right now (it's a big file!) – TheInitializer – 2016-08-09T18:21:23.010

I've mounted the ISO, and have a question - which files am I supposed to copy, and to which folder? My guess is from Windows ISO/boot to /boot/efi/EFI/Microsoft, but I'm really not sure. – TheInitializer – 2016-08-09T21:19:41.710