Packer: Create multiple disk using virtual box builder using packer

Created on 17 Aug 2015  ·  3Comments  ·  Source: hashicorp/packer

I am able to create the 2nd disk using vbox createmedium command. But issue is 2nd disk is getting created in different folder and primary disk is getting created in output-virtualbox-iso folder.

I already tried to modify the parameter after reading the log file. This is I have mentioned to create 2nd disk.

 "vboxmanage": [
        [ "modifyvm", "{{.Name}}", "--memory", "2048" ],
        [ "modifyvm", "{{.Name}}", "--cpus" , "2" ],
        ["storageattach", "{{.Name}}", "--storagectl", "SCSI Controller", "--port", "1", "--device", "2", "--type", "hdd", "--medium", "output-virtualbox-iso/sdb.vdi"]
        ]

Debug log output

2015/08/17 09:43:53 ui: ==> virtualbox-iso: Creating virtual machine...
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 Executing VBoxManage: []string{"createvm", "--name", "shashank", "--ostype", "RedHat_64", "--register"}
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 stdout: Virtual machine 'shashank' is created and registered.
2015/08/17 09:43:53 packer-builder-virtualbox-iso: UUID: 6e98a276-bf26-4b67-acfb-176c30240a5d
2015/08/17 09:43:53 packer-builder-virtualbox-iso: Settings file: '/apps_data_01/Virtualbox/shashank/shashank.vbox'
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 stderr:
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 Executing VBoxManage: []string{"modifyvm", "shashank", "--boot1", "disk", "--boot2", "dvd", "--boot3", "none", "--boot4", "none"}
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 stdout:
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 stderr:
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 Executing VBoxManage: []string{"modifyvm", "shashank", "--cpus", "1"}
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 stdout:
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 stderr:
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 Executing VBoxManage: []string{"modifyvm", "shashank", "--memory", "512"}
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 stdout:
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 stderr:
2015/08/17 09:43:53 ui: ==> virtualbox-iso: Creating hard drive...
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 Executing VBoxManage: []string{"createhd", "--filename", "output-virtualbox-iso/shashank.vdi", "--size", "81040", "--format", "VDI", "--variant", "Standard"}
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 stdout: Medium created. UUID: 97572aa8-dd9a-42c3-947c-72795db83167
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 stderr: 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 Executing VBoxManage: []string{"storagectl", "shashank", "--name", "IDE Controller", "--add", "ide"}
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 stdout:
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 stderr:
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 Executing VBoxManage: []string{"storagectl", "shashank", "--name", "SCSI Controller", "--add", "scsi", "--controller", "LSILogic"}
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 stdout:
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 stderr:
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 Executing VBoxManage: []string{"storageattach", "shashank", "--storagectl", "SCSI Controller", "--port", "0", "--device", "0", "--type", "hdd", "--medium", "output-virtualbox-iso/shashank.vdi"}
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 stdout:
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 stderr:
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 Executing VBoxManage: []string{"storageattach", "shashank", "--storagectl", "IDE Controller", "--port", "0", "--device", "1", "--type", "dvddrive", "--medium", "/apps_data_01/packer-templates/packer_cache/c50dbd33d853ece2fd2d7b1a524ae5868134427a2fef9d98ea5b34fa19c67e82.iso"}
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 stdout:
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 stderr:
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 Not attaching guest additions since we're uploading.
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 No floppy disk, not attaching.
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 Looking for available SSH port between 2222 and 4444
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 Trying port: 4157
2015/08/17 09:43:53 ui: ==> virtualbox-iso: Creating forwarded port mapping for SSH (host port 4157)
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 Executing VBoxManage: []string{"modifyvm", "shashank", "--natpf1", "packerssh,tcp,127.0.0.1,4157,,22"}
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 stdout:
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 stderr:
2015/08/17 09:43:53 ui: ==> virtualbox-iso: Executing custom VBoxManage commands...
2015/08/17 09:43:53 ui:     virtualbox-iso: Executing: modifyvm shashank --memory 2048
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 Executing VBoxManage: []string{"modifyvm", "shashank", "--memory", "2048"}
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 stdout:
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 stderr:
2015/08/17 09:43:53 ui:     virtualbox-iso: Executing: modifyvm shashank --cpus 2
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 Executing VBoxManage: []string{"modifyvm", "shashank", "--cpus", "2"}
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 stdout:
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 stderr:
2015/08/17 09:43:53 ui:     virtualbox-iso: Executing: storageattach shashank --storagectl SCSI Controller --port 1 --device 2 --type hdd --medium output-virtualbox-iso/sdb.vdi
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 Executing VBoxManage: []string{"storageattach", "shashank", "--storagectl", "SCSI Controller", "--port", "1", "--device", "2", "--type", "hdd", "--medium", "output-virtualbox-iso/sdb.vdi"}
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 stdout:
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 stderr: VBoxManage: error: Could not find file for the medium '/vol_01/apps_data_01/packer-templates/output-virtualbox-iso/sdb.vdi' (VERR_FILE_NOT_FOUND)
2015/08/17 09:43:53 packer-builder-virtualbox-iso: VBoxManage: error: Details: code VBOX_E_FILE_ERROR (0x80bb0004), component MediumWrap, interface IMedium, callee nsISupports
2015/08/17 09:43:53 packer-builder-virtualbox-iso: VBoxManage: error: Context: "OpenMedium(Bstr(pszFilenameOrUuid).raw(), enmDevType, enmAccessMode, fForceNewUuidOnOpen, pMedium.asOutParam())" at line 177 of file VBoxManageDisk.cpp
2015/08/17 09:43:53 packer-builder-virtualbox-iso: VBoxManage: error: Invalid UUID or filename "output-virtualbox-iso/sdb.vdi"
2015/08/17 09:43:53 ui error: ==> virtualbox-iso: Error executing command: VBoxManage error: VBoxManage: error: Could not find file for the medium '/vol_01/apps_data_01/packer-templates/output-virtualbox-iso/sdb.vdi' (VERR_FILE_NOT_FOUND)
==> virtualbox-iso: VBoxManage: error: Details: code VBOX_E_FILE_ERROR (0x80bb0004), component MediumWrap, interface IMedium, callee nsISupports
==> virtualbox-iso: VBoxManage: error: Context: "OpenMedium(Bstr(pszFilenameOrUuid).raw(), enmDevType, enmAccessMode, fForceNewUuidOnOpen, pMedium.asOutParam())" at line 177 of file VBoxManageDisk.cpp
==> virtualbox-iso: VBoxManage: error: Invalid UUID or filename "output-virtualbox-iso/sdb.vdi"
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 Executing VBoxManage: []string{"storageattach", "shashank", "--storagectl", "IDE Controller", "--port", "0", "--device", "1", "--medium", "none"}
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 stdout:
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 stderr:
2015/08/17 09:43:53 ui: ==> virtualbox-iso: Unregistering and deleting virtual machine...
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 Executing VBoxManage: []string{"unregistervm", "shashank", "--delete"}
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 stdout:
2015/08/17 09:43:53 packer-builder-virtualbox-iso: 2015/08/17 09:43:53 stderr: 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
2015/08/17 09:43:53 ui: ==> virtualbox-iso: Deleting output directory...
2015/08/17 09:43:53 ui error: Build 'virtualbox-iso' errored: Error executing command: VBoxManage error: VBoxManage: error: Could not find file for the medium '/vol_01/apps_data_01/packer-templates/output-virtualbox-iso/sdb.vdi' (VERR_FILE_NOT_FOUND)
VBoxManage: error: Details: code VBOX_E_FILE_ERROR (0x80bb0004), component MediumWrap, interface IMedium, callee nsISupports
VBoxManage: error: Context: "OpenMedium(Bstr(pszFilenameOrUuid).raw(), enmDevType, enmAccessMode, fForceNewUuidOnOpen, pMedium.asOutParam())" at line 177 of file VBoxManageDisk.cpp
VBoxManage: error: Invalid UUID or filename "output-virtualbox-iso/sdb.vdi"
2015/08/17 09:43:53 Builds completed. Waiting on interrupt barrier...
2015/08/17 09:43:53 machine readable: error-count []string{"1"}
2015/08/17 09:43:53 ui error:
==> Some builds didn't complete successfully and had errors:
2015/08/17 09:43:53 machine readable: virtualbox-iso,error []string{"Error executing command: VBoxManage error: VBoxManage: error: Could not find file for the medium '/vol_01/apps_data_01/packer-templates/output-virtualbox-iso/sdb.vdi' (VERR_FILE_NOT_FOUND)\nVBoxManage: error: Details: code VBOX_E_FILE_ERROR (0x80bb0004), component MediumWrap, interface IMedium, callee nsISupports\nVBoxManage: error: Context: \"OpenMedium(Bstr(pszFilenameOrUuid).raw(), enmDevType, enmAccessMode, fForceNewUuidOnOpen, pMedium.asOutParam())\" at line 177 of file VBoxManageDisk.cpp\nVBoxManage: error: Invalid UUID or filename \"output-virtualbox-iso/sdb.vdi\""}
2015/08/17 09:43:53 ui error: --> virtualbox-iso: Error executing command: VBoxManage error: VBoxManage: error: Could not find file for the medium '/vol_01/apps_data_01/packer-templates/output-virtualbox-iso/sdb.vdi' (VERR_FILE_NOT_FOUND)
VBoxManage: error: Details: code VBOX_E_FILE_ERROR (0x80bb0004), component MediumWrap, interface IMedium, callee nsISupports
VBoxManage: error: Context: "OpenMedium(Bstr(pszFilenameOrUuid).raw(), enmDevType, enmAccessMode, fForceNewUuidOnOpen, pMedium.asOutParam())" at line 177 of file VBoxManageDisk.cpp
VBoxManage: error: Invalid UUID or filename "output-virtualbox-iso/sdb.vdi"
2015/08/17 09:43:53 ui:
==> Builds finished but no artifacts were created.
2015/08/17 09:43:53 waiting for all plugin processes to complete...
2015/08/17 09:43:53 /vol_01/apps_data_01/packer/packer-provisioner-shell: plugin process exited
2015/08/17 09:43:53 /vol_01/apps_data_01/packer/packer-builder-virtualbox-iso: plugin process exited
bug buildevirtualbox

