clalancette / oz

Automated installation for guest images
GNU Lesser General Public License v2.1
310 stars 129 forks source link

Windows 7, 8, 8.1 and 10 unattended installs fails for me. #268

Open itamarjp opened 5 years ago

itamarjp commented 5 years ago

I have downloaded windows 10 iso from

https://www.microsoft.com/en-us/software-download/windows10ISO

oz fails complaining about product key, I think product key should be enclosed inside key /key element

windows-10-fail

I would like to request a feature that allow us to pass a raw file without oz trying to replace windows password and serial key, allowing us to debug the unattended file.

itamarjp commented 5 years ago

@kriegsmanj Can you help to fix this issue ?

chrisoldwood commented 4 years ago

I don't have enough knowledge yet to put together a formal PR with a fix for the Windows 10 template and Python code so I'm just going to dump what I found out here for anyone else who stumbles across this in the meantime.

The reason for the error is that the autounattend.xml file format has changed slightly and you need to put the product key in a different place. I don't know when it changed but for Windows 10 build 1909 it needs to go in the <UserData> section, e.g.

<UserData>
  <AcceptEula>true</AcceptEula>
  <FullName>Mr Admin</FullName>
  <Organization></Organization>
  <ProductKey>
    <Key>W269N-WFGWX-YVC9B-4J6C9-T83GX</Key>
  </ProductKey>
</UserData>

Note: this is the product key for Windows 10 Pro (English) which can be gleaned from Microsoft's KMS client setup keys page.

You can either edit the underlying template or use the -a switch (which is what I did) and override it on the command line by providing a complete autounattend.xml file instead, e.g.

$ oz-install windows10.tdl -a autounattend.xml

That said, this still wasn't quite enough to get me a fully automated Windows installation, at least not with build 1909. The second issue I ran into relates to the <UserAccounts> section (although it's not entirely impossible that I've just made a silly mistake here). I found that the <AdministratorPassword> section in the template needed to be replaced with a <LocalAccount> instead, and a minor tweak to the <AutoLogon> like this:

<UserAccounts>
  <LocalAccounts>
    <LocalAccount wcm:action="add">
      <Password>
        <Value>oz-admin</Value>
        <PlainText>true</PlainText>
      </Password>
      <Description></Description>
      <DisplayName>Oz Admin</DisplayName>
      <Group>Administrators</Group>
      <Name>Oz-Admin</Name>
    </LocalAccount>
  </LocalAccounts>
</UserAccounts>
<AutoLogon>
  <Password>
    <Value>oz-admin</Value>
    <PlainText>true</PlainText>
  </Password>
  <Enabled>true</Enabled>
  <Username>Oz-Admin</Username>
</AutoLogon>

Ultimately I was guided by the output from the Windows Answer File Generator. Instead of just using the generated file as-is though I tried to patch the Oz template instead to see whether I could narrow down the differences as much as possible. I still have some potentially superfluous changes in my working example, like a removed <InstallFrom> section and duplicate <ProductKey> in the old "specialize" section but I need to keep experimenting to see if this is in fact the case.

chrisoldwood commented 4 years ago

Here is the final version of the autounattend.xml that I ended up with. This was for the Windows 10 Pro (English) build 1909 .iso downloaded from Microsoft page: Download Windows 10 Disc Image (ISO File).

I also noticed that the indentation of the template was a little off which I think is down to the use of tabs ala Notepad style, i.e. 8-spaces wide. I tried to avoid touching as much as possible to help make the eventual diff and fix easier to apply later.

<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
  <settings pass="windowsPE">
    <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">
      <DiskConfiguration>
    <!-- <WillShowUI>OnError</WillShowUI> -->
    <Disk>
      <CreatePartitions>
        <CreatePartition>
          <Order>1</Order>
          <Size>1</Size>
          <Type>Primary</Type>
        </CreatePartition>
      </CreatePartitions>
      <DiskID>0</DiskID>
      <WillWipeDisk>true</WillWipeDisk>
      <ModifyPartitions>
        <ModifyPartition>
          <Active>true</Active>
          <Extend>true</Extend>
          <Format>NTFS</Format>
          <Label>C drive</Label>
          <Letter>C</Letter>
          <Order>1</Order>
          <PartitionID>1</PartitionID>
        </ModifyPartition>
      </ModifyPartitions>
    </Disk>
      </DiskConfiguration>
      <ImageInstall>
    <OSImage>
      <InstallTo>
        <DiskID>0</DiskID>
        <PartitionID>1</PartitionID>
      </InstallTo>
      <!-- <WillShowUI>OnError</WillShowUI> -->
    </OSImage>
      </ImageInstall>
      <UserData>
        <AcceptEula>true</AcceptEula>
        <FullName>Oz-Admin</FullName>
        <Organization></Organization>
        <ProductKey>
          <Key>W269N-WFGWX-YVC9B-4J6C9-T83GX</Key>
        </ProductKey>
      </UserData>
    </component>
    <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>
      <SystemLocale>en-US</SystemLocale>
      <UILanguage>en-US</UILanguage>
      <UserLocale>en-US</UserLocale>
    </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>oz-admin</Value>
                            <PlainText>true</PlainText>
                        </Password>
                        <Description></Description>
                        <DisplayName>Oz Admin</DisplayName>
                        <Group>Administrators</Group>
                        <Name>Oz-Admin</Name>
                    </LocalAccount>
                </LocalAccounts>
            </UserAccounts>
            <AutoLogon>
                <Password>
                    <Value>oz-admin</Value>
                    <PlainText>true</PlainText>
                </Password>
                <Enabled>true</Enabled>
                <Username>Oz-Admin</Username>
            </AutoLogon>
      <OOBE>
    <NetworkLocation>Work</NetworkLocation>
    <HideEULAPage>true</HideEULAPage>
    <ProtectYourPC>3</ProtectYourPC>
    <SkipMachineOOBE>true</SkipMachineOOBE>
    <SkipUserOOBE>true</SkipUserOOBE>
      </OOBE>
      <FirstLogonCommands>
    <SynchronousCommand wcm:action="add">
      <Order>1</Order>
      <Description>Turn Off Network Selection pop-up</Description>
      <CommandLine>cmd /c reg add "HKLM\SYSTEM\CurrentControlSet\Control\Network\NewNetworkWindowOff"</CommandLine>
    </SynchronousCommand>
    <SynchronousCommand wcm:action="add">
      <Order>2</Order>
      <Description>Shutting down Windows</Description>
      <CommandLine>cmd /C shutdown /s /t 0</CommandLine>
    </SynchronousCommand>
      </FirstLogonCommands>
    </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>Windows10-OZ</ComputerName>
      <ProductKey>W269N-WFGWX-YVC9B-4J6C9-T83GX</ProductKey>
    </component>
  </settings>
</unattend>

P.S. One other mistake I made for a while was using the English International .iso instead of the plain English one and even though I got the right product key I still found it threw up the UI so reverted my attempts to use a UK locale. That was also why I've commented out the <WillShowUI> sections in the hope of seeing an error message instead.