jetbrains-infra / packer-builder-vsphere

Packer plugin for remote builds on VMware vSphere
Mozilla Public License 2.0
543 stars 175 forks source link

Win7 build, getting "Windows could not apply the unattend answer file's <DiskConfiguration>" #151

Closed shortstack closed 5 years ago

shortstack commented 6 years ago

vSphere 6.7.0 Packer 1.3.1 packer-builder-vsphere 2.0

Cloned the repo, trying to build Windows 7 via vsphere-iso

Getting "Windows could not apply the unattend answer file's "

screenshot 2018-09-25 13 22 20

JSON file:

{
  "builders": [
    {
      "type": "vsphere-iso",

      "vcenter_server":      "10.10.0.9",
      "username":            "xxxxx",
      "password":            "xxxxx",
      "insecure_connection": "true",
      "datacenter": "DFIR Range",

      "vm_name": "windows7",
      "cluster": "HV Cluster",
      "datastore": "hv1",

      "guest_os_type": "windows7_64Guest",

      "communicator": "winrm",
      "winrm_username": "xxxxx",
      "winrm_password": "xxxxx",
      "boot_order": "disk,cdrom",

      "CPUs":             2,
      "CPU_limit":        -1,
      "RAM":              4096,
      "RAM_reserve_all": false,

      "disk_controller_type":  "pvscsi",
      "disk_size":        40960,
      "disk_thin_provisioned": true,

      "network_card": "vmxnet3",
      "network": "d-range-dfir",

      "iso_paths": [
        "[NAS ISO Store] Windows/en_windows_7_professional_with_sp1_x64_dvd_u_676939.iso",
        "[hv1] Windows/vmware-tools.iso"
      ],

      "floppy_files": [
        "{{template_dir}}/setup/"
      ]
    }
  ],

  "provisioners": [
    {
      "type": "windows-shell",
      "inline": ["dir c:\\"]
    }
  ]
}

Autounattend.xml:

