This post discusses how to create an image from a VHD file of a VM you have on Windows Azure to re-use it with other VMs and also shows a resolution to the issue/error: “xxx.vhd is already registered with image repository as the resource with ID xxx” on Windows Azure management portal.
I have a nice windows azure virtual machine with its .vhd drive that I managed to get to an excellent state with all my software installed, configured and working smoothly. I wanted to make this VHD as an Image in my Windows Azure cloud account so that I can create multiple virtual machines (VM) based on the same VHD disk. Here is what I did:
First, I did a sysprep on this nice VM as follows: On the Virtual Machine, Open command prompt as an administrator and navigate to your C:\Windows\System32\Sysprep folder. Then run the Sysprep.exe file. Make sure the generalise option is ticked and select “quit” instead of “shut down” in the actions after sysprep (There is a known issue that happens sometimes when you select shutdown).
Once this is done, I have shut down my VM, went to my Windows Azure management / Control Panel (http://manage.windowsazure.com) and selected the VM and then deleted it. Make sure you select the option to delete VM and retain / keep the VHD hard disk files attached to this VM. This will only delete the Virtual Machine but will keep the VHD virtual disks for you.
Following that, if you go and try to create an image for ths VHD file, you will probably get the error: “xxx.vhd is already registered with image repository as the resource with ID xxx” from Windows Azure. This issue will mostly because the VHD file is still allocated to the disk that was created for the VM (which is now deleted). You will now need to go to Virtual Machines under your Windows Azure Control Panel, click on “disks” tab (you should have Virtual Machines, Images and Disks tabs there). Click on the disk that is allocated to the VHD file and delete it. Make sure you choose to keep and retain the VHD file. This VHD file is still kept in your storage section on Windows Azure.
Now that the disk and the VM are both deleted, you can go to Images tab under Virtual machines and select create image, point to the VHD file and create your image. Make sure you select the tick box: yes I have sysprep my VHD.
You now have an image that you can use to create as many Virtual machines as you want based on it. You just need to go to the Virtual Machines tab and click on create virtual machine and select your VHD from the Gallery.
There are other issues where the disk and the VM are deleted and you are still unable to use the VHD file. In this case, a Windows Azure explorer software may be needed to connect to your Windows Azure cloud account and release the VHD as it is probably still in lease (a lease on the blob) and there is no lease ID specified (because the VM and the disk are deleted). Here is an article explaining the resolution to this issue:
In addition to having the image out of the VHD on windows azure, you can also have a disk instead if you don’t have a sysprep VHD. In this case, you create a disk out of the VHD and then create a VM out of the Disk instead of out of the image. The main difference is that when you create a VM from an image, windows azure creates a copy of the VHD and associates the VM to it while if you creatte a VM from a Disk, it just uses the same VHD – which means you can only use this disk/VHD once with one VM. This is usually a good work around if you are getting the error: Virtual Machine running but provision timed out on your Virtual Machine: Running (Provision timeout).
Hope this helps!