Create iPXE UEFI bootable image for QEMU/Libvirt with custom next-server and filename

ipxelibvirtpxe-bootqemuuefi

I can create a VM with libvirt/qemu to boot in UEFI mode. I know that it does iPXE by default, but I want to create/modify a iPXE image in order to override filename and next-server properties.

How can I do such thing?

EDIT:

I tried the following:

git clone git://git.ipxe.org/ipxe.git

In the directory ipxe/src create an iPXE script:

Contents of file ipxe/src/chain.ipxe:

#!ipxe
prompt --key 0x02 --timeout 2000 Press Ctrl-B for the iPXE command line... && shell ||
dhcp
set net0/filename /pxeserver/loader/uefi/bootx64.efi.0
set net0/next-server <IP>
show net0/filename
show net0/next-server
autoboot

Build the image with embedded script:

make bin-x86_64-efi/ipxe.efi EMBED=chain.ipxe

Build the image:

truncate -s 3MiB usb.img
mkfs.vfat usb.img
mmd -i usb.img "::/efi"
mmd -i usb.img "::/efi/boot"
mcopy -i usb.img bin-x86_64-efi/ipxe.efi "::/efi/boot/bootx64.efi"

Then I create a VM specifying this usb.img on the VM storage device. It boots iPXE, prints the filename and next-server overrides, gets IP through DHCP, then tries to boot from the server, it gets the corresponding bootloader, and then it starts the grub shell, as it seems that it does not try to download any grub configuration from next-server (double checked on its logs, it only logs the bootx64.efi.0 file, not grub.cfg file at all, as if it does not redirect PXE boot to the second server.

Best Answer

At least on Debian, the iPXE ROM images qemu uses are located at /usr/lib/ipxe and /usr/lib/ipxe/qemu, depending on which virtual NIC you're using in your VM.

Download the iPXE source code, make your modifications to it, build the ROM images, and replace the standard images with your customized ones.