<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
    <settings pass="windowsPE">
        <component name="Microsoft-Windows-International-Core-WinPE" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <SetupUILanguage>
                <UILanguage>en-US</UILanguage>
            </SetupUILanguage>
            <InputLocale>en-US</InputLocale>
            <SystemLocale>en-US</SystemLocale>
            <UILanguage>en-US</UILanguage>
            <UserLocale>en-US</UserLocale>
        </component>
        <component name="Microsoft-Windows-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <ImageInstall>
                <OSImage>
                    <InstallFrom>
                        <MetaData wcm:action="add">
                            <Key>/IMAGE/NAME</Key>
                            <Value>Windows 7 PROFESSIONAL</Value>
                        </MetaData>
                    </InstallFrom>
                    <InstallTo>
                        <DiskID>0</DiskID>
                        <PartitionID>1</PartitionID>
                    </InstallTo>
                    <WillShowUI>OnError</WillShowUI>
                </OSImage>
            </ImageInstall>
            <UserData>
                <AcceptEula>true</AcceptEula>
            </UserData>
            <DiskConfiguration>
                <WillShowUI>OnError</WillShowUI>
                <Disk wcm:action="add">
                    <CreatePartitions>
                        <CreatePartition wcm:action="add">
                            <Order>1</Order>
                            <Size>30000</Size>
                            <Type>Primary</Type>
                        </CreatePartition>
                    </CreatePartitions>
                    <ModifyPartitions>
                        <ModifyPartition wcm:action="add">
                            <Active>true</Active>
                            <Extend>true</Extend>
                            <Format>NTFS</Format>
                            <Letter>C</Letter>
                            <Order>1</Order>
                            <PartitionID>1</PartitionID>
                        </ModifyPartition>
                    </ModifyPartitions>
                    <DiskID>0</DiskID>
                    <WillWipeDisk>true</WillWipeDisk>
                </Disk>
            </DiskConfiguration>
        </component>
    </settings>
    <settings pass="oobeSystem">
        <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <UserAccounts>
                <LocalAccounts>
                    <LocalAccount wcm:action="add">
                        <Password>
                            <Value>xxxxx</Value>
                            <PlainText>true</PlainText>
                        </Password>
                        <Description>xxxxx</Description>
                        <DisplayName>xxxxx</DisplayName>
                        <Group>Administrators</Group>
                        <Name>xxxxx</Name>
                    </LocalAccount>
                </LocalAccounts>
            </UserAccounts>
            <AutoLogon>
                <Enabled>true</Enabled>
                <Username>xxxxx</Username>
                <Password>
                    <Value>xxxxx</Value>
                    <PlainText>true</PlainText>
                </Password>
            </AutoLogon>
            <OOBE>
                <NetworkLocation>Work</NetworkLocation>
                <ProtectYourPC>3</ProtectYourPC>
            </OOBE>
        </component>
    </settings>
    <settings pass="specialize">
        <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <ComputerName>*</ComputerName>
            <TimeZone>Central Standard Time</TimeZone>
        </component>
        <component name="Microsoft-Windows-IE-InternetExplorer" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <SearchScopes>
                <Scope wcm:action="add">
                    <ScopeDefault>true</ScopeDefault>
                    <ScopeDisplayName>Google</ScopeDisplayName>
                    <ScopeKey>Google</ScopeKey>
                    <ScopeUrl>http://www.google.com/search?q={searchTerms}</ScopeUrl>
                </Scope>
            </SearchScopes>
            <DisableAccelerators>true</DisableAccelerators>
            <DisableFirstRunWizard>true</DisableFirstRunWizard>
            <Home_Page>about:blank</Home_Page>
            <Help_Page>about:blank</Help_Page>
        </component>
        <component name="Microsoft-Windows-IE-InternetExplorer" processorArchitecture="wow64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <SearchScopes>
                <Scope wcm:action="add">
                    <ScopeDefault>true</ScopeDefault>
                    <ScopeDisplayName>Google</ScopeDisplayName>
                    <ScopeKey>Google</ScopeKey>
                    <ScopeUrl>http://www.google.com/search?q={searchTerms}</ScopeUrl>
                </Scope>
            </SearchScopes>
            <DisableAccelerators>true</DisableAccelerators>
            <DisableFirstRunWizard>true</DisableFirstRunWizard>
            <Home_Page>about:blank</Home_Page>
            <Help_Page>about:blank</Help_Page>
        </component>
        <component name="Microsoft-Windows-TerminalServices-LocalSessionManager" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <fDenyTSConnections>false</fDenyTSConnections>
        </component>
        <component name="Networking-MPSSVC-Svc" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <FirewallGroups>
                <FirewallGroup wcm:action="add" wcm:keyValue="RemoteDesktop">
                    <Active>true</Active>
                    <Group>Remote Desktop</Group>
                    <Profile>all</Profile>
                </FirewallGroup>
            </FirewallGroups>
        </component>
    </settings>
    <settings pass="offlineServicing">
        <component name="Microsoft-Windows-LUA-Settings" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <EnableLUA>false</EnableLUA>
        </component>
    </settings>
</unattend>

Packer output:

    vsphere-iso: Collecting paths from floppy_dirs
2018/09/25 13:12:34 ui:     vsphere-iso: Collecting paths from floppy_dirs
2018/09/25 13:12:34 ui:     vsphere-iso: Resulting paths from floppy_dirs : []
    vsphere-iso: Resulting paths from floppy_dirs : []
2018/09/25 13:12:34 ui:     vsphere-iso: Done copying paths from floppy_dirs
    vsphere-iso: Done copying paths from floppy_dirs
2018/09/25 13:12:34 ui: ==> vsphere-iso: Uploading created floppy image
==> vsphere-iso: Uploading created floppy image
2018/09/25 13:12:39 ui: ==> vsphere-iso: Adding generated Floppy...
==> vsphere-iso: Adding generated Floppy...
==> vsphere-iso: Set boot order...
2018/09/25 13:12:40 ui: ==> vsphere-iso: Set boot order...
2018/09/25 13:12:40 ui: ==> vsphere-iso: Power on VM...
==> vsphere-iso: Power on VM...
2018/09/25 13:12:41 ui: ==> vsphere-iso: Waiting for IP...
==> vsphere-iso: Waiting for IP...

Hangs here ^ because unattend error shows up

boh commented 6 years ago

