hashicorp / packer

Packer is a tool for creating identical machine images for multiple platforms from a single source configuration.
http://www.packer.io
Other
15.12k stars 3.33k forks source link

"StepUploadTools" on Windows creates 0kb windows.iso VMware guest tool #2930

Closed ryanl-ee closed 7 years ago

ryanl-ee commented 9 years ago

I'm having an issue creating a Windows image in VMware Workstation. I'm using the boxcutter Windows template, but I don't think that is the issue. I'm targeting vmware-iso. "tools_upload_flavor" is set to "windows". "C:\Program Files (x86)\VMware\VMware Workstation\windows.iso" exists.

If I run packer, it will correctly provision and install Windows. It reboots and connects to the VM. It tries to upload the 'windows' VMware tools. It creates "C:\Users\vagrant\windows.iso" but the file is 0kb. There are no errors in the packer log and it will continue until it tries to use 7-zip to extract the iso, which obviously fails. I am able to manually install VMware tools through Workstation. If I run packer with "-debug" and copy the windows.iso from my machine to the guest after it creates the 0kb copy, I can step through the rest of the build successfully.

Thanks for reading and I appreciate any help!

Packer 0.8.6, VMware Workstation Pro 12.0.1.

cbednarski commented 9 years ago

Thanks for the report!

icnocop commented 9 years ago

Which version of Windows are you trying to install?

ryanl-ee commented 9 years ago

Server 2012 R2 Datacenter

icnocop commented 9 years ago

Can you post the relevant part of the packer log (PACKER_LOG=1)?

icnocop commented 9 years ago

Also, this: https://github.com/boxcutter/windows/issues/37

icnocop commented 9 years ago

Can you explicitly set "tools_upload_path": "C:/Users/vagrant/windows.iso" or "tools_upload_path": "c:/Windows/Temp/windows.iso"?

icnocop commented 8 years ago

Are you using win2012r2-datacenter.json?

ryanl-ee commented 8 years ago

Hi @icnocop! Just wanted to let you know I didn't fully complete my tests, but did try overriding with "tools_upload_path": "c:/Windows/Temp/windows.iso" and that worked. I can run it with and without that addition and paste the logs if you'd like.

Yes, I'm using win2012r2-datacenter.json.

vmenajr commented 8 years ago

@icnocop In my case changing to the setting used by @ryanl-ee works in that it forces vmtool.bat to download the tools from the web. The window.iso file in c:/Windows/Temp is still zero bytes however vmtool.bat doesn't look for windows.iso in that folder.

The relevant portion of the log: ==> vmware-iso: Provisioning with shell script: script/vmtool.bat vmware-iso: This version of C:\Windows\wget.exe is not compatible with the version of Windows you're running. Check your computer's system information to see whether you need a x86 (32-bit) or x64 (64-bit) version of the program, and then contact the software publisher. vmware-iso: ==> Downloading "https://softwareupdate.vmware.com/cds/vmw-desktop/ws/12.0.0/2985596/windows/packages/tools-windows.tar" to "C:\Users\vagrant\AppData\Local\Temp\vmware\tools-windows.tar" vmware-iso: ==> Creating "C:\Users\vagrant\AppData\Local\Temp\sevenzip" vmware-iso: ==> Downloading "http://www.7-zip.org/a/7z938-x64.msi" to "C:\Users\vagrant\AppData\Local\Temp\sevenzip\7z938-x64.msi" vmware-iso: This version of C:\Windows\wget.exe is not compatible with the version of Windows you're running. Check your computer's system information to see whether you need a x86 (32-bit) or x64 (64-bit) version of the program, and then contact the software publisher. vmware-iso: ==> Installing "C:\Users\vagrant\AppData\Local\Temp\sevenzip\7z938-x64.msi" vmware-iso: ==> Copying "C:\Program Files\7-Zip\7z.exe" to "C:\Windows" vmware-iso: 1 file(s) copied. vmware-iso: 1 file(s) copied. vmware-iso: vmware-iso: 7-Zip [64] 9.38 beta Copyright (c) 1999-2014 Igor Pavlov 2015-01-03 vmware-iso: vmware-iso: Processing archive: C:\Users\vagrant\AppData\Local\Temp\vmware\tools-windows.tar vmware-iso: vmware-iso: Extracting VMware-tools-windows-10.0.0-2977863.iso vmware-iso: vmware-iso: Everything is Ok

icnocop commented 8 years ago

Sorry, my mistake.

I got confused with this batch script that also installs the VMware tools in the guest: https://raw.githubusercontent.com/joefitzgerald/packer-windows/master/scripts/vm-guest-tools.bat

Notice that script looks for the existence of "C:\Users\vagrant\windows.iso" and "C:\Windows\Temp\windows.iso", etc.

In any case, in regards to vmtool.bat, it should search for the existence of VMwareToolsUpgrader.exe and windows.iso in all drives and %USERPROFILE%. If it doesn't find either of them, it will download tools-windows.tar.

I think I'm also experiencing the issue where vmtool.bat doesn't find D:\VMwareToolsUpgrader.exe and I'm thinking it maybe because the iso has not been mounted yet.

I will try to enable more verbose logging and see what happens.

vmenajr commented 8 years ago

Ran this again and see the following:

2015/11/24 11:40:30 ui: ==> vmware-iso: Uploading the 'windows' VMware Tools
2015/11/24 11:40:30 packer-builder-vmware-iso.exe: 2015/11/24 11:40:30 Uploading file to 'c:/Windows/Temp/windows.iso'
2015/11/24 11:45:17 packer-builder-vmware-iso.exe: #< CLIXML
2015/11/24 11:45:17 packer-builder-vmware-iso.exe: <Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><S S="Error">Exception calling "Join" with "2" argument(s): "Exception of type 'System.OutOf_x000D__x000A_</S><S S="Error">MemoryException' was thrown."_x000D__x000A_</S><S S="Error">At line:14 char:35_x000D__x000A_</S><S S="Error">+             $base64_string = [string]::join &lt;&lt;&lt;&lt; ("",$base64_lines)_x000D__x000A_</S><S S="Error">    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException_x000D__x000A_</S><S S="Error">    + FullyQualifiedErrorId : DotNetMethodException_x000D__x000A_</S><S S="Error"> _x000D__x000A_</S></Objs>
icnocop commented 8 years ago

@vmenajr, I'm not exactly sure why you're getting that error but it's an out of memory exception. Make sure your host and guest have enough free RAM. Which version of packer are you using? What messages appear afterwards?

In regards to vmtool.bat, it could be a timing issue. For a VMware ESX host, packer calls vim-cmd vmsvc/tools.install but doesn't necessarily wait for the vmware tools ISO to be mounted completely. And so by the time vmtool.bat is called, the ISO may still not be completely mounted.

For a VMware Workstation host, I think tools_upload_path is required. @vmenajr, if you set tools_upload_path to c:/Windows/Temp/windows.iso, it shouldn't be zero bytes. Please paste your log if that's still the case.

vmtool.bat will look in %USERPROFILE% for windows.iso, so if you set tools_upload_path to c:/Users/vagrant/windows.iso, it should not need to download tools-windows.tar. If packer still downloads tools-windows.tar in this case, please paste your logs.

Thank you.

icnocop commented 8 years ago

Also, are you using ssh or winrm?

vmenajr commented 8 years ago

@icnocop tried both c:/windows/temp and c:/users/vagrant and zero bytes in both cases. The guest started with 2GB of RAM but I quadrupled it just to see with the same result.

_RAM:_

Here's the log starting with the winrm connection https://gist.github.com/vmenajr/c48f8ea74270e6ff12a3

_Versions:_

Communicator: _winrm_

icnocop commented 8 years ago

ryanl-ee is running on a Windows host, and you are running on Ubuntu.

Does the file /usr/lib/vmware/isoimages/windows.iso exist on your host? Is it more than 0 bytes?

I think tools_upload_path needs to have the file name there too, like c:/Users/vagrant/windows.iso

vmenajr commented 8 years ago

I've also tried it on a windows host with the same result.

Here's the json setting for the path: "tools_upload_path": "c:/users/vagrant/windows.iso",

Here's the iso from the filesystem.

stat /usr/lib/vmware/isoimages/windows.iso File: ‘/usr/lib/vmware/isoimages/windows.iso’ Size: 106168320 Blocks: 207360 IO Block: 4096 regular file Device: fc02h/64514d Inode: 131539 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2015-11-24 21:03:51.209216336 -0500 Modify: 2015-11-24 21:03:51.693225402 -0500 Change: 2015-11-24 21:03:53.361256642 -0500

I notice that packer says "Uploading..." for some time before it errors out so maybe it's a winrm issue.

icnocop commented 8 years ago

You may want to try to increase the winrm timeout. "winrm_wait_timeout": "5m"

Also, see this: https://github.com/packer-community/packer-windows-plugins/issues/25