Re: Hyper-v Error getting SSH address: No ip address

1,197 views
Skip to first unread message
Message has been deleted

Mukhtar Elhadi

unread,
Mar 3, 2017, 12:34:05 PM3/3/17
to Packer


On Friday, March 3, 2017 at 8:32:53 PM UTC+3, Mukhtar Elhadi wrote:
Hi,

I am trying to build Ubuntu 16.04 for hyper-v, but I am always get "Waiting for ssh to be available" and nothing happen after that, I would appreciate if you anyone can help with this issue.


Host OS: Microsoft Windows [Version 10.0.14393]
Guest OS: ubuntu-16.04.2-server-amd64
   Packer version: Packer v0.12.3


Here is the result of packer build:

packer build .\hyperv-ubuntu-16.04.json


hyperv-iso output will be in this color.

==> hyperv-iso: Creating temporary directory...
==> hyperv-iso: Downloading or copying ISO
    hyperv-iso: Downloading or copying: file:///F:/ISOs/Ubuntu/ubuntu-16.04.2-server-amd64.iso
==> hyperv-iso: Starting HTTP server on port 8185
==> hyperv-iso: Creating switch 'External' if required...
==> hyperv-iso:     switch 'External' already exists. Will not delete on cleanup...
==> hyperv-iso: Creating virtual machine...
==> hyperv-iso: Enabling Integration Service...
==> hyperv-iso: Setting boot drive to os dvd drive F:/ISOs/Ubuntu/ubuntu-16.04.2-server-amd64.iso ...
==> hyperv-iso: Mounting os dvd drive F:/ISOs/Ubuntu/ubuntu-16.04.2-server-amd64.iso ...
==> hyperv-iso: Skipping mounting Integration Services Setup Disk...
==> hyperv-iso: Mounting secondary DVD images...
==> hyperv-iso: Configuring vlan...
==> hyperv-iso: Starting the virtual machine...
==> hyperv-iso: Waiting 5s for boot...
==> hyperv-iso: Host IP for the HyperV machine: 192.168.100.13
==> hyperv-iso: Typing the boot command...

Enter code here...



This is my packer template hyperv-ubuntu-16.04.json, cloned from https://github.com/taliesins/packer-baseboxes


{
  "variables": {
    "vm_name": "ubuntu-xenial",
    "cpu": "2",
    "ram_size": "2048",
    "disk_size": "21440",
    "iso_url": "F:/ISOs/Ubuntu/ubuntu-16.04.2-server-amd64.iso",
    "iso_checksum_type": "sha256",
    "iso_checksum": "737ae7041212c628de5751d15c3016058b0e833fdc32e7420209b76ca3d0a535",
    "hyperv_switchname": "External",
"username" : "vagrant",
"password" : "vagrant"
  },
  "builders": [
  {
    "vm_name":"{{user `vm_name`}}",
    "type": "hyperv-iso",
    "disk_size": "{{user `disk_size`}}",
    "guest_additions_mode":"disable",
    "iso_url": "{{user `iso_url`}}",
    "iso_checksum_type": "{{user `iso_checksum_type`}}",
    "iso_checksum": "{{user `iso_checksum`}}",
    "communicator":"ssh",
    "ssh_username": "{{user `username`}}",
    "ssh_password": "{{user `password`}}",
    "ssh_timeout" : "4h",
    "http_directory": "./linux/ubuntu/http/",
    "boot_wait": "5s",
    "boot_command": [
      "<esc><wait10><esc><esc><enter><wait>",
      "set gfxpayload=1024x768<enter>",
      "linux /install/vmlinuz ",
      "preseed/url=http://{{.HTTPIP}}:{{.HTTPPort}}/preseed.cfg ",
      "debian-installer=en_US auto locale=en_US kbd-chooser/method=us ",
      "hostname={{.Name}} ",
      "fb=false debconf/frontend=noninteractive ",
      "keyboard-configuration/modelcode=SKIP keyboard-configuration/layout=USA ",
      "keyboard-configuration/variant=USA console-setup/ask_detect=false <enter>",
      "initrd /install/initrd.gz<enter>",
      "boot<enter>"
    ],
    "shutdown_command": "echo 'vagrant' | sudo -S -E shutdown -P now",
    "ram_size": "{{user `ram_size`}}",
    "cpu": "{{user `cpu`}}",
    "generation": 2,
    "switch_name":"{{user `hyperv_switchname`}}",
    "enable_secure_boot":false
  }],
  "provisioners": [{
    "type": "shell",
    "execute_command": "echo 'vagrant' | sudo -S -E sh {{.Path}}",
    "scripts": [
      "./linux/ubuntu/update.sh",
      "./linux/ubuntu/network.sh",
      "./linux/common/vagrant.sh",
      "./linux/common/chef.sh",
      "./linux/common/motd.sh",
      "./linux/ubuntu/cleanup.sh"
    ]
  }],
  "post-processors": [
    {
      "type": "vagrant",
      "keep_input_artifact": true,
      "output": "{{.Provider}}_ubuntu-16.04_chef.box"
    }
  ]
}


Packer log is in this gist


You advise is appreciated.

Thanks,
Mukhtar.

Mukhtar Elhadi

unread,
Mar 3, 2017, 1:25:06 PM3/3/17
to Packer
Sorry I was trying to update my original post and delete it by mistake, so the reply is the original one.

The issue is also with vmware, not only happen with hyper-v

Stuart Luscombe

