hashicorp / packer-plugin-virtualbox

Packer plugin for VritualBox Builder
https://www.packer.io/docs/builders/virtualbox
Mozilla Public License 2.0
22 stars 36 forks source link

Virtual Box with multiple Nics failed to locate the NAT network #6

Open ghost opened 3 years ago

ghost commented 3 years ago

This issue was originally opened by @bax99 as hashicorp/packer#10379. It was migrated here as a result of the Packer plugin split. The original body of the issue is below.


Hi there,

When installing Kali Linux 2004 with preseed.cfg and having packer configured with only the NAT network interface on VirtualBox, everything is fine.

However, in my case, I need 3 network interfaces to be configured. But with more than one interface, the packer build gets stuck on "Waiting for SSH to become available". If I open the GUI Virtual Machine and log on, I only see 1 Network Interfaces available under Kali Linux, even if three are configured in the json file.

part of the Json file

  "builders": [
    {
      "type": "virtualbox-iso",
      "boot_command": [
        "<esc><wait>",
        "/install.amd/vmlinuz<wait>",
        " auto<wait>",
        " console-setup/ask_detect=false<wait>",
        " console-setup/layoutcode=us<wait>",
        " console-setup/modelcode=pc105<wait>",
        " debconf/frontend=noninteractive<wait>",
        " debian-installer=en_US<wait>",
        " fb=false<wait>",
        " initrd=/install.amd/initrd.gz<wait>",
        " kbd-chooser/method=us<wait>",
        " console-keymaps-at/keymap=fr-ch<wait>",
        " keyboard-configuration/xkb-keymap=fr-ch<wait>",
        " keyboard-configuration/layout=Swiss french<wait>",
        " keyboard-configuration/variant=Swiss french<wait>",
        " locale=fr_CH<wait>",
        " netcfg/get_domain=hevs<wait>",
        " netcfg/get_hostname=kali<wait>",
        " grub-installer/bootdev=/dev/sda<wait>",
        " noapic<wait>",
        " interface=enp0s3<wait>",
        " preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg auto=true priority=critical",
        " -- <wait>",
        "<enter><wait>"
      ],
      "boot_wait": "10s",
      "disk_size": "{{user `disk_size`}}",
      "hard_drive_interface": "sata",     
      "iso_interface": "sata",
      "guest_additions_path": "VBoxGuestAdditions_{{.Version}}.iso",
      "virtualbox_version_file": ".vbox_version",
      "guest_os_type": "Debian_64",
      "headless": "{{ user `headless` }}",
      "http_directory": "{{user `http_directory`}}",
      "iso_checksum": "{{user `iso_checksum`}}",
      "iso_url": "{{user `iso_url`}}",    
      "memory": "{{ user `memory` }}",
      "vboxmanage": [
        ["storagectl", "{{.Name}}", "--name", "IDE Controller", "--remove"],
        ["modifyvm", "{{.Name}}", "--vrde", "off"],
        ["modifyvm", "{{.Name}}", "--graphicscontroller", "vmsvga"],
        ["modifyvm", "{{.Name}}", "--vram", "128"],
        ["modifyvm", "{{.Name}}", "--accelerate3d", "off"],
        ["modifyvm", "{{.Name}}", "--usb", "on"],
        ["modifyvm", "{{.Name}}", "--mouse", "usbtablet"],
        ["modifyvm", "{{.Name}}", "--audio", "none"],
        ["modifyvm", "{{.Name}}", "--nictype1", "82540EM"],
        ["modifyvm", "{{.Name}}", "--nictype2", "82540EM"],
        ["modifyvm", "{{.Name}}", "--nictype3", "82540EM"],
        ["modifyvm", "{{.Name}}", "--nictype4", "82540EM"],
        ["modifyvm", "{{.Name}}", "--clipboard", "bidirectional"],            
        ["modifyvm", "{{.Name}}", "--draganddrop", "bidirectional"],
        ["modifyvm", "{{.Name}}", "--nic1", "nat"],
        ["modifyvm", "{{.Name}}", "--natnet1", "default"],      
        ["modifyvm", "{{.Name}}", "--nic2", "intnet"],
        ["modifyvm", "{{.Name}}", "--intnet1", "intnet"],
        ["modifyvm", "{{.Name}}", "--nic3", "natnetwork"]
      ],
      "cpus": "{{ user `cpus` }}",    
      "ssh_username": "adminhevs",
      "ssh_password": "************",
      "ssh_port": 22,
      "ssh_wait_timeout": "10000s",
      "shutdown_command": "echo 'vagrant'|sudo -S shutdown -P now",
      "vm_name": "{{ user `template` }}"
    }
  ],
  "post-processors": [
    {
    "type": "vagrant",
    "output": "builds/{{user `box_basename`}}.{{.Provider}}.box"      
    }
  ],

Kali nics output

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:b2:a1:ae brd ff:ff:ff:ff:ff:ff

3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:98:9c:82 brd ff:ff:ff:ff:ff:ff

4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:b9:8c:a3 brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.35/24 brd 10.0.2.255 scope global dynamic noprefixroute eth2

As shown, eth0 did not get any IP from nat, neither eth1 from intnet. I can set manually IPs with nmcli, but it is not what I expect.

How can we have multiple NICS in the json file and be sure the first one will be taken into account by packer?

Regards