There is currently a lease on the blob and no lease ID...

A co-worker was having an issue trying to reuse a VHD that he previously used for another VM and was receiving an error. He then decided to delete the VHD and move on with a fresh VHD however was now receiving the following error:

Clicking on details yields the following:

 

  “Error deleting blob '/vhds/YourVHD.vhd”: details, There is currently a lease on the blob and no lease ID was specified in the request.

This is where I entered the story, this is “by design” behavior and the error is expected if, the disk you are attempting to work with is truly attached to an existing VM or if you are attempting to remove a VHD that is still considered leased and/or visible through the portal as a disk or an image in the Virtual Machines management interface.

So, let’s start off by checking to make sure that this VHD is not attached to a VM.

 

In the Azure Management Portal, choose the Virtual Machines interface, and select Disks from the top right pane navigation. Look at the Attached To column and ensure it is blank, if it is not blank, then this is the issue.

 

Now let’s figure out whether it is attached to a VM or not, manually review your instances interface and verify if the disk is attached or not. If it is and If you no longer want the VM and want to reuse the disk, in the  Instances interface on the top right pane navigation choose the VM that it was attached to and select Delete from the “Drawer” (bottom navigation ribbon). You will be presented with two options, Delete the attached disks and Keep the attached disks. Choose delete if you want to be done with the VM and the VHD or keep if you want to try and reuse it.

If there is no instance with the disk you are referencing associated, Delete is greyed / not selectable, and you still cannot create a VM from this disk then keep reading. If removal is your goal then you should now be able to use the Storage interface to delete the VHD.

Stop here if your goal was to only remove the disk as you’re done. However, if you decide you want to reuse the VHD and chose to keep it then read on.

 

You can first try to delete the disk entry.

*Note* This will NOT delete the blob from storage, it simply removes the disk entry from the VM configuration.

To delete the Disk entry, navigate to Virtual Machines, then choose Disks on the top navigation. Highlight the disk in question and on the drawer choose Delete. You will be presented with two options, Delete the associated VHD and Retain the associated VHD. Make your choice to retain it if you want to reuse it or delete it if your goal is simply to be rid of it.

 

If you have chosen to keep it you will need to remove the lease from the VHD itself if you want to reuse it. There are several tools out there that will help with this, take a look at the Azure Storage Explorers page to see what is available. My choice was Cloud Explorer simply because I am familiar with it.

We are going to make a copy of our VHD here to work around this issue.

  1. Start at the Azure Management Portal, choose the Storage interface, then select the storage account that homes the VHD we are working with. Now on the Drawer (bottom) choose Manage Access Keys at the bottom, this will activate the information windows where you will need to copy your Storage Account Name and your Primary Access Key. Click the copy icon at end of the entry field to copy each one and paste into OneNote or your note keeper of Choice.


 

  1. Again I am using CloudXplorer, if you chose a different tool you will need to setup your account for that tool. In Cloud Explorer go to Accounts on the Home ribbon, choose New, select Azure Blobs Account. Enter the storage account name you made note of previously in the Name field and supply your primary access key for the Secret Key entry. Ensure that the Endpoint drop down is set for General (*.core.windows.net)  and then everything else below should be unchecked or blank and click ok.

 

  

  1. Now in Cloud Explorer's  left navigation pane, double click or expand the storage account, select the vhds container and the in the right navigation pane select the VHD in question. Right click the VHD and select Rename and change it a another name and click Ok. You will receive an error stating again , There is currently a lease on the blob and no lease ID was specified in the request. Go aheadand click Ok to continue, then click Refresh on the Home ribbon or press (F5) to refresh. You should now see a copy of the VHD with the name you chose.


  

  1. Almost done, back over on the Azure Management Portal, choose the Virtual Machines interface, select Disks from the top navigation, and then Create from the drawer. Enter your new name for the disk, under VHD URL click the folder and browse through to the location of your VHD copy, make sure to check the selection The VHD contains an operating system. Lastly select the drop-down to specify if it is Windows or Linux and then click the Ok check mark at the bottom.

 

 

On the info drawer you will see Creating Disk YourDiskName, wait for the Successfully created disk YourDiskName

Viola you now have a usable disk! 

Go setup your Virtual Machine with your new disk, the process is a little different to reuse a disk. On the Drawer, click New -> Compute -> Virtual Machine -> From Gallery -> My Disks, and choose the new disk that you just created. From this point forward creation is just like creating a Virtual Machine from scratch.

 

*Note*

I have tested this method of using an Azure Storage Explorer and the rename method for creating a copies of disks without detaching them from the VM and it works well.

 

Happy Azure'ing!

Comments

  • Anonymous
    February 17, 2016
    It would be great to be able to do this in the new Azure portal - it doesn't have the feature to attach existing disks to VMs :(
  • Anonymous
    February 17, 2016
    You can on creation but you are correct for an existing VM you cannot, it must be done through PowerShell.
  • Anonymous
    November 09, 2016
    The comment has been removed