packer-plugin-hyperv icon indicating copy to clipboard operation
packer-plugin-hyperv copied to clipboard

No DHCP lease using hyper-v iso

Open ghost opened this issue 4 years ago • 4 comments

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)

  • Download CentOS-7 NetInstall iso
  • run packer build .\iso.json using the given Buildfile
  • manually enter graphical install and see that there is no network connection
  • try connecting to the network and observe that it does not connect

Option B)

  • Boot into a dracut recovery shell
  • run dhcpclient -v etho0
  • observe that no lease is received

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

ghost avatar Apr 21 '21 14:04 ghost

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.

barrymw avatar Aug 25 '21 04:08 barrymw

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

dot-mike avatar Oct 01 '21 03:10 dot-mike

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.

maroskukan avatar Jul 15 '22 14:07 maroskukan

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.

domoran avatar Dec 20 '22 23:12 domoran