EDIT: 2011/04/14 – I’m working on another method of doing this since it appears that this only works sporadically or no longer works as written. I will update this post if I can figure out where the disconnect / issues are.
I’ve been experimenting with creating a good Windows Server 2008 R2 template for VMware vSphere 4 and wondered just how many times Microsoft would allow an activation on the same MSDN license key (Multiple Activation) for the OS. I often deploy multiple servers at a time and am always fearful of activating since I don’t want the key to be shut off. Typically I only run these servers for short periods of time so not activating is no big deal, however in longer running projects I often have no choice but to either activate or destroy and redeploy. With information that I’ve come across on the Internet, I’ve managed to consolidate a method that does not break the Windows Server 2008 activation, while still sysprep’ing and generating a new SID.
This process can be used for other virtualized environments as well I’m sure, but in this case I created it for VMware vSphere.
Create and Activate a Windows Server 2008 R2 VM.
Download the WAIK (Windows Automated Installation Kit) from Microsoft. This is a pretty good sized download (almost 2 GB if I remember correctly) so go and grab a cup of coffee or something, or watch the Jack Bauer Power Hour (also known as ‘24’), or something to pass the time while downloading. You’ll also need a copy of the Windows Server 2008 R2 DVD, so if you don’t have that handy, log into your MSDN account and pull it down as well.
After downloading the WAIK, install it on your workstation. You do not need to run it from the target machine. I configured this on my Win 7 development box. We’re going to create an unattend.xml file to be used with Sysprep to configure the template.
After the WAIK install, run Windows System Image Manager (WSIM) (located in Start > Programs > Microsoft Windows AIK > Windows System Image Manager by default). Insert your Windows Server 2008 R2 DVD into your local drive, or mount the image. You’ll need files from it.
Choose File > Select Windows Image…
Navigate to your server CD/DVD in the Select a Windows Image browser. Inside the ‘Sources’ directory, choose the version of Windows Server that you want to create the unattend file for.
This should add the Catalog information to the lower left hand area of WSIM as seen below.
Create or Open an Answer File in the ‘Answer File’ area of WSIM.
Expand Components and drag and drop to the ‘Answer File’ area as pictured and described:
- Under 3 Generalize
- Under 4 Specialize
- Under 7 oobeSystem
In case you’re like me and wondered if amd64 meant that it was for amd processors, the amd64_… items are for all 64 bit platforms whether Intel or AMD.
Keep in mind that 99% of these settings are personal choice for my template. The ONE that really matters is coming up very shortly.
Clicking on the items in the middle ‘Answer File’, I made the following adjustments using the area on the right ‘… properties’. The item in bold below (amd_64_Microsoft-Windows-Security-SPP_neutral: SkipRearm = 1) setting is the setting that will keep Windows from needing to reactivate after Sysprep has been run.
- 3 generalize
- DoNotOpenInitialConfigurationTasksAtLogon = true
- SkipRearm = 1
- DoNotOpenServerManagerAtLogon = true
- 4 specialize
- DisableAccelerators = true
- DisableFirstRunWizard = true (this one really drives me nuts)
- Home_Page = about:blank
- ShowCompatibilityViewButton = true
- TrustedSites = [any sites that you want to automatically be trusted by the browser – separated by semi-colons]
- ProductKey = [your product key… can’t have mine. 😉 ]
- RegisteredOrganization = [your company name]
- RegisteredOwner = [your name]
- TimeZone = [your time zone – Mountain Standard Time]
- 7 oobeSystem
- InputLocale = [your localization info ie. en-US]
- SystemLocale = [your localization info ie. en-US]
- UILanguage = [your localization info ie. en-US]
- UserLocale = [your localization info ie. en-US]
- (click the plus sign to get to these) Display > Color Depth = 32
- Display > HorizontalResolution = [your preferred width – ie. 1024]
- Display > VerticalResolution = [your preferred height – ie. 768]
- OOBE > HideEULAPage = true
- UserAccounts > AdministratorPassword = [your local admin password]
You can check out the documentation and continue customizing until your heart is content. Once again, the important flag to set is SkipRearm = 1. This will prevent you from having to reactivate Windows.
When your customization is complete, go to File > Save Answer File. I named mine ‘unattend.xml’.
In your Windows Server 2008 R2 virtual machine, copy the unattend.xml file into the following path:
Create the following path if it doesn’t exist:
Inside the ‘scripts’ directory, create a text file with the following line inside:
del /Q /F c:windowssystem32sysprepunattend.xml
This will delete the unattend.xml file that you have stored after sysprep completes, otherwise the file will still be there. Name the file ‘SetupComplete.cmd’. It is VERY important to make sure that you give this file the .cmd extension and not allow it to keep the .txt extension. Make sure that ‘hide file extensions for known file types’ is unchecked inside the folder view options. You should see an icon similar to the one below, instead of the typical text file icon.
You’re almost ready to Sysprep the environment now.
I cloned the VM at this point so that I would have a clean environment in which to go back and make changes to, like running Windows Updates, etc., for when I need to generate a new template or an updated template.
Read the following paragraphs in their entirety before doing anything further. You can lose your template if you reboot a sysprep’ed VM.
If you’ve made all the changes / installations / etc. to the OS and have your unattend file configuration completed, on the server, from the command prompt (you should run the command prompt as Administrator), run the following commands.
sysprep /generalize /oobe /shutdown /unattend:unattend.xml
This ‘sysprep’ command tells sysprep to use configuration information from the ‘generalize’ node and ‘oobe’ node of the xml file. The ‘specialize’ section will run automatically and does not need to be included as a parameter. The ‘shutdown’ switch tells the system to shutdown after sysprep completes, in case you were wondering. 😉
After sysprep finishes running and the system shuts down, it is VERY IMPORTANT that you DO NOT START THE SERVER (as in reboot). Upon reboot, sysprep will run it’s commands and you will have a new system. If you do this, you just lost your template, though I guess nothing would stop you from simply sysprep’ing your system again.
In vCenter, immediately right-click this virtual machine and select ‘Template’ > ‘Clone to Template’ or ‘Convert to Template’ based on what you want to do with the original.
When deploying a virtual machine from this template, make sure to choose ‘Do Not Customize’ in the Deploy Template wizard > Guest Customization screen. Your customizations are already baked into the OS thanks to Microsoft. When you boot the new VM, you will see sysprep configuring the OS.
Thanks to all the bloggers out there whose information helped me to consolidate this post. Also, thanks Microsoft for including this feature and providing such thorough documentation.