Skip to the content
Fabian Lee : Software EngineerFabian Lee : Software Engineer
Cloud Operations and Development
  • Monitoring
  • Logging
  • Containers
  • Python

KVM: Building the latest OVMF firmware for virtual machines

September 12, 2018
Categories: Linux

OVMF is an open-source project that implements the Unified Extensible Firmware Interface (UEFI) specification.  UUEFI is designed to eventually replace the BIOS firmware interface.

In this article, I will show how to build the latest OVMF image from source.

Get OVMF source, make

Install the required packages [1, 2, 3].

$ sudo apt-get install build-essential git uuid-dev iasl nasm python3-dev python-is-python3 -y
$ sudo apt-get install iasl -y

Now go into the source directory, and run a make which populates the “Conf” directory.

$ mkdir -p uuefi; cd uuefi
$ git clone https://github.com/tianocore/edk2.git
$ cd edk2

# download git submodules, make tools
$ git submodule update --init
$ source ./edksetup.sh
$ make -C BaseTools/

Build use target settings

You need to specify which version of OVMF you want to build, there are two ways to do that. First, you can simply specify them as parameters to the build like below:

$ build -a X64 -t GCC5 -b RELEASE -p OvmfPkg/OvmfPkgX64.dsc

OR you can modify ‘Conf/target.txt’ with these same values. Here we are setting the values to generate a 64 bit using gcc 5 just like the command line above.

$ sed -i -e 's/^TARGET_ARCH.*/TARGET_ARCH = X64/' Conf/target.txt
$ sed -i -e 's/^TOOL_CHAIN_TAG/TOOL_CHAIN_TAG = GCC5/' Conf/target.txt
$ sed -i -e 's/^ACTIVE_PLATFORM.*/ACTIVE_PLATFORM = OvmfPkg\/OvmfPkgX64.dsc/' Conf/target.txt

$ build

When build finishes successfully, the final OVMF images are in the ‘Build’ directory.

# show relative path to image
$ find Build -name OVMF.fd
Build/OvmfX64/RELEASE_GCC5/FV/OVMF.fd

Validation with QEMU

As a validation that this is a usable firmware image, let’s run a quick smoke test using QEMU, an open-source emulator/virtualizer.

$ sudo apt-get install qemu-kvm qemu libvirt-bin virt-manager virtinst bridge-utils cpu-checker virt-viewer
$ qemu-system-x86_64 -bios Build/OvmfX64/RELEASE_GCC5/FV/OVMF.fd

This will automatically use the virt-viewer and show you a screen that looks like the screenshot below:

 

If you are interested in using this image to boot a VM on KVM, read my article here.

If you have to restart the host and have issues with reaching grub and only the UEFI shell is displayed, then read here.

 

REFERENCES

http://www.linux-kvm.org/page/OVMF

http://www.linux-kvm.org/downloads/lersek/ovmf-whitepaper-c770f8c.txt (whitepaper)

https://wiki.ubuntu.com/UEFI/EDK2 (building OVMF from source)

tianocore, TianoCore open source UEFI implementation

https://github.com/tianocore/tianocore.github.io/wiki/OVMF (source code)

https://www.kraxel.org/repos/ (prebuilt binary images, no need to build)

https://github.com/tianocore/tianocore.github.io/wiki/Using-EDK-II-with-Native-GCC (building from source)

https://en.wikipedia.org/wiki/BIOS#Vendors_and_products (BIOS feature comparison)

https://github.com/tianocore/tianocore.github.io/wiki/How-to-build-OVMF (building OVMF from source)

https://github.com/tianocore/tianocore.github.io/wiki/Common-instructions (common *nix instructions for building)

https://github.com/tianocore/edk2/blob/master/Vlv2TbltDevicePkg/bld_vlv.sh (examples of scripting changing of Conf/target.txt)

https://www.garyhawkins.me.uk/custom-logo-on-uefi-boot-screen/ (Logo.bmp dropped at MdeModulePkg/Logo/Logo.bmp)

https://wiki.archlinux.org/index.php/PCI_passthrough_via_OVMF (near native performance)

http://ubuntu-on-big-iron.blogspot.com/2017/11/virt-install-kvm-vm-install-options.html (serial interface to vms)

https://superuser.com/questions/239870/change-cd-rom-via-virsh (attach/remove cdrom)

https://www.virtualbox.org/ticket/15884 (custom firmware for virtualbox)

https://www.unixmen.com/how-to-install-and-configure-qemu-in-ubuntu/ (list of packages needed)

https://bluehatrecord.wordpress.com/2016/03/18/how-to-build-ovmf-on-fedora-23-workstation-from-source/

 stackoverflow, git submodule or else you get BrotliCompress.c constants.h fatal error because file not found

 

NOTES

if ERROR – internal error: cannot load AppArmor profile ‘libvirt-

$ sudo service apparmor status

$ sudo apt-get install apparmor-utils

$ sudo aa-complain /usr/sbin/libvirtd (complain only)

$ sudo aa-enforce /usr/sbin/libvirtd (enforce again)

 

DEPRECATED

prebuilt images of OVMF were available at kraxel.org.   If you download “jenkins/edk2/edk2.git-ovmf-x64-0-YYYYMMDD.XXX.gxxxxxxx.noarch.rpm”, then you can pull “OVMF-pure-efi.fd” from the package.

# get rpm2cpio tool
sudo apt-get install rpm2cpio -y

# unpack files from rpm
rpm2cpio edk2.git-ovmf-x64-0-20201023.1484.g6ad819c1ab.noarch.rpm | cpio -idmv

# verify .fd file was unpacked
ls -l usr/share/edk2.git/ovmf-x64/OVMF-pure-efi.fd

# verify that UEFI image can be used
# this won't create a bootable VM, just test the UEFI image
qemu-system-x86_64 -bios usr/share/edk2.git/ovmf-x64/OVMF-pure-efi.fd

if cross-compiling

sudo apt install -y gcc-arch64-linux-gnu
Categories: Linux Tags: build, custom, kvm, logo, make, OVMF, qemu, splash

Post navigation

← KVM: Bare metal virtualization on Ubuntu with KVM
KVM: Building the latest SeaBIOS firmware for virtual machines →
© 2025 Fabian Lee : Software Engineer