Windows Azure – How to delete a Virtual Machine properly

Azure Virtual Machines
If like me you’re playing more and more with Windows Azure, you’ve probably faced some issues with the Windows Azure Manager. Sometimes the problem is that you can’t find easily how to do a task. The last one I’ve been exposed is that I couldn’t delete the hard drive (vhd) use by an old virtual machine. Because when you create a new Virtual Machine, you’re prompted for a storage, I was guessing that I will just have to go to the storage I’ve created to store my machine, then open the container vhds and simply delete the blob. Unfortunately, there is a lock on the file, even if there is no VM using it:

VHD Metadata

So when you try to delete this blob, you’ll get this error message in the portal:

VHD Delete Error

The reason is simple, the lock comes from the management portal. Here is the “good way” to delete a Virtual Machine and the associated resources.

  • First, delete the Virtual Machine by going to the list of Virtual Machines, select the one you want to delete, then click Delete.
  • Once the VM is deleted, go to Virtual Machines | DISKS you will notice that the vhd is still here but not attached to anything. That’s good because you can still create a new VM with the same hard drive later on. Vhd Disks
  • From this screen, and this one only, you can delete the disk. Select the disk and click DELETE in the list of actions at the bottom of the page. In the new menu, click Delete the associated VHD. Vhd Delete Disk
  • A Cloud Service has also been created with your Virtual Machine. It can be used when you have multiple machines for a single service. If you don’t use it, you can delete it.
  • If you don’t need the storage created for this Virtual Machine, you can also delete it.
  • You’re done, you have cleaned your Windows Azure from the Virtual Machine.