How to make EFI grub2 chainload to legacy Windows

How to make EFI grub2 chainload to legacy Windows

Efter reinstalling Fedora, I cannot persuade grub2 to boot Windows.

I have a system with a 1TB harddisk (HD) and a 500GB solid state disk (SSD).

If I ask the bios to boot from SDD then Windows starts.

If I ask the bios to boot from HD then first grub2 and then Fedora starts.

But I cannot persuade grub2 to boot Windows.

I installed Windows and then Fedora five years ago using msdos partitions on both disks. Then my Fedora became unstable and tainted, so I decided to make a fresh install of Fedora, leaving Windows as it was. So I downloaded a fresh Fedora 30/spin xfce installer to a USB stick, asked the installer to wipe my Fedora partitions, and left partitioning to the installer.

BACKGROUND:

Mapping:

/dev/sda = grub hd0 = 1TB HD
/dev/sdb = grub hd1 = 500GB SDD

What Fedora has to say

> cat /etc/fedora-release
Fedora release 30 (Thirty)
> sudo fdisk /dev/sda
...
/dev/sda1                2048  908550143  908548096    433,2G  7 HPFS/NTFS/exFAT
/dev/sda2          1932550144 1953521663   20971520       10G 27 Skjult NTFS Win
/dev/sda3  *        908550144  908959743     409600      200M  6 FAT16
/dev/sda4           908959744 1932550143 1023590400    488,1G  5 Udvidet
/dev/sda5           908961792  911058943    2097152        1G 83 Linux
/dev/sda6           911060992 1932550143 1021489152    487,1G 8e Linux LVM
...
> sudo fdisk /dev/sdb
...
/dev/sdb1  *            2048   2099199   2097152        1G  7 HPFS/NTFS/exFAT
/dev/sdb2            2099200 732899327 730800128    348,5G  7 HPFS/NTFS/exFAT
/dev/sdb3          732899328 937701375 204802048     97,7G 8e Linux LVM
...
> sudo head -c 11 /dev/sdb1 | tail -c 8
NTFS
> sudo ls /boot/efi
'$RECYCLE.BIN'	 EFI   mach_kernel   System  'System Volume Information'
> sudo ls /boot/efi/EFI
BOOT  fedora
> sudo ls /boot/efi/EFI/fedora/grub.cfg
/boot/efi/EFI/fedora/grub.cfg

What grub2 has to say

grub> ls
(hd0) (hd0,msdos6) (hd0,msdos5) (hd0,msdos3) (hd0,msdos2) (hd0,msdos1)
(hd1) (hd1,msdos3) (hd1,msdos2) (hd1,msdos1)
(hd2) (lvm/fedora_localhost--live-root) (lvm/fedora_localhost--live-home)
      (lvm/fedora_localhost--live-swap)
grub> ls (hd0,msdos3)/
efi/ System/ mach_kernel/ System Volume Information/ $recyclebin/
grub> set root=(hd1,msdos1)
grub> chainloader +1
error: ../../grub-core/loader/efi/chainloader.c:156:invalid EFI file path.

PROBLEM:

As said, I cannot persuade grub2 to boot Windows.

I try to boot Windows from the grub command prompt (if I tamper with
/etc/grub.d/40_custom I often end in a state where I have to reboot from
my USB stick and replace /boot/efi/EFI/fedora/grub.cfg by a backup).

If I read the invalid EFI file path error correctly, grub2 is in some sort
of “EFI” mode and refuses to chainload to a legacy disk.

When I boot from SDD, Windows clearly boots from the MBR of the SDD.

When I boot from HD, I have no idea how grub2 is invoked.
But I have asked the bios to try legacy mode first and then EFI.

QUESTION:

Is there a way to persuade grub2 to boot Windows in my situation?

Or do I have to make yet another fresh install of Fedora 30, wiping my
Fedora partitions, and making some clever choice (which) other than
automatic partitioning?

Hi @grue! As far as I understand, there’s one possible variant when grub wouldn’t detect and wouldn’t boot Windows installation.

Basically as you know, you can boot your machine either in UEFi mode (and it’s default for newer machines) or in Legacy/BIOS mode. For all your OSes to be visible to and bootable by grub you need both systems and grub to be installed in either UEFI or legacy/BIOS mode – i.e. in one and the same mode. If even one of them uses different mode – then you’ll have exactly the issue you’re describing.

Judging from this, your Fedora installation (and grub too) use UEFI mode. And from your description it looks like your Windows install (and, I think, previous Fedora install too) was indeed done using legacy mode – and that’s the core of your problem.

Now in this case I’m not sure you can force grub to boot “legacy” installation (I’ve never tried and never researched’ if it’s possible). So maybe it’s indeed easier to reinstall Fedora using legacy/BIOS boot.

But you should first ensure that you Windows installation does indeed use legacy/BIOS boot and not UEFI.

Hi @nightromantic,

Thanks for your input.

Since last, I have done this experiment: When I disable UEFI boot in the bios, I can boot Windows but not Fedora. When I disable legacy boot in the bios, I can boot Fedora but not Windows. So your assumptions seem to be right.

I have found two references which say that mixing UEFI and legacy boot is impossible with grub2 (cf the end of this post). So I think your conclusion is also right: reinstalling Fedora using legacy/BIOS boot seems to be the way to go.

But how?

