hashicorp / packer-plugin-qemu

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

Noisier errors when using -drive or -device in qemuargs #58

Open haydenmuhl opened 2 years ago

haydenmuhl commented 2 years ago

Please search the existing issues for relevant feature requests, and use the reaction feature (https://blog.github.com/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/) to add upvotes to pre-existing requests.

Community Note

Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request. Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request. If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Description

The qemuargs option has the following warning.

Warning: The qemu command line allows extreme flexibility, so beware of conflicting arguments causing failures of your run. For instance adding a "--drive" or "--device" override will mean that none of the default configuration Packer sets will be used.

I'm was building an image that required an additional ISO besides the bootable ISO specified in iso_url. It caught me by surprise that iso_url and the default hard drive silently disappeared because of this. The downstream errors that I saw were very confusing. For example, inline shell provisioners only worked if they contained a single command. If they contained more than one command they would not execute, because the script upload failed.

I will admit, this is a failure on my part to read the documentation in detail, but it took me two months to finally figure out what was going wrong. A big, noisy, descriptive error up front could have saved me a lot of time.

Use Case(s)

An easier way to add additional drives to a qemu VM. For example, we boot our VMs with an iPXE ISO image, for its clean interface for inputing boot parameters. If an OS installs from a disk, such as another ISO image, supplying that additional ISO image triggers this problem.

Potential configuration

If a -drive argument is supplied, raise an error, and require a different configuration.

Option 1: A flag to explicitly disable the default cdrom and hard drive.

{
  "default_drives": false,
  "qemuargs": [[ "-drive", "..."], ...]
}

Option 2: A drives array, where additional drives can be declared in a structured manner.

{
  "drives": [
    {
      "file": "/path/to/image.iso",
      "media": "cdrom",
      ...
    },
    {
      ...
    }
  ]
}

These options aren't mutually exclusive.

Potential References

https://www.packer.io/docs/builders/qemu#qemuargs

haydenmuhl commented 2 years ago

Unless I hear otherwise, I will start playing around with implementing option 1. It seems like the most general use case.

Jamesits commented 1 year ago

I'm having the same issue. I'd like to have the ISO, dynamically-created CD / FDD AND additional custom drives attached to the virtual machine. Consider that QEMU's command line arguments a) can be specified multiple times for the same type of device b) have strict ordering since objects might reference other objects, the current design of qemuargs creates multiple issues in this setup:

It's better that we have a method to append arguments in an order-preserving way.

For now, I'm considering some workarounds, each of which comes with some caveats: