Minimum OVMF UEFI folders and files to boot OpenWrt in ProxmoxVE

If you ever wanted to install OpenWrt in ProxmoxVE with an OVMF/UEFI BIOS, to make some PCI passthrough, this story will help you a lot:

I recently bought two Compex Wireless MiniPCIe adapters along with a 4 port ethernet PCIe card. My main idea was to pass the three adapters to the virtual machine and install OpenWrt into it.
The thing is, in order to pass that pcie adapters to a PVE VM, you need to set the BIOS to OVMF/UEFI. That is the only way to pass a card to a VM, You can´t do it with normal BIOS.
So, I created an OVMF virtual machine and configured it to use the three cards. All went OK.

The next step was install OpenWrt. The RootFS image is only one partition. If I, somehow, put that in a MBR virtual hdd and install grub in it, it will run, for sure. But giving the fact the VM was OVMF, the partition scheme of the virtual hdd must be GPT, mandatory. So, after several days trying I came with this discovering:

If there is no UEFI configuration set at the OVMF menu of the VM, OVMF will try to load this file in the EFI FAT32 partition of the GPT hdd:


That file can be any .efi file renamed to bootx64.efi. So, if I wanted to install OpenWrt manually, I could create a FAT32 partition at the beginning of the GPT virtual hdd, create the /EFI/boot/ folder, copy grubx64.efi to that folder and rename it to bootx64.efi. That change will make OVMF load that file if no other configuration is set, as I said before.

An I did it. But once the file was loaded I discovered Grub was failing each time I booted the VM. I renembered then that the binary grub file is one thing and the text configuration file was another. So I lacked the grub.cfg file. So stupid! That´s it. I created the grub.cfg file like this:


... booted the VM and failed! Then I moved it to several locations:


All failed! I started to get hungry, but continued the struggle. I opened the grubx64.efi with a hex editor and discovered this chain:


Aha! Given I used a Debian grubx64.efi file, it was compiled to search for the crub.cfg file in /EFI/debian/. So depending how grubx64.efi is compiled, it will search for it in different folders. I installed Ubuntu in other OVMF VM, manually mounted the EFI partition and discovered Ubuntu searchs for the grub.cfg file in /EFI/ubuntu/. Interesting.

So, I created the /EFI/debian/grub.cfg, booted the VM and Grub failed, but this time due to errors in the configuration file. (It was searching for the Debian Kernel) So, I was in the process of getting the UUID of the ext4 partition to add the correct information to the grub.cfg file and came with another idea:

OpenWrt in this VM will always load from /dev/sda2, so why do I need to set any root UUID at all?? I just configure grub.cfg to boot always look for the root partition at /dev/sda2 and I can replace the ext4 partition as many times as I want, without caring about UUIDs of that partition. I did it , then. And was a complete success!!

So, at this point I had a completely functional OpenWrt instalation in an OVMF VM with PCI passthrough working correctly. But my mind was not ok cause I still was having that "debian" folder in that FAT32 EFI partition. And this is not Debian. Is OpenWrt! I´m a perfectionist. I now, I now. So I started to search for a solution to this BIG PROBLEM :slight_smile:

I opened the grubx64.efi file with a hex editor and modified the chain to "/EFIboot/grub/grub.cfg". And now Im fine with myself.

Anyway, I wrote some post about it in my web and then I uploaded the files to always boot OpenWrt from /dev/sda2. You can download them and use ´em in your own OVMF PVE virtual machine. Remember to put them in the FAT32 partition like this:


Hope this story can help people with the same issue!