Fast Windows VM provisioning using SysPrep

Image by Colossus Cloud from Pixabay

One of the benefits of having a Virtualization server is having the ability to deploy and destroy machines at will. However, this process can be a little tedious and time-consuming. In my experience, the average windows installation took somewhere around 20-25minutes, and a Linux machine around 15-20minutes, and on top of that adding your own preliminary tools adds another 10-15minutes. Fast Linux provisioning can be achieved using cloud-init, this is what is used in cloud environments like Azure, GCP, AWS, etc. However, I was not able to find any solution that was reliable and worked as smoothly as cloud-inti for Windows. There is one called cloudbase-init however, it did not work well with my Hypervisor, thus I had to look for other primitive methods.

One such method is Sysprep, which is a utility that prepares the machine for the next boot. This simple utility can be utilized to create multiple copies of the Windows OS faster, this can be made even faster if you use “Linked Clones” rather than “Full Clones” in the hypervisor.

My requirements were simple

  • Change the hostname to something random. Something specific would have been ideal, but I was okay with a random one.
  • Preserve admin account and it’s the password for reliable logins and minimal configuration
  • Have few pre-installed tools in the system such as 7-zip, MS Edge, and Sublime Text.

So there are 2 major steps for Sysprep, one is getting the system into audit mode, to prepare it i.e. install software and other necessary configurations, the other step is to run the Sysprep utility with a file called, unattend.xml it contains all the data about how to configure the system after the first boot.

Step 1 – Getting the system into audit mode

There are 2 ways you can get into audit mode of Sysprep. This mode can be utilized to configure the default state of the windows machine i.e. install software, configure system-wide settings, etc.

  1. While installing the windows machine, the first time, on the screen shown below, press CTRL+SHIFT+F3 to boot into the audit mode directly. This will help you skip the agony of logging in to the system even for once.

2. The other way of getting into Sysprep audit mode, on an existing system where you have already logged in, run the Sysprep utility. C:\Windows\System32\Sysprep\sysprep.exe this will get you the dialog box, shown on the screen below. Select “Audit mode”, and tick generalize, and “Reboot”, and click “OK”. On the next boot, you’ll be in the Audit Mode.

Once you are in the audit mode, configure your system as per your linking, install software, make configuration changes, literally do anything that you’d like all your systems to have, and once done, we’ll move onto the next step.

Step 2 – Running Sysprep with unattend.xml file

So this step is rather important in the whole “faster provisioning” process, this is about creating an unattended installation file, which will do all the initial options for us without us interfering in the process. It may range from setting passwords, activating windows, setting up auto-login, expanding drives, etc. The unattended installation file ensures that all the processes are taken care of and our windows machine is ready and configured once the boot process is complete.

So to create an unattended file we’ll use an online utility located here, chose the system which you plan to Sysprep, and select all the appropriate options you wish to apply to the system. Out of all the sub-steps “OOBE” one is the most important, so configure the file appropriately.

Once you have configured the file save it on your machine and run it with the following parameters in the Sysprep utility.

Once the Sysprep steps are complete, the machine will shutdown. Now do not turn on this machine ever, if your Hypervisor has an option of turning this into a template please do so, this will ensure you don’t accidentally start it up.

Now to create a new machine with this template, simply clone this machine, I’d prefer a linked clone rather than a full clone, because it links the files back to this template and ensures faster cloning, but do as you wish. Now you can turn on the cloned machine, and it should boot up and complete the process in under 3-4 minutes on an HDD, it will obviously be faster on an SSD but the process won’t take any longer than 3-4minutes. Now you’ll have a newly configured machine, ready for use without the hassle of installing the windows all over again.

If you have questions or need help setting things up, reach out to me @jtnydv