joefitzgerald / packer-windows

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

Building Windows 10 fails - 'virtualbox-iso' errored: Timeout waiting for SSH. #217

Open Tset-Noitamotua opened 7 years ago

Tset-Noitamotua commented 7 years ago

Im trying to build Windows 10 with Virtualbox (while running on a Windows 7 host). Then running with headless = false the VM comes up and seems to run properly but on my command line (from where I called packer build windows_10.json) I see ==> virtualbox-iso: Waiting for SSH to become available... for a long time (may be about one hour) until it finally fails with the following lines:

==> virtualbox-iso: Timeout waiting for SSH.
==> virtualbox-iso: Unregistering and deleting virtual machine...
==> virtualbox-iso: Deleting output directory...
Build 'virtualbox-iso' errored: Timeout waiting for SSH.

==> Some builds didn't complete successfully and had errors:
--> virtualbox-iso: Timeout waiting for SSH.

==> Builds finished but no artifacts were created.
StefanScherer commented 7 years ago

Which ISO file do you use? We probably should update the template to latest 1607 eval ISO.

Tset-Noitamotua commented 7 years ago

I used the code as is and did not change anything thus the ISO which is referenced in windows_10.json file was used.

"iso_url": "http://care.dlservice.microsoft.com/dl/download/C/3/9/C399EEA8-135D-4207-92C9-6AAB3259F6EF/10240.16384.150709-1700.TH1_CLIENTENTERPRISEEVAL_OEMRET_X64FRE_EN-US.ISO"

StefanScherer commented 7 years ago

OK. I'm online only with a tablet, so not able to test and build a PR. But have a look at https://github.com/StefanScherer/packer-windows/commit/579f24a2861396fcd28ce57b7bbe774a3552af1d And try it with this ISO. You also may send a PR if it works.

Tset-Noitamotua commented 7 years ago

I have recently downloaded 1607, too but with German local (http://care.dlservice.microsoft.com/dl/download/C/2/D/C2DF88E2-3BAF-4AC9-9AF0-B195ADA6CC60/14393.0.160715-1616.RS1_RELEASE_CLIENTENTERPRISEEVAL_OEMRET_X64FRE_DE-DE.ISO)

May I also try with it (to avoid downloading) or would this require more changes in the code than just editing the url in windows_10.json file?

StefanScherer commented 7 years ago

Should work, Update Autounattend.xml as in my commit, maybe select keyboard type etc., calculate the SHA1 sum of that iso and update windows_10.json or run packer with --var iso_url=youriso --var iso_checksum=yourshasum

Tset-Noitamotua commented 7 years ago

I took the ISO that you suggested but same behavior here:

C:\_GITHUB\packer-windows-pilot
λ packer build --only=virtualbox-iso --var iso_url="C:\Users\username\Documents\__Virtual Machines\Windows 10 Enterprise 90 Day Trials\14393.0.160715-1616.RS1_RELEASE_CLIENTENTERPRISEEVAL_OEMRET_X64FRE_EN-US.ISO" --var iso_checksum=a86ae3d664553cd0ee9a6bcd83a5dbe92e3dc41a windows_10.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/username/Documents/__Virtual%20Machines/Windows%2010%20Enterprise%2090%20Day%20Trials/14393.0.160715-1616.RS1_RELEASE_CLIENTENTERPRISEEVAL_OEMRET_X64FRE_EN-US.ISO
==> virtualbox-iso: Creating floppy disk...
    virtualbox-iso: Copying: ./answer_files/10/Autounattend.xml
    virtualbox-iso: Copying: ./scripts/fixnetwork.ps1
    virtualbox-iso: Copying: ./scripts/microsoft-updates.bat
    virtualbox-iso: Copying: ./scripts/win-updates.ps1
    virtualbox-iso: Copying: ./scripts/openssh.ps1
    virtualbox-iso: Copying: ./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 communicator (SSH, WinRM, etc) (host port 3881)
==> virtualbox-iso: Executing custom VBoxManage commands...
    virtualbox-iso: Executing: modifyvm packer-virtualbox-iso-1471523338 --memory 2048
    virtualbox-iso: Executing: modifyvm packer-virtualbox-iso-1471523338 --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: Timeout waiting for SSH.
==> virtualbox-iso: Unregistering and deleting virtual machine...
==> virtualbox-iso: Deleting output directory...
Build 'virtualbox-iso' errored: Timeout waiting for SSH.

==> Some builds didn't complete successfully and had errors:
--> virtualbox-iso: Timeout waiting for SSH.

==> Builds finished but no artifacts were created.

Is it necessary to go with SSH? Can´t the image be configured with WinRM from the start? My experience with SSH was and still is a little messy whenever I am confronted with it. I even could say I hate it - always trouble with SSH! ;-))) Guess I need to take a training on SSH :-/