I have found no instructions on how to install Fedora using legacy/BIOS boot except (https://medium.com/@greg_harvey/fedora-linux-and-legacy-bios-c524c18ae673) which did not work. (Note that the link above only works first time you click it; second time you are requested to create a login). The method in the link tells to create a 2MB “BIOS Boot” (biosboot) partition using the advanced partitioning gui of the installer. But when I run the installer, the advanced partioning gui offers many kinds of partitions, but no biosboot.

Here come the references about not mixing boot method.

(https://docs.fedoraproject.org/en-US/Fedora/23/html-single/Multiboot_Guide/index.html) says:

Be Consistent!

Be consistent with your booting methods when using multiple operating systems. If Windows is installed with UEFI, do not install Fedora in legacy BIOS compatibility mode. Installing all of your operating systems as either UEFI or BIOS booting will ensure that you can boot them all.

(https://askubuntu.com/questions/923327/chainloading-legacy-windows-7-bootloader-from-efi-grub2) says:

Chainloading Legacy Windows 7 bootloader from EFI Grub2?


This is not possible with Grub, but rEFInd is able to do that, take a look at rodsbooks.com/refind/index.html . mook765

@grue, I’ve never tried mixing UEFI and non-UEFI installs on one machine, as I always knew it’s a bad idea, it never occurred to me – and because of that I’ve never tried to find out, if it’s possible to load non-UEFI os from UEFI grub.

Now you know too and you would know to check next time.

It’s very-very easy, really. Fedora installation medium is universal, it works both in UEFI and Legacy mode. So the key is just… to boot it in the right mode in the first place – and that’s all ))) Then you just install it as usual, you can do it exactly as you did last time. And if you choose to replace your existing installation it should create all the necessary partitions including BIOS boot one.

You can also partition you drive manually (for example, to keep your /home partition with all it’s data), if you decide to do it this way I’ll try to help with partitions.

Now for ensuring you start your installation media in the right mode. The simplest way would be to disable UEFI boot completely in BIOS settings – as your Windows also uses Legacy mode, it looks like you really don’t need UEFI booting enabled at all.

Without completely disabling it, on all the notebooks/pcs I’ve seen, BIOS boot menu gives you a hint about boot mode, like this:

UEFI: Sandisk USB...
Sandisk USB...

I.e. it gives two options for booting from one USB drive you have plugged in, and one of them is clearly marked as UEFI boot.

And one more tip, specific to Fedora this time.

When you boot Fedora Live USB, you’re presented with a boot menu, that includes items like

Start Fedora
Test this media and start Fedora
Troubleshooting

When Fedora Live USB is started in legacy/BIOS mode, then this menu has cool graphical background, and also under Troubleshooting you have two further choices:

Start Fedora in basic graphical mode
Memory test

And when Fedora Live USB started in UEFI mode, graphical background isn’t there, you just have white text choices on a black screen, and also under Troubleshooting there’s NO Memory test option.

And the most technical tip of them all for Fedora (and any Linux distribution, I think). Once you’ve booted your Fedora Live USB – but prior to starting the installation process! – you can open terminal and run this command, it’ll tell you if Linux currently running in UEFI (EFI) or Legacy/BIOS mode:

test -d /sys/firmware/efi && echo EFI || echo Legacy

Once you’re sure you now running in legacy mode, just start the installation and proceed as usual. Fedora itself and grub will be installed in legacy mode – and after that grub should automatically pick up your Windows install, as it did previously.

Hi @nightromantic,

Great! Thanks for all the info!

I will now test it and (hopefully :slight_smile:) come back in a couple of hours.

Cheers,
Klaus

Klaus, you’re welcome!

I’m quite sure all will be alright) But if you have more questions – don’t hesitate to ask.

Regards,
Alexey

Hi @nightromantic,

Thanks again. Everything worked.

Except that I had no cool graphical background in legacy/BIOS mode (maybe because I use the xfce spin? maybe because I have a 4k monitor? Don’t know.) I think your last suggestion was the safest one:

test -d /sys/firmware/efi && echo EFI || echo Legacy

I have assembled some lessons learned below for the sake of others with the same problem

Cheers,
Klaus


Lessons learned

  • Fedora uses grub2 as bootloader. At the time of writing, grub2 is either installed in UEFI or in Legacy mode.

  • If grub2 is installed in UEFI mode then it cannot boot operating systems which are installed in Legacy mode and vice versa.

  • Anaconda (the Fedora installer) silently chooses to install grub2 in UEFI mode if the install medium is booted in UEFI mode and likewise for Legacy mode.

  • Thus, if you have one or more operating systems on your computer which you want to keep, then you should find out whether they are installed in UEFI or Legacy mode and then boot the install medium in that mode.

  • When you are up and running in Fedora, you can check what mode you are in using this shell command:

test -d /sys/firmware/efi && echo EFI || echo Legacy
  • Don’t forget to read the selected answer.
2 Likes

A little late to this, but I’d highly recommend that at some point you convert both installs to UEFI. It’s generally an improvement, but in particular, it avoids the classic issue where updating Windows wipes out the Linux bootloader (UEFI is built to support multiple bootloaders installed at once).

1 Like

Am I right there’s no easy way to convert Windows existing installation, you’ll have to reinstall it? Than it can be a major pain in the backside, especially if the installation is several years old, contains all the programs user needs, configured just right, etc.

I don’t mention reinstalling Fedora, that’s easy)

But if you decide you want/need to reinstall Windows (which is quite useful with Windows once in a while), then yep, UEFI if the way to go. And for future installs too.

@refi64 I agree that in theory UEFI is the way to go. But after Googling “windows 10 upgrade legacy to uefi” and reading a lot, I gave up. I admit it seems easy to repartition a disk from mbr to gpt without data loss. Microsoft even provides a way to automate the task if you have to do it for lots of pc’s. But I fear that only changes the partitioning.

@nightromantic I think the answer to “Am I right there’s no easy way to convert Windows existing installation, you’ll have to reinstall it?” is “yes”, c.f. https://answers.microsoft.com/en-us/windows/forum/windows_10/converting-from-bios-legacy-to-uefi-how/33366c44-1f5c-4a7a-8837-cb9feb663e1f