hashicorp / packer-plugin-hyperv

Packer plugin for Hyper-V Builder
https://www.packer.io/docs/builders/hyperv
Mozilla Public License 2.0
19 stars 23 forks source link

No DHCP lease using hyper-v iso #12

Open ghost opened 3 years ago

ghost commented 3 years ago

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


Overview of the Issue

I am trying to build a hyper-v image using a custom .iso-image. The image itself is valid and works in manual tests. However, there is no DHCP lease when using the hyper-v builder and thus our kickstarter file fails.

Reproduction Steps

Option A)

Option B)

Packer version

Packer v1.4.5

Simplified Packer Buildfile

{
  "variables": {
    "iso_url":  "./extra/CentOS-7-x86_64-NetInstall-1908.iso",
    "iso_checksum": "6FFA7AD44E8716E4CD6A5C3A85BA5675A935FC0448C260F43B12311356BA85AD",
    "switch_name": "",
    "vm_name": "test",
    "disk_size": "20000",
    "output_directory": "",
    "ssh_password": "rootroot",
    "memory": "8192",
    "cpus": "1"
  },
  "builders": [
    {
      "type": "hyperv-iso",
      "vm_name": "{{ user `vm_name` }}",
      "temp_path": ".",
      "iso_url": "{{ user `iso_url` }}",
      "iso_checksum": "{{user `iso_checksum`}}",
      "disk_size": "{{user `disk_size`}}",
      "disk_block_size": "1",
      "communicator": "ssh",
      "ssh_username": "root",
      "ssh_password": "{{ user `ssh_password` }}",
      "ssh_timeout" : "4h",
      "shutdown_timeout": "30m",
      "shutdown_command": "echo 'password' | sudo -S shutdown -P now",
      "memory": "{{ user `memory` }}",
      "enable_dynamic_memory": "true",
      "cpus": "{{ user `cpus` }}",
      "generation": 1,
      "switch_name": "{{user `switch_name`}}",
      "http_directory": "./extra/html",
      "boot_wait": "5s",
      "boot_command": [ ],
      "guest_additions_mode":"disable",
      "enable_secure_boot": false,
      "output_directory": "{{ user `output_directory` }}"
    }
  ],
  "provisioners": [ ]
}

Operating system and Environment details

Windows 10 Host Hyper-V Version 10.0.17763.1

Log Fragments and crash.log files

When checking through the hyper-v manager, there is no IP address allocated to the VM.

Booting into the dracut shell, we can check the network status using ip addr. The result shows no allocated IPv4 address for eth0.

1: lo <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group
    [...]
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:15:5d:01:c4:35 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::215::5dff::fe01::c435/64 scope link
        valid_lft forever preferred_lft forever
barrymw commented 3 years ago

I stumbled across this thread as well as a comment on the hyperv iso builder page. As a work around, I modified the packer-hyperv-iso virtual switch to use the External network rather than the Internal network. image After that, the build was successfully able to obtain an IP address and progress with the build of Ubuntu.

dot-mike commented 3 years ago

Internally, Hyper-V does not provide a DHCP-server.

maroskukan commented 2 years ago

I also ran into this issues recently, I don't think its related to this plugin but rather Hyper-V itself as it occurred from time to time also during VM provisioning through Vagrant. In both cases I have used the Default switch which does provide DHCP services through ICS. In my case (Build 19042) a host reboot solved the issue.

domoran commented 1 year ago

This issue should be closed. Machine getting no DHCP lease has nothing todo with the packer plugin rather with the fact, that no DHCP server was available at build time.