Netbooting with UEFI/OVMF from QEMU
Long story short: when using OVMF with QEMU and want to network boot, it seems that -device virtio-rng-pci is required.
Props to this gist.
What does not work
First: obviously just running a plain qemu-system-x86_64 -m 2G -enable-kvm -drive if=pflash,format=raw,readonly=on,file=/usr/share/ovmf/x64/OVMF_CODE.4m.fd will not netboot. There is no problem nowhere, it just doesn't show netboot in the boot menu and will not try.
Next, looking at the OVMF README is not really useful. You can read that it should just work with the bundled simulated NICs. It does not, in my experience. Setting the parameters for the network device is also going nowhere. Disabling KVM, as hinted by the README elsewhere does not help either.
And apparently other documentation is mostly useless too in this regard.
In all of the previous cases, the NIC is there (according to devices command in the EFI shell) and has a driver (drivers), but I didn't manage to invoke it. The NIC also shows in Device Manager in the “SETUP”.
Alternative approach
Knowing that the NIC is there but does not work out of the box, I was almost determined to get iPXE EFI binary, supply the machine with a trivial FAT32 EFI system partition containing it and just launching that. I believe that would have worked, although that does not help test OVMF/TianoCore network stack.
Also, during writing this up, -cpu host seems to help. Which is not that surprising when we know that the missing part is a RNG and not anything related to networking…
My system
In order to be as transparent as possible, this was tested on my Larch linux (it's like Arch, but so heavily tweaked that it almost does not count lol), QEMU 10.0.0-5, edk2-ovmf 202411-1 (EFI shell says: UEFI v2.70 (EDK II, 0x00010000)), linux kernel 6.14.10.arch1-1.
I hope this saves someone some time debugging.