hashicorp / packer-plugin-qemu

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

Allow both cdrom & disk to use the virtio interface #136

Open leifliddy opened 1 year ago

leifliddy commented 1 year ago

I'm running into this exact same issue with qemu-system-aarch64 (running on a macbook m2) except it's with the virtio interface.

https://github.com/hashicorp/packer-plugin-qemu/issues/35

source "qemu" "vagrant" {
  headless            = true
  cpu_model           = "host"
  memory              = 2048
  cpus                = 4  
  disk_size           = 210000 
  net_device          = "virtio-net"
  disk_interface      = "virtio"
  cdrom_interface     = "virtio"
  format              = "qcow2"
  accelerator         = "hvf"
  machine_type        = "virt"
  qemu_binary         = "qemu-system-aarch64"
  iso_url             = "${var.iso_path}"
...
}

The issue is two fold.

  1. I can only use the virtio interface for both the hdd + cdrom on this system. So I can't use virtio-scsi, sata, ide....etc

    unsupported bus type 'virtio-scsi'

    So I can't utilize this "fix" https://github.com/hashicorp/packer/issues/10211#issuecomment-778164090 As that comment shows, people were experiencing this exact issue years ago.

  2. There's a device conflict: The error I'm getting is

    qemu-system-aarch64: -drive file=boot.iso,if=virtio,id=cdrom0,media=cdrom,index=0: drive with bus=0, unit=0 (index=0) exists](qemu-system-aarch64: -drive file=boot.iso,if=virtio,index=0,id=cdrom0,media=cdrom: drive with bus=0, unit=0 (index=0) exists)

    Normally when I'm running qemu manually on my system, I use the following argument

    -cdrom boot.iso 

    and that works fine. But packer seems very opinionated in this area and forces the use of the -drive argument I would like to request one of the following two features.

  3. Allow both cdrom & disk to use the virtio interfaces. The same logic already exists here for the virtio-scsi interface: https://github.com/hashicorp/packer-plugin-qemu/pull/40/commits/221d5f94ec7b9898eb5bbba29f61a88d6bfdee80

  4. Create an additional iso_manual_args option (or something like that) that would be mutually exclusive with iso_url(s) So that users could simply manually specify the cdrom args themselves. Currently packer enforces the use of iso_url

    One of iso_url or iso_urls must be specified
leifliddy commented 1 year ago

I was able to workaround this issue with the following

  qemuargs = [  
    ["-drive", "file=${var.iso_path},if=virtio,index=1,id=cdrom0,media=cdrom"],
    ["-boot", "d"]
  ]    

But it still would be nice to have a proper fix for it. Not sure why that aforementioned fix was only made for virtio-scsi and not for virtio as well.

leifliddy commented 1 year ago

Nevermind, that workaround doesn't register the hdd disk, so it's a pure cdrom boot.

Not sure why packer can't just specify the cdrom with the -cdrom argument as that would solve most of my problems.

But....there's one more thing that would need to be sorted out after that. Ok, let's say I have the following

   -drive file=disk.qcow2,format=qcow2,if=virtio,cache=writethrough \
   -cdrom boot.iso \

So if I try -boot once=c or -boot once=d I'm greeted with this

qemu-system-aarch64: no function defined to set boot device list for this architecture

However, just specifying -boot c or boot d work as expected.
I think this might be a difference between qemu-system-x86_64 and qemu-system-aarch64

qemu is so complicated -- honestly I have no idea how you guys deal with this stuff. Differences in versions, platforms, and binaries....