Enable UEFI for VMs in RHEL KVM: A Practical Guide
In this article
Yes, you can enable UEFI for virtual machines (VMs) in RHEL KVM, and it is done by configuring the VM to use OVMF (Open Virtual Machine Firmware) instead of the default SeaBIOS. You enable it either at VM creation with virt-install or by editing the VM's XML definition in virsh. This guide explains the exact steps, the prerequisites, and the common pitfalls you will encounter.
Why UEFI Matters for KVM VMs
UEFI (Unified Extensible Firmware Interface) replaces the decades-old BIOS. For KVM VMs, UEFI provides several practical benefits:
- Secure Boot support: UEFI can verify the signature of the bootloader and kernel, protecting against bootkits and unauthorized modifications.
- Larger boot disks: UEFI supports GPT (GUID Partition Table), which allows booting from disks larger than 2 TB—something traditional BIOS/MBR cannot do.
- Faster boot and modern features: UEFI initializes hardware more efficiently and supports features like UEFI shell and network boot (iPXE) more robustly.
- Required for some modern OSes: Windows 11 and recent versions of some Linux distributions require UEFI (and often Secure Boot) to install.
If you are running a modern guest OS or need to boot from a disk over 2 TB, enabling UEFI is not just an option—it is a requirement.
Prerequisites: OVMF Package
The firmware that provides UEFI for KVM is called OVMF (Open Virtual Machine Firmware), a port of TianoCore EDK II. On RHEL (and its derivatives like CentOS and Rocky Linux), you must install the edk2-ovmf package:
sudo dnf install edk2-ovmf
After installation, verify the firmware files exist:
ls /usr/share/edk2/ovmf/
You should see files like OVMF_CODE.fd and OVMF_VARS.fd. The OVMF_CODE.fd is the read-only firmware code, while OVMF_VARS.fd contains the NVRAM variables (like Secure Boot keys and boot order). Some distributions also provide a separate OVMF_CODE.secboot.fd for Secure Boot enabled guests.
Enabling UEFI at VM Creation (virt-install)
The easiest way to create a UEFI VM is to pass the --boot uefi option to virt-install. This tells libvirt to use the default OVMF firmware. Example:
sudo virt-install \
--name rhel9-uefi \
--memory 2048 \
--vcpus 2 \
--disk size=10 \
--cdrom /path/to/install.iso \
--os-variant rhel9.0 \
--boot uefi
This command creates a VM with a UEFI boot. If you need Secure Boot, you can use --boot uefi,secure=yes (requires the OVMF_CODE.secboot.fd file). However, note that Secure Boot may not work with all guest OSes—Windows 11 works, but some older Linux distributions may not have signed kernels.
Enabling UEFI on an Existing VM (virsh edit)
To convert an existing BIOS-based VM to UEFI, you must edit its XML definition. First, shut down the VM:
sudo virsh shutdown vm-name
Then edit the XML:
sudo virsh edit vm-name
In the <os> section, change the firmware line to:
<os firmware="efi">
If you want to specify the exact firmware path, you can add a <loader> element:
<os>
<type arch="x86_64" machine="pc-q35-6.2">hvm</type>
<loader readonly="yes" type="pflash">/usr/share/edk2/ovmf/OVMF_CODE.fd</loader>
<nvram template="/usr/share/edk2/ovmf/OVMF_VARS.fd">/var/lib/libvirt/qemu/nvram/vm-name_VARS.fd</nvram>
</os>
After saving, the VM will use UEFI. Important: the guest OS must already have a GPT partition table and an EFI system partition (ESP) to boot. If the existing disk uses MBR, you will need to convert it to GPT and create an ESP—this is a non-trivial operation and often easier to reinstall the OS.
Choosing Between UEFI and Secure Boot
When enabling UEFI, you have two main options:
- UEFI without Secure Boot: Use
OVMF_CODE.fd. This is compatible with almost all modern OSes and is sufficient for most users. - UEFI with Secure Boot: Use
OVMF_CODE.secboot.fd. This enforces signature verification. It is required for Windows 11 and some enterprise Linux distributions that enable Secure Boot by default. It can cause boot failures with unsigned kernels or third-party drivers.
For most Linux guests, plain UEFI is enough. For Windows 10/11, you should enable Secure Boot to meet the OS requirements. Check your guest OS documentation before deciding.
Common Problems and Troubleshooting
Enabling UEFI can lead to a few typical issues:
- VM boots to a black screen or UEFI shell: This usually means the disk does not have a bootable EFI entry. Ensure the guest OS was installed in UEFI mode (the installer must have booted via UEFI). If you converted an existing BIOS VM, the disk likely lacks an ESP.
- Secure Boot prevents booting: If you enabled Secure Boot and the guest kernel is not signed, you will see a "Verification failed" error. Disable Secure Boot or use a signed kernel.
- Cannot find OVMF files: The package name may differ on non-RHEL distributions (e.g.,
ovmfon Debian/Ubuntu). Ensure the package is installed and the paths are correct. - NVram file missing: libvirt expects a per-VM NVRAM file. If it is missing, you may see an error like "failed to load nvram". Use
virsh editto specify the<nvram>path, or recreate the VM.
Verifying UEFI is Active
To confirm your VM is using UEFI, you can check the XML:
sudo virsh dumpxml vm-name | grep -E "firmware|loader"
You should see firmware='efi' or a <loader type="pflash"> entry. Inside the guest, run:
ls /sys/firmware/efi
If the directory exists, the guest booted in UEFI mode. If not, it booted in BIOS mode.
Frequently Asked Questions
Can I switch a VM from BIOS to UEFI without reinstalling?
Technically yes, but it is risky. You must convert the disk from MBR to GPT (using tools like gdisk), create an EFI System Partition, and install the EFI bootloader (e.g., GRUB2 EFI). This is error-prone and can make the VM unbootable. A fresh install is usually safer and faster.
Does UEFI affect VM performance?
No, UEFI has no measurable performance impact on the guest OS after boot. It only changes the firmware initialization phase, which is negligible in a virtualized environment.
Why does my Windows 11 VM fail to install without UEFI?
Windows 11 mandates UEFI with Secure Boot as a hardware requirement. Without it, the installer will refuse to run. You must enable both UEFI and Secure Boot in the VM settings.
What is the difference between OVMF and SeaBIOS?
SeaBIOS is the default legacy BIOS implementation used by KVM. OVMF is the UEFI firmware. SeaBIOS is simpler and compatible with older OSes, but lacks GPT boot support and Secure Boot. OVMF is the modern standard.
Can I use UEFI with a non-x86 architecture?
Yes, UEFI is architecture-independent. On ARM64 (AArch64) hosts, you would use the AAVMF firmware (a port of OVMF for ARM). The configuration is similar, but the package name and paths differ.
Does enabling UEFI require a special disk controller?
No, UEFI works with any disk controller supported by KVM (virtio, SATA, IDE). However, for best performance and to meet Windows 11 requirements, use virtio-scsi or virtio-blk.