Unattended Windows installation is done via 'Answer Files', or 'Unattend files'.
These files are generally named 'autounattend.xml'. They are notPacker-specific tools, though we do make use of them.
If, after following this guide, you're still having issues getting an answerfile working, We recommend you read the official documentation onanswer files.
The guide here is hopefully enough to get you started, but isn't a replacementfor the official documentation.
»When To Use an Answer File
If you are installing the Windows Operating System from a mounted iso as part ofyour Packer build, you will need to use an Answer file. For example, you'rebuilding an image from scratch using the vmware-iso,virtualbox-iso, orhyperv-iso builders.
If you are not installing the operating system, you won't need to provide ananswer file. If you are using a pre-built imagein a cloud, you don't need to worry about Answer files.
»How to make an Answer File
You can either start from an example answer file from a known repo (take a lookat the examples links below), or you can generate one using an answer filewizard by selecting New File > New Answer file on a Windows machine.A comprehensive list of all the options you can set in an answer file can befound here
»Where to put the Answer File
Windows will automatically look for an autounattend.xml file on mounted drives.Many users use the floppy_files
option or a secondary mounted iso forproviding the answer file to their iso builders.
You can also specify an unattend file to use by using the /unattend: option whenrunning Windows Setup (setup.exe) in your boot_command
.
- May 29, 2019 Create media for automated unattended install of Windows 10. Note that this tutorial assumes that you will create a sysprep image. If you want to do an unattended installation with only an autounattend.xml answer file do this: Follow all the steps up through section 3.18 of the tutorial. Then skip to section 4.
- Where is the unattend file stored after you install Windows?Helpful? Please support me on Patreon: thanks & praise.
Windows Unattend File Recovery
»What does Packer need the Answer File to do?
Packer needs the Answer File to handle any questions that would normally beanswered interactively during a Windows installation.
Search order #8 can also apply to your setup: Drive from where Windows Setup (setup.exe) is running, at the root of the drive. The name of the answer file must be Unattend.xml or Autounattend.xml, and must be located at the root of the Windows Setup folder path. Where is the unattend file stored after you install Windows?Helpful? Please support me on Patreon: thanks & praise. Nov 07, 2019 Search order #8 can also apply to your setup: Drive from where Windows Setup (setup.exe) is running, at the root of the drive. The name of the answer file must be Unattend.xml or Autounattend.xml, and must be located at the root of the Windows Setup folder path.
Windows Unattend File System
If you want to be able to use provisioners, the Answer file must also containa script that sets up SSH or WinRM so that Packer can connect to the instance.
Finally, your Packer build will be much smoother if the Answer File handles ordisables windows updates rather than you tyring to run them using a Packerprovisioner. This is because the winrm communicator does not handle thedisconnects caused by automatic reboots in Windows updates well, and thedisconnections can fail a build.
»Examples
Windows Unattend File Transfer
The chef-maintained bento boxes are a great example of a windows build thatsets up openssh as part of the unattended installation so that Packer canconnect using the SSH communicator. They functioning answer files for everymodern Windows version can be found here.
Stefan Scherer's packer-windows repois a great example of windows builds that set up WinRM as part of the unattendedinstallation so that Packer can connect using the winrm communicator:
One of the biggest time drains when deploying a new Windows client or server is installing Windows itself. The wizard that comes with the install forces you to set various configuration settings ahead of time so that Windows knows how to install the operating system. Let’s automate this by finding where the autounattend.xml location is and how to create an autounattend XML file.
The start of automating on a Windows machine is typically after the install process. After all, you’ve got to have a platform to automate on, right? Not really. In fact, if installing Windows from a WIM or ISO file, it’s possible to completely automate the install step too using a single well-placed file.
Autounattend.xml
Automating a Windows install requires a file called AutoUnattend.xml. Remember that name. It must be exactly that name when placed inside of the ISO. This is an XML file that can act as an install answer file answering each of those setup questions ahead of time, so you don’t have to.
The first task is to create this file. Because this file must be structured in a specific way, it’s always a good idea to start from a template. You can download an example template here to get started. This file is broken down into the different phases of a
Windows install.
- windowsPE (bootstrapping and disk configuration)
- specialize (setting computer name, users, etc.)
- oobeSystem (local administrator password, etc.)
If you’d like to start from scratch, another useful method of creating this template is with the Windows File Answer Generator. This autounattend generator is a website that provides a wizard-like interface to answer simple questions which will create an unattended XML file for you.
By either choosing to use an existing template or the Windows File Answer Generator site, it’s most likely the template must be modified by hand.
Since the XML is strict about the structure and specific nodes, it’s probable that the first version of your template will not work as expected. However, before we get into that, let’s at least give the first version a try.
Inserting the Autounattend XML in the ISO
Once you have the AutoUnattend.xml file created, it’s now time to insert it into the Windows ISO into the required autounattend XML location.
Unfortunately, there’s not an easy way to make this happen without third-party tools. Options include WinISO or use a combination of extracting and creating a new ISO file with 7Zip. Either way, the process is not as automated as you might want to think, but as of this writing, I could find no other way.
Once you’ve decided on a method to insert a file into the ISO, it’s now time to place the AutoUnattend.xml file into the root of ISO. There are a few other places this file can be placed but I’ve found it easier to put it in the root.
Start the Automated Install
When the file has been put into the root of the ISO, and a new ISO has been generated, it’s now time to test it out. At this point, all the hard work is done. Just attach the ISO as a media drive in your virtualization platform of choice and start up the VM.
The only difference now is that you’ll see instead of being prompted with
questions, the install will just run entirely hands off. Once complete, Windows will be installed, and any additional scripts or configuration you’ve applied will have been set!
Windows Unattend File Location
Summary
Performing a Windows unattended install all comes down to creating a well-formed autounattend.xml. Using the example I’ve provided and the Windows File Answer Generator site, you should have everything you need to start automating Windows OS deployments in no time!
Windows Unattend File Format
More from Adam The Automator & Friends