OK. There is one last thing I have to try - I turned off Windows Updates. So I will try again with updates turned on.

Tset-Noitamotua commented 7 years ago

Btw ... isn´t there a "communicator": "winrm" missing in "builders" section of windows_10.json ?

StefanScherer commented 7 years ago

Oh yes, I forgot that. The winrm fixes are in the branch jf/switch-to-winrm https://github.com/joefitzgerald/packer-windows/blob/jf/switch-to-winrm/windows_10.json

It's time to contribute some of that in master branch... But there also is the conductor branch with a major refactoring.

Tset-Noitamotua commented 7 years ago

Now it seems to hang at ==> virtualbox-iso: Waiting for WinRM to become available...:

C:\_GITHUB\packer-windows (jf/switch-to-winrm)
λ packer build --only=virtualbox-iso --var iso_url="C:\Users\username\Documents\__Virtual Machines\Windows 10 Enterprise 90 Day Trials\14393.0.160715-1616.RS1_RELEASE_CLIENTENTERPRISEEVAL_OEMRET_X64FRE_EN-US.ISO" --var iso_checksum=a86ae3d664553cd0ee9a6bcd83a5dbe92e3dc41a windows_10.json
virtualbox-iso output will be in this color.

==> virtualbox-iso: Downloading or copying ISO
    virtualbox-iso: Downloading or copying: file:///C:/Users/username/Documents/__Virtual%20Machines/Windows%2010%20Enterprise%2090%20Day%20Trials/14393.0.160715-1616.RS1_RELEASE_CLIENTENTERPRISEEVAL_OEMRET_X64FRE_EN-US.ISO
==> virtualbox-iso: Creating floppy disk...
    virtualbox-iso: Copying: ./answer_files/10/Autounattend.xml
    virtualbox-iso: Copying: ./scripts/fixnetwork.ps1
    virtualbox-iso: Copying: ./scripts/disable-winrm.ps1
    virtualbox-iso: Copying: ./scripts/enable-winrm.ps1
    virtualbox-iso: Copying: ./scripts/microsoft-updates.bat
    virtualbox-iso: Copying: ./scripts/win-updates.ps1
    virtualbox-iso: Copying: ./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 communicator (SSH, WinRM, etc) (host port 3201)
==> virtualbox-iso: Executing custom VBoxManage commands...
    virtualbox-iso: Executing: modifyvm packer-virtualbox-iso-1471599826 --memory 2048
    virtualbox-iso: Executing: modifyvm packer-virtualbox-iso-1471599826 --cpus 2
==> virtualbox-iso: Starting the virtual machine...
==> virtualbox-iso: Waiting 2m0s for boot...
==> virtualbox-iso: Typing the boot command...
==> virtualbox-iso: Waiting for WinRM to become available...

According to the screenshots below it looks like its hanging in an endless loop(?)

Screenshot from VM: image

image

Tset-Noitamotua commented 7 years ago

I forgot something, too. I am behind a corporate proxy. Thus Windows updates cant´t work. So I need to turn them off.

