2

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.

NiKiZe
  • 1,189
  • 7
  • 17
djuarez
  • 131
  • 1
  • 2
  • 8

2 Answers2

2

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.

telcoM
  • 4,153
  • 12
  • 23
1

iPXE has more features than the average bootloader, in this case when booting grub, grub will try to load the configuration from the same location as it was started from, however that does not work due to previously mentioned features.

To work around this make sure to build iPXE with correct config, in this case that is CONFIG=qemu which does #define EFI_DOWNGRADE_UX (page with some details: https://bugs.launchpad.net/maas/+bug/1789319/comments/16 there is mailing list threads with more details)

Regarding named configs, See https://ipxe.org/appnote/named_config

You can then either build this as a ROM to replace the original, either by replacing the original file, or provide path to ROM at commandline. Other ways is to chain from the original to your new one, or as you do now build a usb device.

I think you can even have it in your target to avoid the manual image build step: make bin-x86_64-efi/ipxe.usb EMBED=chain.ipxe CONFIG=qemu

NiKiZe
  • 1,189
  • 7
  • 17