Fiddling around with Packer and VirtualBox I stumbled about some weird error that prevented me for some time to further use Packer with VirtualBox.

Scope

  • Packer 1.4.1
  • VirtualBox 6.0.8

Scenario

We create a base-image by using packer and a Debian Net-Install ISO-image. Afterwards we import this base-image into virtualbox and apply some configuration (with Ansible) on it. The resulting VM gets exported and then uploaded to a destination where it is started or instanciated.

Somewhere in my fiddling with our packer-scripts I found me and my mac in a uncertain state. I was no longer able to import the base-image into VirtualBox with packer, but a manual import worked. The manual import of course lacked a lot of parameters Packer would usually add and I was able to reproduce the error by running Packer, but could not trigger the same issue by doing a manual import of the base-image to VirtualBox

See the error-message:

*snip*
==> virtualbox-ovf: Retrieving OVF/OVA
==> virtualbox-ovf: Trying ../debian_base/baseimage/baseimage-debian.ovf
==> virtualbox-ovf: Using ovf inplace
==> virtualbox-ovf: leaving retrieve loop for OVF/OVA
==> virtualbox-ovf: Importing VM: ../debian_base/baseimage/baseimage-debian.ovf
==> virtualbox-ovf: Error importing VM: VBoxManage error: 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
==> virtualbox-ovf: Interpreting /Users/myuser/git/webserver_packer_baseimage/debian_base/baseimage/baseimage-debian.ovf...
==> virtualbox-ovf: OK.
==> virtualbox-ovf: 0%...
==> virtualbox-ovf: Progress state: NS_ERROR_INVALID_ARG
==> virtualbox-ovf: VBoxManage: error: Appliance import failed
==> virtualbox-ovf: VBoxManage: error: Code NS_ERROR_INVALID_ARG (0x80070057) - Invalid argument value (extended info not available)
==> virtualbox-ovf: VBoxManage: error: Context: "RTEXITCODE handleImportAppliance(HandlerArg *)" at line 957 of file VBoxManageAppliance.cpp
==> virtualbox-ovf: Error importing VM: VBoxManage error: 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
==> virtualbox-ovf: Interpreting /Users/myuser/git/webserver_packer_baseimage/debian_base/baseimage/baseimage-debian.ovf...
==> virtualbox-ovf: OK.
==> virtualbox-ovf: 0%...
==> virtualbox-ovf: Progress state: NS_ERROR_INVALID_ARG
==> virtualbox-ovf: VBoxManage: error: Appliance import failed
==> virtualbox-ovf: VBoxManage: error: Code NS_ERROR_INVALID_ARG (0x80070057) - Invalid argument value (extended info not available)
==> virtualbox-ovf: VBoxManage: error: Context: "RTEXITCODE handleImportAppliance(HandlerArg *)" at line 957 of file VBoxManageAppliance.cpp
==> virtualbox-ovf: Step "StepImport" failed, aborting...
Build 'virtualbox-ovf' errored: unexpected EOF

==> Some builds didn't complete successfully and had errors:
--> virtualbox-ovf: unexpected EOF

==> Builds finished but no artifacts were created.

I found no way to have packer show me the commands it uses to trigger VirtualBox and I read many VirtualBox issues.

The error-message tells Invalid argument value which is, as I found out, not correct.

Somewhere I stumbled across this quite old post from 2013: https://forums.virtualbox.org/viewtopic.php?t=58492#p271772. And this was the issue.

Doing a VBoxManage list hdds showed be two registered hdds although my VirtualBox was completely empty (in the UI).

$ VBoxManage list hdds
UUID:           b4f018c4-d7e2-4c74-9a22-d6aa8cce4777
Parent UUID:    base
State:          inaccessible
Type:           normal (base)
Location:       /Users/myuser/VirtualBox VMs/the-webserver/baseimage-debian-disk001.vmdk
Storage format: VMDK
Capacity:       0 MBytes
Encryption:     disabled

UUID:           5ee851c9-99b7-4d53-88d4-f9aab557d1cf
Parent UUID:    base
State:          inaccessible
Type:           normal (base)
Location:       /Users/myuser/VirtualBox VMs/theother_webserver/baseimage-debian-disk001.vmdk
Storage format: VMDK
Capacity:       0 MBytes
Encryption:     disabled

Using the command VBoxManage closemedium I was able to delete these invalid disks manually and my packer-scripts worked again as intended.

$ VBoxManage closemedium --delete b4f018c4-d7e2-4c74-9a22-d6aa8cce4777
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

$ VBoxManage closemedium --delete 5ee851c9-99b7-4d53-88d4-f9aab557d1cf
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

Problem solved.