Or is there a possibility to "burn" proxy settings into the image by Packer?

e.g. the following powershell script seemed to work through winrm for a Windows 7 box. It was called from a Vagrantfile

config.vm.provision "shell",
    path: "set_global_proxy.ps1"
# content of set_global_proxy.ps1
$ErrorActionPreference = "Stop"
# set global proxy (in Internet Options)
$reg = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
Set-ItemProperty -Path $reg -Name ProxyServer -Value "http://proxy_host_name:proxy_port"
Set-ItemProperty -Path $reg -Name ProxyEnable -Value 1
StefanScherer commented 7 years ago

You probably have to add this script to floppy files and run it from Autounattend.xml. Other scripts also want to download things like sdelete etc.

Tset-Noitamotua commented 7 years ago

Thanks. Internet Options (set proxy) configured succesfully! I did as you suggested and added set_global_proxy.ps1 to Autounattend.xml and to windows_10.json

Autounattend.xml

<SynchronousCommand wcm:action="add">
    <CommandLine>cmd.exe /c C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File a:\set_global_proxy.ps1</CommandLine>
    <Description>Enable WinRM</Description>
    <Order>100</Order>
</SynchronousCommand>

windows_10.json

 "floppy_files": [
        "{{user `autounattend`}}",
        "./scripts/fixnetwork.ps1",
        "./scripts/disable-winrm.ps1",
        "./scripts/enable-winrm.ps1",
        "./scripts/set_global_proxy.ps1",
        "./scripts/microsoft-updates.bat",
        "./scripts/win-updates.ps1",
        "./scripts/oracle-cert.cer"
      ]
Tset-Noitamotua commented 7 years ago

I am now at the point there it states:

...
virtualbox-iso: SDelete v2.0 - Secure file delete
virtualbox-iso: Copyright (C) 1999-2016 Mark Russinovich
virtualbox-iso: Sysinternals - www.sysinternals.com
virtualbox-iso:
virtualbox-iso: SDelete is set for 1 pass.

How long does it take from here to finish (approx.)?

StefanScherer commented 7 years ago

@Tset-Noitamotua Did sdelete finish? On my machine it's about 10-15 minutes, but only a guess.

Tset-Noitamotua commented 7 years ago

I dont know yet. It was not ready as I went home. But I have left my PC turned on and will check later. Stefan Scherer notifications@github.com schrieb am Fr., 19. Aug. 2016 um 21:34:

@Tset-Noitamotua https://github.com/Tset-Noitamotua Did sdelete finish? On my machine it's about 10-15 minutes, but only a guess.

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/joefitzgerald/packer-windows/issues/217#issuecomment-241114261, or mute the thread https://github.com/notifications/unsubscribe-auth/AFX9hpLLz5V0qDIr-T5OInGXHatZuTf0ks5qhgVFgaJpZM4Jmgp1 .

avtar commented 7 years ago

I'm using Packer 0.10.1, Vagrant 1.8.4, and VirtualBox 5.0.26 (saw the same behaviour with 5.0.22 as well) and I left a Packer build running for about 1.5 hours with the https://github.com/StefanScherer/packer-windows/commit/579f24a2861396fcd28ce57b7bbe774a3552af1d changes but without success. SDelete wasn't able to finish within that time. Here's a screenshot of Resource Monitor running in the guest. The VirtualBox Guest Additions service wasn't running either.

