bento icon indicating copy to clipboard operation
bento copied to clipboard

libvirt builds always use EFI, even on qemu_efi_boot=false

Open b0inbot opened this issue 2 months ago • 6 comments

Version

git branch main (b576310), 5.0.0 (635483b)

Environment

Fedora Linux 42 Workstation. Packer is installed from hashicorps repo. Packer v1.14.2

Scenario

running rockylinux build for qemu.vm

PACKER_LOG=1 bento build --only qemu.vm --vars qemu_efi_boot=false  os_pkrvars/rockylinux/rockylinux-10-x86_64.pkrvars.hcl

Steps to Reproduce

PACKER_LOG=1 bento build --only qemu.vm --vars qemu_efi_boot=false os_pkrvars/rockylinux/rockylinux-10-x86_64.pkrvars.hcl

OR

PACKER_LOG=1 bento build --only qemu.vm os_pkrvars/rockylinux/rockylinux-10-x86_64.pkrvars.hcl

Expected Result

A box gets built.

Actual Result

Attempts to build and boot with EFI

On my system, where the EFI files aren't available, the box fails to build:

2025/10/29 02:36:54 packer-plugin-qemu_v1.1.4_x5.0_linux_amd64 plugin: 2025/10/29 02:36:54 Started Qemu. Pid: 265164
2025/10/29 02:36:54 packer-plugin-qemu_v1.1.4_x5.0_linux_amd64 plugin: 2025/10/29 02:36:54 Qemu stderr: qemu-system-x86_64: -drive file=/usr/local/share/qemu/edk2-x86_64-code.fd,if=pflash,unit=0,format=raw,readonly=on: Could not open '/usr/local/share/qemu/edk2-x86_64-code.fd': No such file or directory

Additional notes

Looks like qemu_efi_firmware_code and qemu_efi_firmware_vars get set to /usr/local/share/... even if qemu_efi_boot is null or false.

I was able to get around this issue by changing the workflow setting the variables in pkr-sources.pkr.hcl:

diff --git a/packer_templates/pkr-sources.pkr.hcl b/packer_templates/pkr-sources.pkr.hcl
index e6356ab..e6375f1 100644
--- a/packer_templates/pkr-sources.pkr.hcl
+++ b/packer_templates/pkr-sources.pkr.hcl
@@ -68,14 +68,14 @@ locals {
   qemu_efi_boot = var.qemu_efi_boot == null ? (
     var.os_arch == "aarch64" ? true : false
   ) : var.qemu_efi_boot
-  qemu_efi_firmware_code = var.qemu_efi_firmware_code == null ? (
+  qemu_efi_firmware_code = (var.qemu_efi_boot == null || var.qemu_efi_boot == false) ? null : (var.qemu_efi_firmware_code == null ? (
     local.host_os == "Darwin" ? "/opt/homebrew/share/qemu/edk2-${var.os_arch}-code.fd" : "/usr/local/share/qemu/edk2-x86_64-code.fd"
-  ) : var.qemu_efi_firmware_code
-  qemu_efi_firmware_vars = var.qemu_efi_firmware_vars == null ? (
+  ) : var.qemu_efi_firmware_code)
+  qemu_efi_firmware_vars = (var.qemu_efi_boot == null || var.qemu_efi_boot == false) ? null : (var.qemu_efi_firmware_vars == null ? (
     local.host_os == "Darwin" ? (
       var.os_arch == "aarch64" ? "/opt/homebrew/share/qemu/edk2-arm-vars.fd" : "/usr/local/share/qemu/edk2-i386-vars.fd"
     ) : null
-  ) : var.qemu_efi_firmware_vars
+  ) : var.qemu_efi_firmware_vars)
   qemu_machine_type = var.qemu_machine_type == null ? (
     var.os_arch == "aarch64" ? "virt" : "q35"
   ) : var.qemu_machine_type

b0inbot avatar Oct 29 '25 09:10 b0inbot

Looks like that was introduced here https://github.com/chef/bento/commit/50199ef4eac1e9e034f2fa4dc3d5160d368222a8#diff-d22e528bf5024505d83aebd9b934b9ba5c40dd909f068907cf96ae57a6dc8666R72

b0inbot avatar Oct 29 '25 09:10 b0inbot

of course... the new image i was able to build with my changes isn't bootable.

b0inbot avatar Oct 29 '25 09:10 b0inbot

that does make sense. Eventually I'd like to get all builds for all providers to be uefi compliant, but not knowing qemu very well I've struggled with getting these builds stable and working. Can be very annoying when they build successfully but then don't work in actual use. I'm working on a windows update at the moment and will add the check for local.qemu_efi_boot to decide if firmeware code var should be set.

Stromweld avatar Oct 31 '25 18:10 Stromweld

Excuse the delay. I'm sitting down to work on this again and it looks like uefi-enabled builds of rockylinux 10 are booting which is perfect. just have to set the right variables in both bento and vagrant. Not yet getting an IP address

In my case I updated the repo but a CLI invocation should work as well. The paths listed below are based on my own system (Fedora Workstation with RPM edk2-ovmf-20250523-16.fc42.noarch).

There are some discussions here about the challenges of doing UEFI file autodiscovery https://github.com/vagrant-libvirt/vagrant-libvirt/issues/1753

lasagna > git diff
diff --git a/os_pkrvars/rockylinux/rockylinux-10-x86_64.pkrvars.hcl b/os_pkrvars/rockylinux/rockylinux-10-x86_64.pkrvars.hcl
index b8f5f4e..005eb7e 100644
--- a/os_pkrvars/rockylinux/rockylinux-10-x86_64.pkrvars.hcl
+++ b/os_pkrvars/rockylinux/rockylinux-10-x86_64.pkrvars.hcl
@@ -8,3 +8,6 @@ vbox_guest_os_type      = "Oracle_64"
 vmware_guest_os_type    = "centos-64"
 utm_vm_icon             = "linux"
 boot_command            = ["<wait><up>e<wait><down><down><end><wait> inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/rhel/ks.cfg inst.repo=https://download.rockylinux.org/pub/rocky/10/BaseOS/x86_64/os/ <leftCtrlOn>x<leftCtrlOff>"]
+qemu_efi_boot           = true
+qemu_efi_firmware_code = "/usr/share/edk2/ovmf/OVMF_CODE.fd"
+qemu_efi_firmware_vars = "/usr/share/edk2/ovmf/OVMF_VARS.fd"
     box.vm.provider :libvirt do |domain|
      domain.driver = "qemu"
      domain.qemu_use_session = false
      domain.loader = "/usr/share/OVMF/OVMF_CODE.fd"
      domain.nvram = "/usr/share/OVMF/OVMF_VARS.fd"
    end

b0inbot avatar Nov 07 '25 02:11 b0inbot

Code is too incomplete for a PR but i got the workflow all together.

booting (via correct variables which aren't included in the changes) and then following the other OS patterns of setting up static ifnames via kernel params https://github.com/chef/bento/compare/main...b0inbot:bento:boin/rockylinux-10

earlier versions of rockylinux might have different ways of doing this as grubby might be pretty new to 9 or 10.

b0inbot avatar Nov 07 '25 03:11 b0inbot

nice, appreciate the work and help with libvirt.

Stromweld avatar Nov 07 '25 14:11 Stromweld