hashicorp / packer-plugin-qemu

Packer plugin for QEMU Builder
https://www.packer.io/docs/builders/qemu
Mozilla Public License 2.0
60 stars 44 forks source link

Packer cannot send boot commands to QEMU #28

Open ghost opened 3 years ago

ghost commented 3 years ago

This issue was originally opened by @jacob-carlborg as hashicorp/packer#11061. It was migrated here as a result of the Packer plugin split. The original body of the issue is below.


Overview of the Issue

I'm building a VM image using the QEMU builder. I'm trying to install FreeBSD for ARM64, using qemu-system-aarch64. I have an array of boot commands in the Packer file. The problem is that after Packer sends the first boot command, any further boot commands will not be received in the VM. What seems to be happening is the QEMU stops respond to input, either from Packer or from manually entering input (using the QEMU window or over VNC). If I instead manually enter the first boot command, then QEMU continues to respond to input, either from manual input or from Packer.

The issue occurs when using the edk2-aarch64-code.fd firmware, which is shipped with QEMU. Or using the UEFI firmware provided here [2]. It does not occur when booting using U-Boot as described here [1] (U-Boot fails later for reasons that are not related to Packer, making it not usable for my use case). The issue does not occur when installing OpenBSD using the same firmware [2]. The issue seems to be a combination of Packer, the firmware and the FreeBSD installer.

I've attached a screen shot at the bottom, showing that the input Packer is sending is not received/visible in the QEMU window. The second <enter> and waiting 5 seconds should provide a prompt which Packer can enter the remaining boot commands on.

Reproduction Steps

Run packer build freebsd.pkr.hcl on the file available here [3].

Packer version

Packer v1.7.2

Simplified Packer Buildfile

https://gist.github.com/jacob-carlborg/e00cd902984532bc174a47e48482438e

Operating system and Environment details

Occurs on both macOS and Linux.

$ qemu-system-aarch64 --version
QEMU emulator version 5.2.0
Copyright (c) 2003-2020 Fabrice Bellard and the QEMU Project developers

The issue occurs using QEMU 6 as well.

Log Fragments and crash.log files

https://gist.github.com/jacob-carlborg/2adb7a5f622acf27d7a5466641cc36b0

Set the env var PACKER_LOG=1 for maximum log detail.

[1] https://wiki.freebsd.org/arm64/QEMU [2] http://releases.linaro.org/components/kernel/uefi-linaro/latest/release/qemu64/QEMU_EFI.fd

Screen Shot 2021-06-01 at 07 35 28
theAeon commented 3 years ago

https://github.com/ddelnano/packer-plugin-xenserver/issues/26

possibly related issue, considering its based on this code. Ancient SDK though, currently trying to bring it to parity on my devbox

ospalax commented 2 years ago

I am encountering the same issue - leaving the comment here so I can get updates.

tannevaled commented 2 years ago

same problem with ubuntu 20.04 and bios firmware, not with uefi one.

tannevaled commented 2 years ago

trying to use the last seabios version (https://www.seabios.org/downloads/bios.bin-1.15.0.gz; finally not needed), i made it works enabling the qemu boot menu. the keycodes are now correctly received.

$ qemu-system-x86_64 --version
QEMU emulator version 4.2.1 (Debian 1:4.2-3ubuntu6.18)
Copyright (c) 2003-2019 Fabrice Bellard and the QEMU Project developers
$ packer version
Packer v1.7.8
source "qemu" "image-build" {

  accelerator = "kvm"
  qemuargs = [
    [ "-boot",  "menu=on,splash-time=10000" ],
...
jacob-carlborg commented 1 year ago

I think I found the problem. My first boot command looked like this 2<enter><wait30s>, instead of 2<wait30s>. It had an extra <enter>. Now it's working. But I don't think the extra <enter> should cause QEMU to not be able to receive further keypresses.