$ VBoxManage.exe showvminfo packer-virtualbox-iso-1471887384
Name:            packer-virtualbox-iso-1471887384
Groups:          /
Guest OS:        Windows 10 (64-bit)
UUID:            f150b36a-63c3-4f8d-a2e9-7c9b782c8403
Config file:     C:\Users\avtar\VirtualBox VMs\packer-virtualbox-iso-1471887384\packer-virtualbox-iso-1471887384.vbox
Snapshot folder: C:\Users\avtar\VirtualBox VMs\packer-virtualbox-iso-1471887384\Snapshots
Log folder:      C:\Users\avtar\VirtualBox VMs\packer-virtualbox-iso-1471887384\Logs
Hardware UUID:   f150b36a-63c3-4f8d-a2e9-7c9b782c8403
Memory size:     2048MB
Page Fusion:     off
VRAM size:       8MB
CPU exec cap:    100%
HPET:            off
Chipset:         piix3
Firmware:        BIOS
Number of CPUs:  2
PAE:             on
Long Mode:       on
CPUID Portability Level: 0
CPUID overrides: None
Boot menu mode:  message and menu
Boot Device (1): HardDisk
Boot Device (2): DVD
Boot Device (3): Not Assigned
Boot Device (4): Not Assigned
ACPI:            on
IOAPIC:          on
Time offset:     0ms
RTC:             local time
Hardw. virt.ext: on
Nested Paging:   on
Large Pages:     on
VT-x VPID:       on
VT-x unr. exec.: on
Paravirt. Provider: Default
State:           running (since 2016-08-22T17:36:40.444000000)
Monitor count:   1
3D Acceleration: off
2D Video Acceleration: off
Teleporter Enabled: off
Teleporter Port: 0
Teleporter Address:
Teleporter Password:
Tracing Enabled: off
Allow Tracing to Access VM: off
Tracing Configuration:
Autostart Enabled: off
Autostart Delay: 0
Default Frontend:
Storage Controller Name (0):            IDE Controller
Storage Controller Type (0):            PIIX4
Storage Controller Instance Number (0): 0
Storage Controller Max Port Count (0):  2
Storage Controller Port Count (0):      2
Storage Controller Bootable (0):        on
Storage Controller Name (1):            Floppy Controller
Storage Controller Type (1):            I82078
Storage Controller Instance Number (1): 0
Storage Controller Max Port Count (1):  1
Storage Controller Port Count (1):      1
Storage Controller Bootable (1):        on
IDE Controller (0, 0): C:\users\avtar\Downloads\tmp\packer-windows\output-virtualbox-iso\packer-virtualbox-iso-1471887384.vdi (UUID: 5e267868-e4e5-48f4-bd99-d4c267d12be6)
IDE Controller (0, 1): C:\users\avtar\Downloads\tmp\packer-windows\packer_cache\efc726ba407ac1dc2e937593416019501aa478207d31b870ccc0290fcd4ce9ef.iso (UUID: 0b46bae7-ee11-4fb6-bdc9-793b3bec8edf)
Floppy Controller (0, 0): C:\msys64\tmp\packer334193858\floppy.vfd (UUID: c4c4121a-93b6-4e8c-8a24-acc435a0b310)
NIC 1:           MAC: 080027D60890, Attachment: NAT, Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none
NIC 1 Settings:  MTU: 0, Socket (send: 64, receive: 64), TCP Window (send:64, receive: 64)
NIC 1 Rule(0):   name = packercomm, protocol = tcp, host ip = 127.0.0.1, host port = 3586, guest ip = , guest port = 22
NIC 2:           disabled
NIC 3:           disabled
NIC 4:           disabled
NIC 5:           disabled
NIC 6:           disabled
NIC 7:           disabled
NIC 8:           disabled
Pointing Device: PS/2 Mouse
Keyboard Device: PS/2 Keyboard
UART 1:          disabled
UART 2:          disabled
UART 3:          disabled
UART 4:          disabled
LPT 1:           disabled
LPT 2:           disabled
Audio:           disabled
Clipboard Mode:  disabled
Drag and drop Mode: disabled
Session name:    GUI/Qt
Video mode:      1024x768x0 at 0,0 disabled
VRDE:            enabled (Address 127.0.0.1, Ports 5912, MultiConn: off, ReuseSingleConn: off, Authentication type: null)
VRDE port:       5912
Video redirection: disabled
VRDE property: TCP/Ports  = "5912"
VRDE property: TCP/Address = "127.0.0.1"
VRDE property: VideoChannel/Enabled = <not set>
VRDE property: VideoChannel/Quality = <not set>
VRDE property: VideoChannel/DownscaleProtection = <not set>
VRDE property: Client/DisableDisplay = <not set>
VRDE property: Client/DisableInput = <not set>
VRDE property: Client/DisableAudio = <not set>
VRDE property: Client/DisableUSB = <not set>
VRDE property: Client/DisableClipboard = <not set>
VRDE property: Client/DisableUpstreamAudio = <not set>
VRDE property: Client/DisableRDPDR = <not set>
VRDE property: H3DRedirect/Enabled = <not set>
VRDE property: Security/Method = <not set>
VRDE property: Security/ServerCertificate = <not set>
VRDE property: Security/ServerPrivateKey = <not set>
VRDE property: Security/CACertificate = <not set>
VRDE property: Audio/RateCorrectionMode = <not set>
VRDE property: Audio/LogPath = <not set>
USB:             disabled
EHCI:            disabled
XHCI:            disabled

