Adding Windows Server 2012 R2 Image to Azure Stack

In a previous post I covered how to add a Linux image to Azure Stack.  In this post I am going to detail a simple (if slow) way of adding a Server 2012 R2 image to Azure Stack as well.  With Azure Stack TP3 (original and extra-crispy) there are no default VM Images included in the install.  You are prompted to download a Windows Server 2016 ISO as part of the Azure Stack POC download, and there is a script in the AzureStack.ComputeAdmin module called New-Server2016Image that will take that ISO and turn it into a Core or Datacenter image.  But what if you wanted that good ole Server 2012 R2 image?

For whatever reason, VM Images are not yet part of the marketplace syndication.  So you are on your own when it comes to creating them.  So I figured, why not go to the source?  I can spin up a Windows Server 2012 R2 Datacenter VM in Azure, sysprep it, and then copy the VHD down locally.  Then using the Add-VMImage cmdlet in AzureStack.ComputeAdmin I’ll add it to the Azure Stack Install.  That is essentially what the script below does.

This set of commands is meant to be run from the MAS-CON01 VM, and it assumes that you have installed the proper version of AzureRM PowerShell and the AzureStack tools from Github.  You also need to have a valid subscription in Azure, obviously, in which to spin up the VM.  The commands assume that you have already logged into Azure Cloud and selected the proper subscription.  There are a few fields to change here and there and I have added <> on either side of the text to indicate a necessary change.  The ARM template being used is sitting on my GitHub, but feel free to use whatever template you like.  The key is to allow WinRM traffic from the public subnet so that the script can remote in and sysprep the server.  These commands could easily be repurposed to capture custom VM images using other operating systems too, assuming they support WinRM.  I am looking into turning this into a proper script that can take some arguments and do the whole thing for you, but that’s not quite ready yet.  Minimum Viable Product right?  Lastly, the image is a whopping 128GB in size, so be congizant of that when you select a destination location for the VHD.  I picked the SU1Fileserver share as a target since it should have ample space, but your mileage may vary.

Occasionally the token for uploading the VHD and creating the Gallery Item will time out.  In that case, you can manually add the image and create the gallery item.  I’m working with the Azure Stack team to fix that particular issue, possibly checking for token status after the initial VHD upload and refreshing it if expired.

Leave a Reply

Your email address will not be published. Required fields are marked *