Overview of the Issue
Build fails when attaching a floppy to an image built with virtual-ova builder, when the OVA already has a floppy controller configured.
StepVBoxManage is running after the StepAttachFloppy, therefore it's not possible to instruct VBoxManage to remove the floppy controller before the floppy attachment step.
The difference with vmware and parallels builders is that controllers are not deleted before adding a new one. I assume the reason for that is that in VirtualBox a controller has a name and has to be deleted by supplying a name, whereas in other VM solutions there's a generic name for the single floppy controller.
For example the ubuntu cloud-images OVA files already have floppy controller configured. In those images the floppy controller name is Floppy, while VirtualBox builder is not trying to detect wether it exists and is always adding a floppy controller with the name of Floppy Controller.
Reproduction Steps
Building the ubuntu cloud-image fails with:
...
==> virtualbox-ovf: Attaching floppy disk...
==> virtualbox-ovf: Deregistering and deleting imported VM...
==> virtualbox-ovf: Deleting output directory...
Build 'virtualbox-ovf' errored: Error creating floppy controller: VBoxManage error: VBoxManage: error: Too many storage controllers of this type
VBoxManage: error: Details: code NS_ERROR_INVALID_ARG (0x80070057), component StorageControllerWrap, interface IStorageController, callee nsISupports
VBoxManage: error: Context: "AddStorageController(Bstr(pszCtl).raw(), StorageBus_Floppy, ctl.asOutParam())" at line 1092 of file VBoxManageStorageController.cpp
==> Some builds didn't complete successfully and had errors:
--> virtualbox-ovf: Error creating floppy controller: VBoxManage error: VBoxManage: error: Too many storage controllers of this type
VBoxManage: error: Details: code NS_ERROR_INVALID_ARG (0x80070057), component StorageControllerWrap, interface IStorageController, callee nsISupports
VBoxManage: error: Context: "AddStorageController(Bstr(pszCtl).raw(), StorageBus_Floppy, ctl.asOutParam())" at line 1092 of file VBoxManageStorageController.cpp
Packer version
Packer v1.5.4
Simplified Packer Buildfile
{
"builders": [{
"type": "virtualbox-ovf",
"source_path": "https://cloud-images.ubuntu.com/releases/bionic/release/ubuntu-18.04-server-cloudimg-amd64.ova",
"vboxmanage": [
["modifyvm", "{{.Name}}", "--boot1", "disk"],
["modifyvm", "{{.Name}}", "--boot2", "none"],
["modifyvm", "{{.Name}}", "--boot3", "none"],
["modifyvm", "{{.Name}}", "--boot4", "none"],
["modifyvm", "{{.Name}}", "--uart1", "0x3F8", "4"],
["modifyvm", "{{.Name}}", "--uartmode1", "file", "{{ pwd }}/console.log"]
],
"floppy_files": [
"{{ template_dir }}/seed/user-data",
"{{ template_dir }}/seed/meta-data"
],
"floppy_label": "cidata",
"ssh_username": "ubuntu",
"ssh_password": "passw0rd",
"shutdown_command": "echo 'packer' | sudo -S shutdown -P now"
}]
}
The content of {{ template_dir }}/seed/user-data and {{ template_dir }}/seed/meta-data doesn't matter.
Proposed solutions
Align with other VM builders
In order to align with other VM builders (vmware, parallels), the floppy controller needs to be removed before creating a new one. In the case of VirtualBox, the floppy controller in the supplied OVA file has an arbitrary name, so in order to remove it, we would need to first get information about the VM with something like: VBoxManage showvminfo "{{ .Name }}" --machinereadable, extract the floppy controller name from the output and remove it with VBoxManage storagectl "{{ .Name }}" --name "[existing floppy controller name]" --remove.
Allow setting the floppy controller name
If we allow passing through config the name of the controller within the existing OVA file, we could assume it already exists and configured properly. In this case we can skip the adding of floppy controller in the StepAttachFloppy and attach floppy to existing floppy controller.
Add ability to run VBoxManage before adding the floppy
If there was an ability to supply vboxmanage_pre in config, which would configure the runs of VBoxManage before adding the floppy (right after importing the OVA image), it would solve the problem too. I will be able to remove the existing floppy controller with VBoxManage command before the new one is added by packer.
Overview of the Issue
Build fails when attaching a floppy to an image built with virtual-ova builder, when the OVA already has a floppy controller configured.
StepVBoxManageis running after theStepAttachFloppy, therefore it's not possible to instruct VBoxManage to remove the floppy controller before the floppy attachment step.The difference with vmware and parallels builders is that controllers are not deleted before adding a new one. I assume the reason for that is that in VirtualBox a controller has a name and has to be deleted by supplying a name, whereas in other VM solutions there's a generic name for the single floppy controller.
For example the ubuntu cloud-images OVA files already have floppy controller configured. In those images the floppy controller name is
Floppy, while VirtualBox builder is not trying to detect wether it exists and is always adding a floppy controller with the name ofFloppy Controller.Reproduction Steps
Building the ubuntu cloud-image fails with:
Packer version
Packer v1.5.4Simplified Packer Buildfile
The content of
{{ template_dir }}/seed/user-dataand{{ template_dir }}/seed/meta-datadoesn't matter.Proposed solutions
Align with other VM builders
In order to align with other VM builders (vmware, parallels), the floppy controller needs to be removed before creating a new one. In the case of VirtualBox, the floppy controller in the supplied OVA file has an arbitrary name, so in order to remove it, we would need to first get information about the VM with something like:
VBoxManage showvminfo "{{ .Name }}" --machinereadable, extract the floppy controller name from the output and remove it withVBoxManage storagectl "{{ .Name }}" --name "[existing floppy controller name]" --remove.Allow setting the floppy controller name
If we allow passing through config the name of the controller within the existing OVA file, we could assume it already exists and configured properly. In this case we can skip the adding of floppy controller in the
StepAttachFloppyand attach floppy to existing floppy controller.Add ability to run VBoxManage before adding the floppy
If there was an ability to supply
vboxmanage_prein config, which would configure the runs of VBoxManage before adding the floppy (right after importing the OVA image), it would solve the problem too. I will be able to remove the existing floppy controller with VBoxManage command before the new one is added by packer.