unread,
Jul 6, 2017, 1:33:57 AM7/6/17
to Packer, mukhta...@gmail.com
Did you find a solution to this issue?

I'm seeing the same thing when trying to build an RHEL 7 image. I can get the OS to install, but after the initial reboot nothing happens. The IP shown by packer will respond to a ping but trying to ssh into the box will not.

Alvaro Miranda Aguilera

unread,
Jul 6, 2017, 3:29:25 AM7/6/17
to packe...@googlegroups.com
Can you share your packer project somewhere?

kickstart + packer template + scripts that set the user you will be using on packer to ssh into

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/f9dd6e65-b40a-4c58-9766-9fc596028403%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Alvaro

Mukhtar Elhadi

unread,
Jul 6, 2017, 7:27:30 AM7/6/17
to Packer, mukhta...@gmail.com
I didn't find a solution that time, so I built the server manually. but I think the issue was related to line feeds and boot command

Stuart Luscombe

unread,
Jul 6, 2017, 7:30:04 AM7/6/17
to Packer
ks.cfg:

#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
cdrom
# Use text install
text
# Keyboard layouts
keyboard --vckeymap=gb --xlayouts='gb'
# System language
lang en_GB.UTF-8
# Network information
network  --bootproto=dhcp --device=eth0 --ipv6=auto --activate
# Root password
rootpw --iscrypted <redacted>
# System services
services --enabled="chronyd"
# System timezone
timezone Europe/London --isUtc
# User acounts
user --groups=wheel --name=packer --password=$6$DcoAmARrcZV75ZyV$zGKlyPg4qgel8GS9H38q3sFGqlkBaDMz7luQrZyJZEDEmBnlwCJxLPMPSCV5//huRl3JBDfHCR.6XMpim0X3V0 --iscrypted --gecos="Packer"
# Partition clearing information
zerombr
clearpart --all
# System bootloader configuration
bootloader --append=" crashkernel=auto" --location=mbr
ignoredisk --only-use=sda
# Disk partitioning information
part /boot --fstype="xfs" --size=1024
part pv.156 --fstype="lvmpv" --grow
part /boot/efi --fstype="efi" --size=200 --fsoptions="umask=0077,shortname=winnt"
volgroup main pv.156
logvol swap  --fstype="swap" --size=2048 --name=swap --vgname=main
logvol /  --fstype="xfs" --grow --size=1024 --name=rootvol --vgname=main

# Accept the EULA
eula --agreed

# Reboot at the end of installation
reboot

%packages
@^minimal
@core
chrony
kexec-tools

%end

%addon com_redhat_kdump --enable --reserve-mb='auto'

%end

%anaconda
pwpolicy root --minlen=6 --minquality=50 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=50 --notstrict --nochanges --notempty
pwpolicy luks --minlen=6 --minquality=50 --notstrict --nochanges --notempty
%end

packer-rhel.json:

{
 "variables": {
   "vm_name": "rhel-7.3",
   "cpu": "1",
   "ram_size": "1024",
   "disk_size": "40960",
   "iso_url": "../iso/os/redhat/rhel-server-7.3-x86_64-dvd.iso",
   "iso_checksum_type": "sha1",
   "iso_checksum": "377B264F3488A623A2155C65F9B9429C9B3F9C35"
 },
 "builders": [
   {
     "vm_name": "{{user `vm_name`}}",
     "type": "hyperv-iso",
     "disk_size": "{{user `disk_size`}}",
     "guest_additions_mode": "disable",
     "iso_url": "{{user `iso_url`}}",
     "iso_checksum_type": "{{user `iso_checksum_type`}}",
     "iso_checksum": "{{user `iso_checksum`}}",
     "communicator": "ssh",
     "ssh_username": "packer",
     "ssh_password": "packer",
     "ssh_timeout": "4h",
     "http_directory": "../linux/rhel-7-server-x64/",
     "boot_command": [
       "<up>e<down><down><end><spacebar>",
       "inst.ks=http://{{.HTTPIP}}:{{.HTTPPort}}/ks.cfg ",
       "network --hostname {{.Name}}",
       "<leftCtrlOn>x<leftCtrlOff>"
     ],
     "shutdown_command": "echo 'packer' | sudo -S shutdown -P now",
     "ram_size": "{{user `ram_size`}}",
     "cpu": "{{user `cpu`}}",
     "generation": 2,
     "enable_secure_boot": false
   }
 ]
}

Interestingly, I ran the example Ubuntu build from the hyperv-iso documentation page and apart from some minor adjustments to the boot_command it completes successfully.

I found that I needed to have an external VM switch created prior to running packer for it to work though.

With the RHEL build I can now SSH into the VM using the created packer account once the install has completed, but packer itself is still timing out waiting for an SSH connection.
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool...@googlegroups.com.



--
Alvaro

Stuart Luscombe

unread,
Jul 6, 2017, 8:14:01 AM7/6/17
to Packer
OK, so I seem to have found the solution for my RHEL build issue.

Firstly, I needed to have an external VM switch already set up in Hyper-V as packer would only create an internal one. This would cause the build to fail as the VM could not get an IP address. Manually setting up an external switch resolved this problem and I was able to perform a full Ubuntu build as per the packer documentation.

Secondly it would appear that the RHEL-provided Hyper-V drivers do not work correctly. I installed the latest ones from Microsoft (https://www.microsoft.com/en-us/download/details.aspx?id=51612), rebooted and almost immediately packer was able to login and do what was needed.

Hopefully this info will help anyone else having the same problem.


Reply all
Reply to author
Forward
0 new messages