I can confirm, having the same issue with Windows 2012r2 and Windows 10. I can't bypass the error, tried several Autounattend.xml modifications.

shortstack commented 6 years ago

i was successful with windows 7 after i removed "disk_controller_type": "pvscsi"

bigvlc commented 6 years ago

You are using "disk_controller_type": "pvscsi" which drivers are not available by default you have to provide them in Autounattend.xml:

B:\

And mount them from datastore: "floppy_img_path": "[datastore1] ISO/vmtools/pvscsi-Windows8.flp"

boh commented 5 years ago

Correct, the floppies correctly placed on the datastore made it work. Deleting the "disk_controller_type": "pvscsi" in my case did not help.

mkuzmin commented 5 years ago

The suggestion above is correct. If you want using paravirtual SCSI type, external drivers should be provided on floppy

henshin commented 5 years ago

On the latest version of VMWare Tools (tested on 10.3.10), we need to specify the folder on the floppy as well. It seems that Windows doesn't look on the floppy directories recursively. So the autounattended.xml should look like this:

<component name="Microsoft-Windows-PnpCustomizationsWinPE" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <DriverPaths>
        <PathAndCredentials wcm:action="add" wcm:keyValue="A">
            <!-- pvscsi-Windows8.flp -->
            <Path>B:\AMD64\</Path>
        </PathAndCredentials>
    </DriverPaths>
</component>    
fivener commented 4 years ago

I have a new vSphere 6.7 U3 setup in my lab and the vmimages folder did not actually contain any .flp files. Got impatient looking for the files elsewhere and ended up just mounting the VMware Tools ISO on my local machine (D:) and sftp'd the driver files from D:\Program Files\VMware\VMware Tools\Drivers\pvscsi\Win8\amd64 into the setup folder under the project working directory. The same directory defined for the "floppy_files" in the packer build config. This directory is mounted as A:\ in the VM.

  "floppy_files": [
    "{{template_dir}}/setup/"

Then set the path in the Autounattended.xml for the driver to A:\

<component name="Microsoft-Windows-PnpCustomizationsWinPE" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <DriverPaths>
        <PathAndCredentials wcm:action="add" wcm:keyValue="A">
            <!-- pvscsi-Windows8.flp -->
            <Path>A:\</Path>
        </PathAndCredentials>
    </DriverPaths>
</component>

The build completed without issue.

niko-dunixi commented 3 years ago

I ran into this issue as well, not really understanding it it took me a lot of time to read through threads like this one to understand how it applied to myself. This thread is specifically about Windows 7, but searching in Google for Windows 10 brings this up as a primary result so I'm sharing my personal findings here for future searchers.

I'm still not sure why vSphere presents the hardware differently from other virtualization software (such as VirtualBox) and requires a driver installation first, but it does. I had the most success specifying the controller type as pvscsi

disk_controller_type = [
  "pvscsi",
]

With the Windows10 installation ISO as the first virtual CD, I also needed to find and attach our VMWare tools ISO as a second CD (typically found at [datastore1] ISO/VMware Tools/10.2.0/windows.iso, ours was in a different location [] /usr/lib/vmware/isoimages/windows.iso).

iso_paths = [
  "[Network-Install] Media/Microsoft/Win10/en_windows_10_business_editions_version_2004_updated_oct_2020_x64_dvd_732b2088.iso",
  "[] /usr/lib/vmware/isoimages/windows.iso",
]

To account for both x86 and x64 drivers, we need to add two sections to the Autounattend.xml file

<component name="Microsoft-Windows-PnpCustomizationsWinPE" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <DriverPaths>
        <PathAndCredentials wcm:action="add" wcm:keyValue="A">
            <Path>E:\Program Files\VMware\VMware Tools\Drivers\pvscsi\Win8\amd64</Path>
        </PathAndCredentials>
    </DriverPaths>
</component>
<component name="Microsoft-Windows-PnpCustomizationsWinPE" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <DriverPaths>
        <PathAndCredentials wcm:action="add" wcm:keyValue="A">
            <Path>E:\Program Files\VMware\VMware Tools\Drivers\pvscsi\Win8\i386</Path>
        </PathAndCredentials>
    </DriverPaths>
</component>

With these individual pieces brought together I was able to get Windows up and running