joefitzgerald / packer-windows

Windows Packer Templates
MIT License
1.63k stars 1.12k forks source link

Packer build hangs on SSH when building Win 2012 Server + Virtualbox #180

Closed tommasodargenio closed 8 years ago

tommasodargenio commented 8 years ago

I'm trying to use virtualbox+packer+vagrant to automate the provisioning of VMs.

I've got the json template setup to show the VM UI (so headless=false), and configured the autounattend.xml with my ISO key and the OpenSSH Server option to be installed as first.

The issue is that the vm creation get stuck on the "Waiting for SSH" log entry, I can see the VM running and the prompt for entering the Windows Key but nothing else happen.

Any help is appreciated

this is the output up to that point from packer build, at which point I've aborted the installation

PS C:\Users\xxxxxxx\Documents\DevVM> packer build .\windows_2012_r2.json 
virtualbox-iso output will be in this color.
==> virtualbox-iso: Downloading or copying Guest additions
    virtualbox-iso: Downloading or copying: file:///C:/Program%20Files/Oracle/VirtualBox/VBoxGuestAdditions.iso
==> virtualbox-iso: Downloading or copying ISO
    virtualbox-iso: Downloading or copying: file:///C:/Users/xxxxxxx/Documents/Work/VMs/ISOs/en_windows_server_2012_r2_x64_dvd_2707946.iso
==> virtualbox-iso: Creating floppy disk...
    virtualbox-iso: Copying: C:/Users/xxxxxxx/Documents/DevVM/Autounattend.xml
    virtualbox-iso: Copying: C:/Users/xxxxxxx/Documents/DevVM/GitHub/packer-windows/scripts/microsoft-updates.bat
    virtualbox-iso: Copying: C:/Users/xxxxxxx/Documents/DevVM/GitHub/packer-windows/scripts/win-updates.ps1
    virtualbox-iso: Copying: C:/Users/xxxxxxx/Documents/DevVM/GitHub/packer-windows/scripts/openssh.ps1
    virtualbox-iso: Copying: C:/Users/xxxxxxx/Documents/DevVM/GitHub/packer-windows/scripts/oracle-cert.cer
==> virtualbox-iso: Creating virtual machine...
==> virtualbox-iso: Creating hard drive...
==> virtualbox-iso: Attaching floppy disk...
==> virtualbox-iso: Creating forwarded port mapping for SSH (host port 4430)
==> virtualbox-iso: Executing custom VBoxManage commands...
    virtualbox-iso: Executing: modifyvm packer-virtualbox-iso-1443107958 --memory 2048
    virtualbox-iso: Executing: modifyvm packer-virtualbox-iso-1443107958 --cpus 2
==> virtualbox-iso: Starting the virtual machine...
==> virtualbox-iso: Waiting 2m0s for boot...
==> virtualbox-iso: Typing the boot command...
==> virtualbox-iso: Waiting for SSH to become available...
==> virtualbox-iso: Unregistering and deleting virtual machine...
==> virtualbox-iso: Deleting output directory...
Build 'virtualbox-iso' errored: Build was cancelled.
Cleanly cancelled builds after being interrupted.

This is the autounattend.xml part with the openssh entry

 <FirstLogonCommands>
            <SynchronousCommand wcm:action="add">
                <CommandLine>cmd.exe /c C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File a:\openssh.ps1 -AutoStart</CommandLine>
                <Description>Install OpenSSH</Description>
                <Order>1</Order>
                <RequiresUserInput>true</RequiresUserInput>
            </SynchronousCommand>        

I've also tried to change the order of the above as last command (order=23) but with no effect.

This is a part of the json template

 "type": "virtualbox-iso",
  "iso_url": "C:/Users/xxxxxx/Documents/Work/VMs/ISOs/en_windows_server_2012_r2_x64_dvd_2707946.iso",
  "iso_checksum_type": "md5",
  "iso_checksum": "0e7c09aab20dec3cd7eab236dab90e78",
  "headless": false,
  "boot_wait": "2m",
  "ssh_username": "vagrant",
  "ssh_password": "vagrant",
  "ssh_wait_timeout": "10m",
  "shutdown_command": "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"",
  "guest_os_type": "Windows2012_64",
  "disk_size": 61440,
  "floppy_files": [
    "C:/Users/xxxxxx/Documents/DevVM/Autounattend.xml",
    "C:/Users/xxxxxx/Documents/DevVM/GitHub/packer-windows/scripts/microsoft-updates.bat",
    "C:/Users/xxxxxx/Documents/DevVM/GitHub/packer-windows/scripts/win-updates.ps1",
    "C:/Users/xxxxxx/Documents/DevVM/GitHub/packer-windows/scripts/openssh.ps1",
    "C:/Users/xxxxxx/Documents/DevVM/GitHub/packer-windows/scripts/oracle-cert.cer"
  ],
StefanScherer commented 8 years ago

If the VM hangs and Windows requests to enter the key, there is something wrong in Autounattend.xml with your key. The OpenSSH will be installed a long way after your problem. Just your ISO and key and the xml tags for the key in the Autounattend.xml to get it run. The headless=false mode really helps here.

kensykora commented 8 years ago

The ISO that it's configured to use is specifically a trial ISO and I'm not sure if just any Key will be able to activate it. If you're providing your own key, I've found that you need to also provide your own ISO also.

tommasodargenio commented 8 years ago

Thanking you all for the feedback. I've managed to fix the issue which was very stupid, I realized that there was this in the autounattend script

<WillShowUI>OnError</WillShowUI>

which brought up the license key screen on the UI, meaning there was something wrong with it (now I realize, instead I thought it couldn't input the license key and was hanging there). Indeed of all license key I had I managed to pick the only one that was expired (didn't check the expire column in my spreadsheet as was further down), once I've put in one that wasn't expired already everything worked flawlessly.

@kensykora the iso files are not bound to the license keys, as long as they are of the same type. I have production licenses and production ISOs, obviously I won't be able to use a production license on a trial ISO and viceversa.