Skip to Content

How to Enable UEFI Mode in RHEL KVM

RHEL KVM, a Type 1 hypervisor, is a robust and user-friendly platform that transforms an ordinary computer into a virtualization powerhouse. It can host multiple VMs simultaneously. One of its key features is the ability to boot UEFI-only systems in Linux, extending its capabilities.

Advantages of UEFI in KVM

UEFI in KVM opens up the possibility of using modern operating systems in a virtual environment. For example, it enables the installation of Windows 11 on a virtual machine. Additionally, it provides a platform to test various OS configurations. It can be used to verify if partition layout schemes are compatible with real hardware.

How to Enable UEFI Mode in RHEL KVM

Setup UEFI Support

To enable UEFI in KVM, first ensure your system is up-to-date:

sudo dnf update

Install and enable the KVM subsystem and packages:

sudo dnf install module virt
sudo dnf install virt-install virt-viewer
sudo systemctl start libvirtd

Next, install the UEFI firmware for your KVM:

sudo dnf install edk2-ovmf cockpit-machines

Ensure the Cockpit daemon is running:

sudo systemctl enable --now cockpit.socket

Reboot your system to load the new firmware.

sudo reboot

Create a UEFI-Enabled VM in RHEL Cockpit

Access your machine’s Cockpit dashboard using a web browser.

http://localhost:9090

Log in with your root or superuser account and select Virtual Machines. Click Create VM, fill in your VM details, and press Create and Edit.

Under the Overview section, click the BIOS link. A dropdown menu will appear where you can select UEFI for your VM’s firmware. Save your changes.

It’s crucial to set the firmware before the first boot of your VM, as changes are not permitted after startup.

In a new terminal session, create a nvram directory under /var/libvirt/qemu

sudo mkdir /var/libvirt/qemu/nvram

Copy the non-Secure Boot UEFI variables from the default EDK2 directories to your KVM’s NVRAM

 sudo cp /usr/share/edk2/ovmf/OVMF_VARS.fd /var/lib/libvirt/qemu/nvram/YOUR-VM-NAME_VARS.fd

Click Install to boot your VM in UEFI mode.

To verify if your system is running in UEFI mode, open a terminal and run

 ls /sys/firmware/efi

This should display the contents of the EFI variables for the current system. For Windows 10 and older, check this by pressing Win + R, entering the following command on the Run prompt:

msinfo32.exe

Scrolling to the line that starts with BIOS Mode in the System Information window.

Constructing a UEFI-Enabled VM via Command Line

In addition to the Cockpit interface, a UEFI-enabled VM can be set up directly from the terminal. This approach is beneficial if you prefer not to install extra dependencies on your system.

To proceed, initiate a new terminal session and copy the non-Secure Boot UEFI variables to your KVM’s NVRAM directory using the following command:

sudo cp /usr/share/edk2/ovmf/OVMF_VARS.fd /var/lib/libvirt/qemu/nvram/YOUR-VM-NAME_VARS.fd

Next, input the following command into your terminal:

sudo virt-install \
    --graphics vnc \
    --name YOUR-VM-NAME --memory 4096 \
    --vcpus 2 --disk size=40 --boot uefi \
    --cdrom /PATH/TO/YOUR/INSTALLER/FILE.iso

Ensure to replace the –name value with the name you’ve assigned to your UEFI variables. Adjust the –memory–vcpus, and –disk size flags according to your VM requirements.

Note: The –memory flag interprets values in megabytes, while the –disk size flag sets it in gigabytes.

Press Enter to execute virt-install and initiate your UEFI VM.

To access your VM’s graphical screen, open virt-viewer with the following command:

sudo virt-viewer YOUR-VM-NAME

To verify that your system is operating in EFI mode, list the contents of /sys/firmware/efi.

Creating UEFI-mode KVM virtual machines in Linux is one of the many capabilities of virtualization technology. It provides a flexible and powerful platform for managing and running multiple operating systems concurrently.