Add Host only network in the Virtual Box builder

64 views
Skip to first unread message

steve BP

unread,
Oct 15, 2018, 4:26:50 AM10/15/18
to Packer
Hi

I am using packer (Windows) to build and deploy virtual box VMs with Windows 2012 installations. This has worked very well for our automated deployment and test of control applications.

I am trying to add a hostonly network interface as part of the virtual box builder and have run into errors.
 
I wish to add the host-only interface in the builder, as opposed to a provisioner or post builder so that resources on the host only network can be used by the provisioners.
 
My builder vboxmanage is as follows (full builder below)

    "vboxmanage": [
        [ "modifyvm", "{{.Name}}", "--natpf1", "winrm,tcp,,55985,,5985" ],
        [ "modifyvm", "{{.Name}}", "--memory", "{{user `target_MemorySize`}}" ],
        [ "modifyvm", "{{.Name}}", "--cpus", "{{user `target_Cpu`}}" ],
        [ "modifyvm", "{{.Name}}", "--nic2", "hostonly --hostonlyadapter1 vboxnet1" ]
      ],
 
Packer is responding as following with an error.

I have tried the vboxmanage command from a shell and this works ok on a test vm, so think that my command syntax is ok.

> vboxmanage modifyvm "C:\Users\sbp\VirtualBox VMs\hostTest"\hostTest.vbox --nic2 hostonly --hostonlyadapter1 vboxnet1

Would anybody please be able to advise me how to make this feature work.

Thanks in advance.

Steve

Packer Output

E:\svn-mirror\projects\Home\Steve_Pinfold\PackerWindowsBuilder\branches\TLS-amd64>packer.exe build Output.json
virtualbox-iso output will be in this color.

==> virtualbox-iso: Retrieving Guest additions
    virtualbox-iso: Using file in-place: file:///C:/Program%20Files/Oracle/VirtualBox/VBoxGuestAdditions.iso
==> virtualbox-iso: Retrieving ISO
    virtualbox-iso: Using file in-place: file:///E:/usr/tools/WindowsInstallers/SW_DVD5_WIN_PRO_7W_SP1_64BIT_ENGLISH_-2_MLF_X17-59279.ISO
==> virtualbox-iso: Creating floppy disk...
    virtualbox-iso: Copying files flatly from floppy_files
    virtualbox-iso: Copying file: AutoUnattend.xml
    virtualbox-iso: Done copying files from floppy_files
    virtualbox-iso: Collecting paths from floppy_dirs
    virtualbox-iso: Resulting paths from floppy_dirs : []
    virtualbox-iso: Done copying paths from floppy_dirs
==> virtualbox-iso: Creating virtual machine...
==> virtualbox-iso: Creating hard drive...
==> virtualbox-iso: Attaching floppy disk...
==> virtualbox-iso: Creating forwarded port mapping for communicator (SSH, WinRM, etc) (host port 2840)
==> virtualbox-iso: Executing custom VBoxManage commands...
    virtualbox-iso: Executing: modifyvm packer-virtualbox-iso-1539588999 --natpf1 winrm,tcp,,55985,,5985
    virtualbox-iso: Executing: modifyvm packer-virtualbox-iso-1539588999 --memory 2048
    virtualbox-iso: Executing: modifyvm packer-virtualbox-iso-1539588999 --cpus 2
    virtualbox-iso: Executing: modifyvm packer-virtualbox-iso-1539588999 --nic2 hostonly --hostonlyadapter1 vboxnet1
==> virtualbox-iso: Error executing command: VBoxManage error: VBoxManage.exe: error: Invalid type 'hostonly --hostonlyadapter1 vboxnet1' specfied for NIC 2
==> virtualbox-iso: Deregistering and deleting VM...
==> virtualbox-iso: Deleting output directory...
Build 'virtualbox-iso' errored: Error executing command: VBoxManage error: VBoxManage.exe: error: Invalid type 'hostonly --hostonlyadapter1 vboxnet1' specfied for NIC 2

==> Some builds didn't complete successfully and had errors:
--> virtualbox-iso: Error executing command: VBoxManage error: VBoxManage.exe: error: Invalid type 'hostonly --hostonlyadapter1 vboxnet1' specfied for NIC 2

==> Builds finished but no artifacts were created.

