Creating a Base Image for use in Windows Azure

This is the third blog post on the subject of creating and deploying a SharePoint farm in Windows Azure. The previous two are:

    In this post we will create an image that can be used when creating virtual machines. The advantage of this is, that it gives you the ability to “pack” the image/disk, both with software (installed or just the binaries) and – in our case – with an extended OS-disk.
    I assume that you have followed the initial steps and created the VNET, the storage account and the affinity group.
    We will use one of the images supplied in the gallery. To get the available images, submit the following command from a Windows Azure PowerShell prompt:

Get-AzureVMImage | Select ImageName

This will give you something similar to:

image

The name of the VM, Cloud Service and VHD-disk in the script below is not important as we will delete them later.

# Your Storage account
$storageAccount = “mystorageaccount”

# Your subscription name
$subscriptionName = “MySubscription“

Select-AzureSubscription $subscriptionName
Set-AzureSubscription $subscriptionName -CurrentStorageAccount $storageAccount

# VM Paramaters
$imageName = “a699494373c04fc0bc8f2bb1389d6106__Windows-Server-2012-Datacenter-201301.01-en.us-30GB.vhd”
$size = “Small”
$mediaLocation = “
http://mystorageaccount.blob.core.windows.net/vhds/
$subnet = “SP-AppSubnet”
$password =
“P@ssw0rd” # This will be the password for the VM

$vmName = “sp-base”
$vmStorageLocation = $mediaLocation + “sp-base.vhd”
$bi = New-AzureVMConfig -Name $vmName ‘
-InstanceSize $size -ImageName $imageName ‘
-MediaLocation $vmStorageLocation
Add-AzureProvisioningConfig -Windows -Password $password -VM $bi
Set-AzureSubnet -SubnetNames $subnet -VM $base

# Cloud Service Paramaters
$serviceName = “BaseServiceImage”
$serviceLabel = “BaseServiceImage”
$serviceDesc = “Base Image. Will be deleted”
$ag = “SP-AG”

# Create the Base VM
New-AzureVM -ServiceName $serviceName ‘
-ServiceLabel $serviceLabel  ‘
-ServiceDescription $serviceDesc `
-AffinityGroup $ag -VMs $bi

We now have a plain VM running Windows Server 2012.

The following will be displayed in the PowerShell windows

image

If you log on to the management portal you will see the new VM under virtual machines. I have removed the name of the subscription due to certain confidentiality considerations, hence the black bar.

image

image

Next step is to extend the disk.

First we need to delete the VM just created. Ensure it is selected and then click Delete from the bottom menu.

image

and confirm

image

The system will begin to remove the VM.

image

and after a short while

image

Next step is to delete the disk.

Select Disk from the top menu

image

If the delete process is not completed you will see that the VM is still having a lease on the disk

image

Wait until the lease has expired

image

Delete the disk, but retail the VDH-file. This is very important as this is the one we wish to extend.

image

If you look in your storage account under the container vhds you can see, that the VHD-file is still there

image

Maarten Balliauw has created a small utility that will change the header information on the VHD-file allowing us to extend it. The maximum size is 127 GB; we will make it 100 GB.

Download the WindowsAzureDiskResizer tool from GitHub.

The syntax is the following:

image

You can get the accountname and accountkey from the storage page in the management portal.

As stated previously I set the size to 100

image

Before the tool was executed the VHD-file looked like this. Notice the size.

image

After running the tool the picture is the following:

image

Next step is to create an image using the VDH-file.

Select Images from the top menu under Virtual Machines.

image

and then click Create in the bottom menu

image

Enter a name and browse to the sp-base.vhd file

image

You need to check the “I have run Sysprep” even though that is not the case.

When the process is complete you can see the new image is available

image

We now want to create a new VM based on this new image, extend the disk from the Disk Manager, copy any software onto the disk or install it and when capture that VM.

I will show how this is done using the management portal, but you could amend the script above and just set the image name to

$imageName = “spbaseimage”

Select Virtual Machine Instances from the top menu

image

and then New from the bottom one.

image

You want to create a new VM from the gallery

image

Using your new image (the other two images are some I have created previously)

 

image

Give the VM a name, password and select the size

image

Give the VM a public facing DNS name and place it in the VNET. As we are actually not going to use this VM for anything other than begin the “template” for further work, it is more to ensure it is placed in our storage account.

 

image

Click OK to kick off the creating process.

Once the VM has been provisioned you want to open a Remote Desktop session (RDP) and log into it.

Enter the Disk Management

You can see the “original” 30 GB and the new unallocated 70 GB

image

Right click on C and select Extend Volume.

image

This will open up the Extend Volume Wizard.

image

Click Next.

Select the disk and the maximum size

image

and click Next again.

image

Click Finish to complete the wizard.

You now have a single OS volume of 100 GB.

image

The final step is to run Sysprep.

This is usually found in C:\Windows\System32\sysprep

Remember to set the Shutdown Option to Shutdown.

image

Press OK.

You can now Capture the VM. Select it and click Capture from the bottom menu. The VM has to be stopped before you can select the menu item.

image

Give the image a name and select the Sysprep option.

 

image

This turned out to be quite a long post.

In the next one in the series we will create the virtual machines for the two domain controllers and look at how to promote them to DCs.

About strobaek

.NET developer/architect. Runner, espresso drinker and lover of gourmet food.
This entry was posted in Azure. Bookmark the permalink.

Leave a Reply

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