I've got a strange situation at work, and I have about 700 systems that all are booting to EFI by default.

I have a PXE menu set up, and I can install CentOS - but the units need to swap to Legacy booting mode to continue in our process.

This presents a problem; once CentOS 7.4 is laid down in UEFI installer mode, it will not boot when the BIOS is swapped to Legacy mode.

How can I force CentOS 7.4, in an automated way, to do a Legacy-style bootloader install while running in UEFI mode?


Yes. You can set the platform using --target option with grub2-install as follows

grub2-install --target=i386-pc /dev/sdX

i386-pc option creates a legacy grub installation even in a UFI booted platform.

NOTE You must have a small 1Mb unformatted partition with bios-boot flag while installing legacy style grub with gpt partition table.

You must also have grub create a config file, and then because the installer is in EFI mode, you must replace instances of EFI keywords with Legacy ones. Here is an example using awk:

#EXAMPLE: Normal grub make config command
#grub2-mkconfig > /boot/grub2/grub.cfg

#With awk statement to replace EFI keywords with legacy ones:
grub2-mkconfig |awk '{gsub("linuxefi /", "linux /");gsub("initrdefi /", "initrd /");print $0}' > /boot/grub2/grub.cfg
  • 1
    +1 without the bios-boot partition the grub installation will fail. – GAD3R Jan 13 '18 at 16:38
  • I'm having a hell of a time getting this to work. The system reboots to a grub rescue prompt - grub2-install --target=i386-pc /dev/sda also doesn't place a grub.cfg. When I make it manually, it makes it with EFI linux references. – Locane Jan 14 '18 at 22:25
  • @Locane Use grub2-mkconfig and redirect the output into grub.cfg. It'll auto detect all installed OSs (including Windows, if any) and will generate grub.cfg for you.. grub2-install is not supposed to generate the configuration. – Abhik Bose Jan 15 '18 at 0:08
  • Thanks @AbhikBose - I actually got that far (in my comment it says "when I make it manually") - it auto-detects EFI style installation, so the terms "linuxefi" and "initrdefi" replace "linux" and "initrd" respectively. I was able to get it to work by awking the output and just gusb()ing the terms; so linuxefi->linux and initrdefi->initrd. – Locane Jan 15 '18 at 1:53
  • Can you edit your answer to include those two steps? "grub2-mkconfig > /boot/grub2/grub.cfg" and replace all instances of "linuxefi" with "linux" and "initrdefi" with "initrd"? – Locane Jan 15 '18 at 1:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.