Centos – Install both BIOS and UEFI bootloaders with kickstart


I am trying to build a disk image with Koji. To do so you specify a kickstart file to be used. Since QEMU is spawning a BIOS VM, my kickstart is doing only BIOS related stuff.

My issue here is that I want this image to run on UEFI-only machines as well. How could I accomplish that with just one kickstart file? Bear in mind building always happens in a BIOS machine, so my idea is whether it is possible to "install both bootloaders" for both BIOS and UEFI so this image can run on every machine no matter what it uses.

This is the Kickstart file I am using:

ignoredisk --only-use=vda
# System bootloader configuration
bootloader --append="console=ttyS0,115200 console=tty0 inst.gpt" --location=mbr --timeout=5 --boot-drive=vda
# Clear the Master Boot Record
# Partition clearing information
clearpart --all --disklabel gpt

part biosboot --fstype=biosboot --size=1 --ondisk=vda
partition /boot/efi --fstype=efi --label EFI  --size=200
partition /         --fstype=xfs --ondisk=vda --label ROOT --size=2800 --mkfsoptions="-n ftype=1"


/usr/sbin/grub2-mkconfig -o /boot/grub2/grub.cfg
/usr/sbin/grub2-mkconfig --o /etc/grub2-efi.cfg
# We are installing bootloader with the bootloader command, but this only adds bios compatible, so we force both: https://unix.stackexchange.com/questions/273329/can-i-install-grub2-on-a-flash-drive-to-boot-both-bios-and-uefi
# Should not be necessary to add --directory=/usr/lib/grub/x86_64-efi/ /dev/vda
/usr/sbin/grub2-install --target x86_64-efi
/usr/sbin/grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg