joefitzgerald / packer-windows

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

add Packer template for Windows XP #266

Open Wenzel opened 6 years ago

Wenzel commented 6 years ago

This is an attempt to create a Packer template for Windows XP, and open WinRM for provisioners. Work in Progress

WinRM requires DotNet 2.0. I had to add wget in the floppy to download the necessary files after the initial installation is done.

At this point, WinRM is installed and I'm calling a setup_winrm.bat script to open it, but somehow Packer cannot connect to it :/

If anyone is interest and can give me some help, i would appreciate !

Thanks.

StefanScherer commented 6 years ago

Wow. What is the use case for that? I mean, other than collecting packer templates ;-) Edit: OK your profile gives me some tips why someone wants to build XP in 2008. It's still alive.

When I started with Packer years ago I also thought about Win XP, but never found a way to do this.

Instead of using wget, what about some built-in tools (maybe bitsadmin.exe, or other things described eg. in https://stackoverflow.com/questions/4619088/windows-batch-file-file-download-from-a-url)

lmayorga1980 commented 6 years ago

I thought it was out of support until I found this...

screenshot from 2018-05-04 08-51-35

StefanScherer commented 6 years ago

😨

Wenzel commented 6 years ago

@StefanScherer Wow. What is the use case for that? I mean, other than collecting packer templates ;-)

Let's say i'm an archaeologist :) And for the sake of completeness !

Instead of using wget, what about some built-in tools (maybe bitsadmin.exe, or other things described eg. in https://stackoverflow.com/questions/4619088/windows-batch-file-file-download-from-a-url)

The thing is that there is no Powershell 2.0 in Windows XP ... So you need to download something to give you powershell.

I tried many things to download files natively, even VBscript: https://github.com/Wenzel/packer-templates-winxp/blob/3f606178602090258d2ba6d1e400a0a8b358a450/scripts/download_dotnet2.0.vbs

' Set your settings
strFileURL = "https://download.microsoft.com/download/0/8/c/08c19fa4-4c4f-4ffb-9d6c-150906578c9e/NetFx20SP1_x86.exe"
strHDLocation = "c:\temp\dotnet.exe"

' Fetch the file
Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")

objXMLHTTP.open "GET", strFileURL, false
objXMLHTTP.send()

If objXMLHTTP.Status = 200 Then
    Set objADOStream = CreateObject("ADODB.Stream")
    objADOStream.Open
    objADOStream.Type = 1 'adTypeBinary

    objADOStream.Write objXMLHTTP.ResponseBody
    objADOStream.Position = 0    'Set the stream position to the start

    Set objFSO = Createobject("Scripting.FileSystemObject")
    If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation
        Set objFSO = Nothing

        objADOStream.SaveToFile strHDLocation
        objADOStream.Close
        Set objADOStream = Nothing
    End if

    Set objXMLHTTP = Nothing
End if

But it always failed. And as i'm not a VBScript expert, i prefered to just add the wget binary.

But if you can figure out how to use this bitsadmin, go for it =)

lmayorga1980 commented 6 years ago

I wonder how a Packer template with Win95 will look with this inside.

prince_of_persia_ 1989_video_game _ibm_pc_version_gameplay

Wenzel commented 6 years ago

@lmayorga1980

challenge-accepted-meme

Seems like it's possible ! https://www.youtube.com/watch?v=BfWw8ALGCQ0

StefanScherer commented 6 years ago

I just looked into my MSDN downloads and found some XP downloads with type "CDR" - I had to think what this could be. Wow, we were able install operating systems from CD-ROM 😆

StefanScherer commented 6 years ago

I gave it some minutes and added the vmware-iso section. But my problem is that I don't see a network card in the VM. VMware Fusion tells me that the e1000 network card is present.

Wenzel commented 6 years ago

When i tested with Qemu, i had internet access after the installation.

Is it not the case for you on vmware ?

Wenzel commented 6 years ago

I made some progress since last time. First, WinRM was not opened because of an Access Denied issue.

This has been solved by disabling the forceguest key. see this forum for more information.

Now WinRM is opened, but misconfigured. When packer tries to connect, it returns 401 - invalid content type screenshot from 2018-06-11 17-09-06

Any ideas ? We are close ! Thanks !

StefanScherer commented 6 years ago

Wow! Maybe something like this https://github.com/masterzen/winrm/issues/75, there also is a link to a blog post by Matt Wrock.

Wenzel commented 6 years ago

hi @StefanScherer , thanks for the link.

I tested my winrm setup script on a dedicated VM, and attempted a connection with PyWinRM: screenshot from 2018-06-12 15-49-05

so this winrm script is not working only in the context of packer. Maybe it's a bug in the packer winrm code ?

joefitzgerald commented 6 years ago

This PR is fantastic! @sneal can you summon the WinRM gods?

Wenzel commented 6 years ago

@joefitzgerald i actually found the issue. The problem does not come from WinRM, but Windows XP.

It turns out that the WINNT.sif configuration that i provided will setup an account named Administrator with the vagrant password, and not vagrant/vagrant as i expected.

Therefore the WinRM error is totally correct !

Right now i'm trying to tweak the autounattend file to setup an admin vagrant/vagrant account :)

Wenzel commented 6 years ago

I have my first successful build of this packer template on QEMU ! :tada: screenshot from 2018-06-12 17-03-51 WinRM connection is working.

Looking at this forum, it seems that setting the user accounts are the responsability of another file oobeinfo.inf

You don't create user accounts with WinNT.sif - that would be done either with oobeinfo.inf, or the NET command (put in to a batch command file).

So let's not go too complicated for this PR.

TODO:

StefanScherer commented 6 years ago

Thanks @Wenzel for all the hard work. I'll try to find some time to test again with vmware-iso soon.

The product key from MSDN shouldn't be added.

What we need in general would be this https://github.com/hashicorp/packer/issues/4530 to be able to insert variables into static floppy files. That would help all Windows Packer templates.

lavahot commented 5 years ago

@StefanScherer, from what I can tell from folks who have worked with Packer before, like in mwrock/packer-templates, the pattern to use to prep files is to use some external tool to template the files before a run and then run your packer command. For example, if you want to parameterize an autounattend.xml file you would put some unique string in the file as a parameter, "{{ user windowsKey }}" and replace it: (Get-Content $file) -replace "{{ *userwindowsKey*}}", $windowsKey

Wenzel commented 5 years ago

@StefanScherer I removed the product key from WINNT.SIF and cleared the template. What's the next step for this PR ?

(Sorry i forgot that it was still opened :) )