Full Builder

  "builders": [
    {
      "type": "virtualbox-iso",
      "vboxmanage": [
        [ "modifyvm", "{{.Name}}", "--natpf1", "winrm,tcp,,55985,,5985" ],
        [ "modifyvm", "{{.Name}}", "--memory", "{{user `target_MemorySize`}}" ],
        [ "modifyvm", "{{.Name}}", "--cpus", "{{user `target_Cpu`}}" ],
    [ "modifyvm", "{{.Name}}", "--nic2", "hostonly --hostonlyadapter1 vboxnet1" ]
      ],
      "vboxmanage_post": [
[ "modifyvm", "{{.Name}}", "--nic1", "bridged", "--bridgeadapter1", "{{user `host_NetworkAdaptor`}}" ]
  ],
      "guest_os_type": "{{user `OS_Type`}}",
      "iso_url": "{{user `OS_Iso`}}",
      "iso_checksum": "{{user `Os_Checksum`}}",
      "iso_checksum_type": "md5",
      "disk_size": "{{user `target_DiskSize`}}",
      "communicator": "winrm",
      "winrm_username": "vagrant",
      "winrm_password": "vagrant",
      "winrm_port": "5985",
      "winrm_timeout": "10h",
      "guest_additions_mode": "attach",
  "post_shutdown_delay": "3m",
      "shutdown_command": "shutdown -s -t 3000",
      "shutdown_timeout": "5h",
      "floppy_files": [
        "AutoUnattend.xml"
      ],
      "export_opts": [
"--manifest",
        "--vsys",
        "0",
        "--description",
        "{{user `vm_description`}}",
        "--version",
        "{{user `vm_version`}}"
      ]
    }
  ],

Rickard von Essen

unread,
Oct 15, 2018, 5:45:52 AM10/15/18
to packe...@googlegroups.com
Each argument need to be it's own string:
[ "modifyvm", "{{.Name}}", "--nic2", "hostonly --hostonlyadapter1 vboxnet1" ]

must be:
[ "modifyvm", "{{.Name}}", "--nic2", "hostonly", "--hostonlyadapter1", "vboxnet1" ]

// Rickard

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/be5dcf72-efac-44c4-9cf0-317f2da5f445%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

steve BP

unread,
Oct 15, 2018, 6:15:54 AM10/15/18
to Packer
Hi Rickard

Thanks for the prompt reply. I have modified my template as per your instructions (I was led a bit astray by the WinRM port forwarding line) and I am hitting my next error

=> virtualbox-iso: Executing custom VBoxManage commands...
   virtualbox-iso: Executing: modifyvm packer-virtualbox-iso-1539598042 --natpf1 winrm,tcp,,55985,,5985
   virtualbox-iso: Executing: modifyvm packer-virtualbox-iso-1539598042 --memory 2048
   virtualbox-iso: Executing: modifyvm packer-virtualbox-iso-1539598042 --cpus 2
   virtualbox-iso: Executing: modifyvm packer-virtualbox-iso-1539598042 --nic2 hostonly --hostonlyadapter1 vboxnet1
=> virtualbox-iso: Starting the virtual machine...
=> virtualbox-iso: Error starting VM: VBoxManage error: VBoxManage.exe: error: Nonexistent host networking interface, name '' (VERR_INTERNAL_ERROR)
=> virtualbox-iso: VBoxManage.exe: error: Details: code E_FAIL (0x80004005), component ConsoleWrap, interface IConsole
=> virtualbox-iso: Deregistering and deleting VM...

Looking at the help for VboxManage  modifyvm, 

 [--hostonlyadapter<1-N> none|<devicename>]

I am wondering, I am wondering if it is complaining about the device name field. In the command line example this vboxnet1 works, but my actual host network adapter is VirtualBox Host-Only Ethernet Adaptor. I have tried this also but it still did not work.

Rickard von Essen

unread,
Oct 15, 2018, 6:28:33 AM10/15/18
to packe...@googlegroups.com
Yes your syntax is incorrect check section 6.7 at https://www.virtualbox.org/manual/ch06.html

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool...@googlegroups.com.

steve BP

unread,
Oct 15, 2018, 11:16:49 AM10/15/18
to Packer
Rickard.

from your experience do you think that the error is caused by a packer configuration issue, or a virtual box configuration issue?

Steve

Rickard von Essen

unread,
Oct 15, 2018, 3:13:22 PM10/15/18
to packe...@googlegroups.com
VBoxManage.exe: error: Nonexistent host networking interface, name ''

This is caused by your vboxmanage command, either the natpf or the adding the host network. Remove one and see if you get further. 

Reply all
Reply to author
Forward
0 new messages