Most helpful comment

I am able to successully create and attach multiple hard drives to a Packer-VB build.

Here's how:

  • Create the disks with commands which run before packer (i.e. in a separate script), and outside the output directory:

VBoxManage createhd --filename io1.vdi --size 10000

  • Refer said disk in the packer manifest:
"vboxmanage": [
        ["storageattach", "{{.Name}}", "--storagectl", "IDE Controller", "--port", "0", "--device", "1", "--type", "hdd", "--medium", "io1.vdi"]
    ]
  • Perform the build. It will just work. io1.vdiwill disappear, and in turn an extra vdi file will appear in the right output folder.

Here's a screenshot of my 4-disk setup.

image

Everything's correct this way - I can format the drives during Packer build time, and after creation they'll still be there.

Hope this ever helps someone out.

Also, this issue might be good to close!

All 3 comments

Interesting bug! Thanks for the report.

I am able to successully create and attach multiple hard drives to a Packer-VB build.

Here's how:

  • Create the disks with commands which run before packer (i.e. in a separate script), and outside the output directory:

VBoxManage createhd --filename io1.vdi --size 10000

  • Refer said disk in the packer manifest:
"vboxmanage": [
        ["storageattach", "{{.Name}}", "--storagectl", "IDE Controller", "--port", "0", "--device", "1", "--type", "hdd", "--medium", "io1.vdi"]
    ]
  • Perform the build. It will just work. io1.vdiwill disappear, and in turn an extra vdi file will appear in the right output folder.

Here's a screenshot of my 4-disk setup.

image

Everything's correct this way - I can format the drives during Packer build time, and after creation they'll still be there.

Hope this ever helps someone out.

Also, this issue might be good to close!

I think the ultimate issue is with virtualbox. Sounds like there's a good workaround, thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wduncanfraser picture wduncanfraser  ·  3Comments

mushon4 picture mushon4  ·  3Comments

Tensho picture Tensho  ·  3Comments

mwhooker picture mwhooker  ·  3Comments

mvermaes picture mvermaes  ·  3Comments