USB Device Filters:

<none>

Available remote USB devices:

<none>

Currently Attached USB Devices:

<none>

Bandwidth groups:  <none>

Shared folders:  <none>

VRDE Connection:    not active
Clients so far:     0

Video capturing:    not active
Capture screens:    0
Capture file:       C:\Users\avtar\VirtualBox VMs\packer-virtualbox-iso-1471887384\packer-virtualbox-iso-1471887384.webm
Capture dimensions: 1024x768
Capture rate:       512 kbps
Capture FPS:        25

Guest:

Configured memory balloon size:      0 MB
OS type:                             Windows10_64
Additions run level:                 1
Additions version:                   5.0.26 r108824

Guest Facilities:

Facility "VirtualBox Base Driver": active/running (last update: 2016/08/22 17:49:03 UTC)
Facility "Seamless Mode": not active (last update: 2016/08/22 17:49:03 UTC)
Facility "Graphics Mode": not active (last update: 2016/08/22 17:49:03 UTC)
lmayorga1980 commented 7 years ago

Same configuration as @avtar but on VBOX 5.0.24. Had to lock it there after a few compatibility issues on windows and osx. sDelete takes around 45 -60 mins in my Windows 7 workstation

Tset-Noitamotua commented 7 years ago

Back at office PC. Does not look good:

    virtualbox-iso: SDelete is set for 1 pass.
    virtualbox-iso: Zeroing free space on C:\: 0%
==> virtualbox-iso: Unregistering and deleting virtual machine...
==> virtualbox-iso: Deleting output directory...
Build 'virtualbox-iso' errored: Script exited with non-zero exit status: 1

==> Some builds didn't complete successfully and had errors:
--> virtualbox-iso: Script exited with non-zero exit status: 1

==> Builds finished but no artifacts were created.

But I can't say what went wront as I did not monitored the guest. Is there a log or something on host that could give more insight?

Will try again on updated VBox and Vagrant as I ran on VBox 5.0.16 and Vagrant 1.8.1.

Tset-Noitamotua commented 7 years ago

Upgraded VirtualBox and Vagrant:

λ Vboxmanage -v
5.1.4r110228

λ vagrant -v
Vagrant 1.8.5

And ... finally ... after approx. 3 - 4 hours build finished successfully:

    virtualbox-iso: SDelete v2.0 - Secure file delete
    virtualbox-iso: Copyright (C) 1999-2016 Mark Russinovich
    virtualbox-iso: Sysinternals - www.sysinternals.com
    virtualbox-iso:
    virtualbox-iso: SDelete is set for 1 pass.
    virtualbox-iso: Free space cleaned on C:\
    virtualbox-iso: 1 drive cleaned.
==> virtualbox-iso: Gracefully halting virtual machine...
    virtualbox-iso: Removing floppy drive...
