Add a custom image to Azure Stack

In this blog post I will explain how you can add multiple custom images to Azure Stack.

At cubesys we have a brand new Azure Stack environment that we use as a demo and test environment for our consultants. Each consultant has his own subscription with pre-defined quotas that they can use to build, test and destroy whenever and whatever they want to test. One of our senior consultants asked me to add the following custom images as he wanted to test and validate a System Center upgrade scenario:

Windows 7 SP1 x64 Enterprise

Windows 8.1 x64 Enterprise

Windows 10 (Build 1511) x64 Enterprise

Windows Server 2008 R2 SP1 Datacenter

Windows Server 2012 Datacenter

So let’s make our tenant happy shall we?

Sysprep the virtual machines

Initially you will have to sysprep the virtual machines.

Create a new virtual machine in Hyper-V

make sure it’s generation 1

and the hard drive needs to be VHDand not VHDX

Install the operating system

Once the operating system is installed you need to sysprep the machine using the following command

For Windows 8 and after:

open a Command Prompt window as an administrator, and then move to the %WINDIR%\system32\sysprep directory.

Run the following command:

[php]Sysprep /generalize /shutdown /oobe /mode:vm[/php]

Anything before Windows 8

open a Command Prompt window as an administrator, and then move to the %WINDIR%\system32\sysprep directory

Run the following command:

[php] Sysprep /generalize /shutdown /oobe [/php]

Once complete the virtual machines will shutdown automatically. Copy the sysprepped virtual hard drives to another location. In my case E:\templates

Add the image to the Platform Image Repository

Once we have all our virtual machines sysprepped and have copied the virtual hard drives we can add them to Azure Stack. To add a new image to Azure stack it needs to be added to the Platform Image Repository or PIR. Microsoft has provided a PowerShell script (CopyImageToPlatformImageRepository.ps1) to do this.

You can find this PowerShell script on the MicrosoftAzureStackPOC.vhd virtual hard drive.

Right click on the vhd file and mount the VHD

Get the Drive letter of the DATAIMAGE drive

Use PowerShell and Navigate to D:\CRP\VM\Microsoft.AzureStack.Compute.Installer\content\Scripts where you will find the CopyImageToPlatformImageRepository.ps1 PowerShell script

After the command completes, restart your browser to see the new item in the Marketplace. The image can now be referenced in your virtual machine deployment templates. In some instances it may take up to 5 minutes for this new image to appear in the Marketplace.