==> virtualbox-iso: Preparing to export machine...
    virtualbox-iso: Deleting forwarded port mapping for the communicator (SSH, WinRM, etc) (host port 3722)
==> virtualbox-iso: Exporting virtual machine...
    virtualbox-iso: Executing: export packer-virtualbox-iso-1471940492 --output output-virtualbox-iso\packer-virtualbox-iso-1471940492.ovf
==> virtualbox-iso: Unregistering and deleting virtual machine...
==> virtualbox-iso: Running post-processor: compress
==> virtualbox-iso (compress): Zipping virtualbox-iso.zip
==> virtualbox-iso (compress): Archive virtualbox-iso.zip completed
Build 'virtualbox-iso' finished.

==> Builds finished. The artifacts of successful builds are:
--> virtualbox-iso: VM files in directory: output-virtualbox-iso
--> virtualbox-iso: '' compressing: virtualbox-iso.zip
Tset-Noitamotua commented 7 years ago

Several times during packer build process one do not see any progress from the host side e.g. when udefrag.exe, sdelete.exe or Exporting virtual machine is running. Is it possible to get more insight at these parts of the process - a progress bar would be cool :)

avtar commented 7 years ago

I had to kill the process on one computer with an SSD that was taking over two hours with no signs of ending and started it on another computer with a faster NVMe drive but just sdelete still took just under two hours to finish. The end result is that a new box did get created but I remember the sdelete process taking about 10 - 15 minutes in the past.

Tset-Noitamotua commented 7 years ago

Any idea why it takes so long now? And is it really necessary? What is it good for (to keep image size small)? Are there other options worth to try?

rustamkulenov commented 7 years ago

I decided not to run sdelete to save time. I suppose, that VirtualBox uses IDE interface for hard disk (at least, on my current VM). That's why the process is so slow. You can try to change disk interface via "vboxmanage" params. May be some drivers are required for SATA\SCSI.

Tset-Noitamotua commented 7 years ago

@rustamkulenov And what's the impact of not running sdelete? Is the resulting image much bigger?

rustamkulenov commented 7 years ago

You can try to remove "compact.bat" at all and run. It will finish much faster. As I remember, the size was something like 9Gb for Windows 2012R2 Server. After importing this image into Vagrant box, it shrinks it to 6Gb. Actually, I never used sdelete because it was to long for me, I always got "timeout error". May be because I'm building images inside ubuntu VM and it is slower than real PC.

Tset-Noitamotua commented 7 years ago

I think it's definitely worth to try. Just finished building Windows 10 Enterprise which took exactly 3 hours and created a Vagrant .box file of 3,86 GB.

Will try without compact.bat next to see how big the resulting box will be.

SUMMARY

I played around with Windows 10 part of jf/switch-to-winrm branch. Considering the slight changes discussed above one can get it running successfully even behind a corporate proxy. Though some things still could be done to enhance usage of this repo:

kensykora commented 7 years ago

The purpose of these scripts always has been to produce the smallest possible image, knowing that one of the outputs of this could be a vagrant box that you'd use to vagrant up -- downloading 9gb vs 6gb vs 3gb makes a huge difference. Build time generally shouldn't be a huge consideration because these images can be created on a build server. Obviously a goal should be to keep the file AND build time as low as possible, but IMO file size is more important than build time (more people will need to download / extract the artifact than those that will need to build an artifact)

StefanScherer commented 7 years ago

It seems that sdelete takes longer recently, but I haven't measured it exactly.

On interesting thing about size is that using these packer templates and enhancing them for the upcoming(?) hyperv builder it turned out that that skipping the compact step results in smaller images as discussed here https://github.com/StefanScherer/packer-windows/commit/f1ebb93af11fd63d6756d69403467f85d0f2d695 which resulted in this commit https://github.com/PatrickLang/packer-windows/commit/b38ca2fbdb4d120fd8f8c2f07b60aaadab0652e1 to skip defrag and sdelete for hyperv-iso builder.