Error deleting VHD: There is currently a lease on the blob and no lease ID was specified in the request
When attempting to delete a VHD's blob you may receive the following error:
There is currently a lease on the blob and no lease ID was specified in the request
While these errors are expected if a VHD is still registered as a disk or image in the portal, we have identified an issue where a lease remains even if the blob is not registered as a disk or image in the portal.
If you receive one of these errors, first make sure the VHD is not in use:
Breaking the lease
You can use the Lease Blob API to break the lease in this scenario, which is also available in the Windows Azure PowerShell assembly Microsoft.WindowsAzure.StorageClient.dll using LeaseAction Enumeration.
A PowerShell script to break the lease is provided below. Mac and Linux users can use the Node.js script for releasing a Windows Azure blob lease.
To use the BreakLease.ps1 PowerShell script to break the lease:
Sample output:
BreakLease.ps1 -Uri 'http://clstorage.blob.core.windows.net/vhds/testvm1-testvm1-2012-06-26.vhd'
Processing http://clstorage.blob.core.windows.net/vhds/testvm1-testvm1-2012-06-26.vhd
Reading storage account information...
Confirmed - storage account 'clstorage'.
Checking whether the blob is currently registered as a disk or image...
Confirmed - the blob is not in use by the Windows Azure platform.
Inspecting the blob's lease status...
Current lease status: Locked
Unlocking the blob...
Current lease status: Unlocked
Success - the blob is unlocked.
BreakLease.ps1
Param([string]$Uri = $(Read-Host -prompt "Please specify a blob URL"))
$ProgressPreference = 'SilentlyContinue'
echo "Processing $Uri"
echo "Reading storage account information..."
$acct = Get-AzureStorageAccount | ? { (new-object System.Uri($_.Endpoints[0])).Host -eq (new-object System.Uri($Uri)).Host }
if(-not $acct) {
write-host "The supplied URL does not appear to correspond to a storage account associated with the current subscription." -foregroundcolor "red"
break
}
$acctKey = Get-AzureStorageKey ($acct.StorageAccountName)
$creds = "DefaultEndpointsProtocol=http;AccountName=$($acctKey.StorageAccountName);AccountKey=$($acctKey.Primary)"
$acctobj = [Microsoft.WindowsAzure.CloudStorageAccount]::Parse($creds)
$uri = $acctobj.Credentials.TransformUri($uri)
echo "Confirmed - storage account '$($acct.StorageAccountName)'."
$blobclient = New-Object Microsoft.WindowsAzure.StorageClient.CloudBlobClient($acctobj.BlobEndpoint, $acctobj.Credentials)
$blobclient.Timeout = (New-TimeSpan -Minutes 1)
$blob = New-Object Microsoft.WindowsAzure.StorageClient.CloudPageBlob($uri, $blobclient)
echo "Checking whether the blob is currently registered as a disk or image..."
$disk = Get-AzureDisk | ? { (new-object System.Uri($_.MediaLink)) -eq $blob.Uri }
if($disk) {
write-host "The blob is still registered as a disk with name '$($disk.DiskName)'. Please delete the disk first." -foregroundcolor "red"
break
}
$image = Get-AzureVMImage | ? { $_.MediaLink -eq $blob.Uri.AbsoluteUri }
if($image) {
write-host "The blob is still registered as an OS image with name '$($image.ImageName)'. Please delete the OS image first." -foregroundcolor "red"
break
}
echo "Confirmed - the blob is not in use by the Windows Azure platform."
echo "Inspecting the blob's lease status..."
try {
$blob.FetchAttributes()
} catch [System.Management.Automation.MethodInvocationException] {
write-host $_.Exception.InnerException.Message -foregroundcolor "red"
break
}
echo "Current lease status: $($blob.Properties.LeaseStatus)"
if($blob.Properties.LeaseStatus -ne [Microsoft.WindowsAzure.StorageClient.LeaseStatus]::Locked) {
write-host "Success - the blob is unlocked." -foregroundcolor "green"
break
}
echo "Unlocking the blob..."
$request = [Microsoft.WindowsAzure.StorageClient.Protocol.BlobRequest]::Lease($uri, 0, [Microsoft.WindowsAzure.StorageClient.Protocol.LeaseAction]::Break, $null)
$request.Timeout = $blobclient.Timeout.TotalMilliseconds
$acctobj.Credentials.SignRequest($request)
try {
$response = $request.GetResponse()
$response.Close()
}
catch {
write-host "The blob could not be unlocked:" -foregroundcolor "red"
write-host $_.Exception.InnerException.Message -foregroundcolor "red"
break
}
$blob.FetchAttributes()
echo "Current lease status: $($blob.Properties.LeaseStatus)"
write-host "Success - the blob is unlocked." -foregroundcolor "green"
Alternate method: make a copy of the VHD in order to reuse a VHD with a stuck lease
If you have removed the VM and the disk object but the lease remains and you need to reuse that VHD, you can make a copy of the VHD and use the copy for a new VM:
Thanks,
Craig
Doug Mahugh has posted similar instructions for Node.js enthusiasts.
I ran the PS script and it tells me that the VHD file stored in Blob is tied to a OS Image with the name "" (No name). I can not determine how to delete the VHD based in the fact that somehow the blob lease is tied to an OS image with no name.
same thing is happening to me. this is the error message that i'm getting:
The blob is still registered as an OS image with name 'CANONICAL__Canonical-Ubuntu-12-04-amd64-server-20120528.1.3-en-us-30GB.vhd MSFT__Win2K8R2SP1-120612-1520-121206-01-en-us-30GB.vhd MSFT__BizTalk-Server-2010R2-CTP-3.10.77.0-07162012-en-us-50GB.vhd MSFT__Windows-Server-2012-Datacenter-201208.01-en.us-30GB.vhd MSFT__Sql-Server-11EVAL-11.0.2215.0-08022012-en-us-30GB.vhd MSFT__Win2K8R2SP1-Datacenter-201207.01-en.us-30GB.vhd OpenLogic__OpenLogic-CentOS-62-20120531-en-us-30GB.vhd SUSE__openSUSE-12-1-20120603-en-us-30GB.vhd SUSE__SUSE-Linux-Enterprise-Server-11SP2-20120601-en-us-30GB.vhd'. Please delete the OS image first.
what the hell is going on? i've never created any of these images.
ok. each of these vhds in the error message is associated with one of the platform images in the gallery. why am i getting this error message when i'm trying to delete one of my own vhds?
I have the exact same issue on one of my disks as well, is there anyway to fix this yet?I ran the PS script and it tells me that the VHD file stored in Blob is tied to a OS Image with the name "" (No name). I can not determine how to delete the VHD based in the fact that somehow the blob lease is tied to an OS image with no name.
same thing is happening to me. this is the error message that i'm getting:
The blob is still registered as an OS image with name 'CANONICAL__Canonical-Ubuntu-12-04-amd64-server-20120528.1.3-en-us-30GB.vhd MSFT__Win2K8R2SP1-120612-1520-121206-01-en-us-30GB.vhd MSFT__BizTalk-Server-2010R2-CTP-3.10.77.0-07162012-en-us-50GB.vhd MSFT__Windows-Server-2012-Datacenter-201208.01-en.us-30GB.vhd MSFT__Sql-Server-11EVAL-11.0.2215.0-08022012-en-us-30GB.vhd MSFT__Win2K8R2SP1-Datacenter-201207.01-en.us-30GB.vhd OpenLogic__OpenLogic-CentOS-62-20120531-en-us-30GB.vhd SUSE__openSUSE-12-1-20120603-en-us-30GB.vhd SUSE__SUSE-Linux-Enterprise-Server-11SP2-20120601-en-us-30GB.vhd'. Please delete the OS image first.
what the hell is going on? i've never created any of these images.
ok. each of these vhds in the error message is associated with one of the platform images in the gallery. why am i getting this error message when i'm trying to delete one of my own vhds?
Same error for me, but following the instruction in this post fixed my issue. Deleting a VM will not delete the disk attached to it. You need to go the the 'DISKS' tab in the Virtual Machine area and delete those as well.
That is the normal fix, however at least in my case, this happened, I believe, after I had deleted the disk from the section in Virtual Machine management (There isn't a disk in VM management for it anymore). The issue seems to be that the disks are leased to the default azure images, which we can't delete our self.Same error for me, but following the instruction in this post fixed my issue. Deleting a VM will not delete the disk attached to it. You need to go the the 'DISKS' tab in the Virtual Machine area and delete those as well.
I have been using the .Net API as I got the same error on the PowerShell script.
I'm using 1.7.1 but I think the below code is exactly the same for 1.7.0.
I'm working on a simple tool that will kill these Leases. I have also seen stuck Disks that cannot be removed, other than using PowerShell.
I have a simple tool that does this that I hope to post soon. If you want it now, just email me.
CloudStorageAccount sourceStorageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("SourceStorageConnection"));
// Create the blob client using the Accounts above
CloudBlobClient sourceBlobClient = sourceStorageAccount.CreateCloudBlobClient();
CloudBlobContainer sourceContainer = sourceBlobClient.GetContainerReference("vhds");
CloudBlob sourceBlob = sourceContainer.GetBlobReference(VHDNAME.vhd);
TimeSpan breakTime = new TimeSpan(0, 0, 1);
sourceBlob.BreakLease(breakTime);
Stephen W. Thomas 8 Year BizTalk Server MVP http://www.BizTalkGurus.com
MS Azure Support just had me attempt to use myAzureStorage BlobBrowser at https://www.myazurestorage.com; however, it also gave me the same exception as the Preview UI. I did get a full stack trace this time just for fun, which I'll paste below.
I like your code. I'll give that a shot and see what happens - thanks.
Luke
Server Error in '/' Application.
The remote server returned an error: (412) There is currently a lease on the blob and no lease ID was specified in the request..
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.WebException: The remote server returned an error: (412) There is currently a lease on the blob and no lease ID was specified in the request..
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[WebException: The remote server returned an error: (412) There is currently a lease on the blob and no lease ID was specified in the request..]
System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) +3236201
Microsoft.WindowsAzure.StorageClient.EventHelper.ProcessWebResponse(WebRequest req, IAsyncResult asyncResult, EventHandler`1 handler, Object sender) +80
[StorageClientException: There is currently a lease on the blob and no lease ID was specified in the request.]
Microsoft.WindowsAzure.StorageClient.Tasks.Task`1.get_Result() +95
Microsoft.WindowsAzure.StorageClient.Tasks.Task`1.ExecuteAndWait() +201
Microsoft.WindowsAzure.StorageClient.CloudBlob.DeleteIfExists(BlobRequestOptions options) +213
MyAzureStorage.Controllers.BlobsController.Delete(String uri) in D:\proj\myazurestorage-v1\managed\development\MyAzureStorage\main\code\MyAzureStorage\Controllers\BlobsController.cs:141
lambda_method(Closure , ControllerBase , Object[] ) +127
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +248
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +39
System.Web.Mvc.<>c__DisplayClassd.<InvokeActionMethodWithFilters>b__a() +125
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +640
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +312
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +691
System.Web.Mvc.Controller.ExecuteCore() +162
System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__4() +58
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +20
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +469
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +375
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
YES! Stephen, I'm officially naming you in this thread as "THE MAN!"
Stephen's code works. Get the Storage Client version 1.7.1 (there is no BreakLease method in 1.7.0) from GitHub at: https://github.com/WindowsAzure/azure-sdk-for-net
Open and compile the project in the microsoft-azure-api folder
Replace your 1.7.0 dll with the 1.7.1 dll in your project.
For those using VB.NET, use this:
Dim sourceBlobClient As New CloudBlobClient("http://YOUR_BLOB_ACCT.blob.core.windows.net/", New StorageCredentialsAccountAndKey("YOUR_BLOB_ACCT", "YOUR_ACCT_KEY"))
Dim sourceContainer As CloudBlobContainer = sourceBlobClient.GetContainerReference("vhds")
Dim sourceBlob As CloudBlob = sourceContainer.GetBlobReference("YOUR_STUCK_BLOB_NAME")
Dim breakTime As TimeSpan = New TimeSpan(0, 0, 1)
sourceBlob.BreakLease(breakTime)
For those using C#, use Stephen's code above.
Once you run the code, you will be able to use the Preview UI to delete the unlocked blob. Note that you must drop the disk if this is VHD blob attached to a VM ... make sure you've done that first in the VM area of the UI under the Disks tab. When the blob is only showing up in storage and nowhere else, then you can break the lease and kill it.
I had a similar issue and the breaking lease script didn't work. I eventually fixed my problem.
My symptoms:
When I tried to delete the Virtual Machine Disk, the delete icon was grayed out.
When I tried to delete the blob storage, I would get a no lease ID on the blog
When I ran the break lease powershell, I got the error message:
Reading storage account information...
Confirmed - storage account 'portalvhds8w9nk13lyf9h5'.
Checking whether the blob is currently registered as a disk or image...
The blob is still registered as a disk with name 'OGDemo-OGDemo-0-20120724172512'. Please delete the disk first.
ARGHH. It was a circular argument. I cant delete the Disk because the blob has a lease. I cant break the lease because the blog still has a disk attached! @#$&@!!!
My solution --
1. Run Remove-AzureDisk from the AzurePowerShell like this:
PS C:\> Remove-AzureDisk -DiskName "OGDemo-OGDemo-0-20120724172512" –DeleteVHD
It processed like this:
OperationDescription OperationId
OperationStatus
-------------------- -----------
---------------
Remove-AzureDisk 2f004d86-779d-41e3-9850-224ab49223f8 Succeeded
Remove-AzureDisk : There is currently a lease on the blob and no lease ID was specified in the request.
It succeeded to removed the disk but still failed with the lease ID.
But wait! In the Azure Portal, the Virtual Machine Disk has disappeared.
I could then go to the storage and delete the Azure storage using the Azure Portal
Mission accomplished for me..
Dear Azure Team -- This is stupid. Please fix stuff like this. Delete should just delete stuff.
Your code combined with Stephen's did the trick for me. Thank you very much!YES! Stephen, I'm officially naming you in this thread as "THE MAN!"
Stephen's code works. Get the Storage Client version 1.7.1 (there is no BreakLease method in 1.7.0) from GitHub at: https://github.com/WindowsAzure/azure-sdk-for-net
Open and compile the project in the microsoft-azure-api folder
Replace your 1.7.0 dll with the 1.7.1 dll in your project.
For those using VB.NET, use this:
Dim sourceBlobClient As New CloudBlobClient("http://YOUR_BLOB_ACCT.blob.core.windows.net/", New StorageCredentialsAccountAndKey("YOUR_BLOB_ACCT", "YOUR_ACCT_KEY")) Dim sourceContainer As CloudBlobContainer = sourceBlobClient.GetContainerReference("vhds") Dim sourceBlob As CloudBlob = sourceContainer.GetBlobReference("YOUR_STUCK_BLOB_NAME") Dim breakTime As TimeSpan = New TimeSpan(0, 0, 1) sourceBlob.BreakLease(breakTime)For those using C#, use Stephen's code above.
Once you run the code, you will be able to use the Preview UI to delete the unlocked blob. Note that you must drop the disk if this is VHD blob attached to a VM ... make sure you've done that first in the VM area of the UI under the Disks tab. When the blob is only showing up in storage and nowhere else, then you can break the lease and kill it.
Glad I (we) could help. Hopefully, Jai sees this and his team work up something via the UI to break a lease like this. One thing for sure, nobody should create a support ticket. The support folks are clueless on this particular issue.
Vote UP Stephen's post & mark it "Propose as Answer" --- He is the one who really figured it out and deserves all of the credit. I was just riding his coat tails.
I finally posted my tool to my blog that makes working with VHD's easer.
You can download it here: http://www.biztalkgurus.com/biztalk_server/biztalk_blogs/b/biztalk/archive/2012/09/26/windows-azure-virtual-hard-disk-blob-storage-cross-account-copy-lease-break-and-management-tool.aspx
One click break of the lease. And shows you all the lease too.
Stephen W. Thomas
Stephen W. Thomas 8 Year BizTalk Server MVP http://www.BizTalkGurus.com
Steve. Thanks
This is a great tool and worked awsome. Though it threw error first time. But then I ran it again and it worked.
Now I am stuck with Stoarge with Container and no VHD. Cannot delete comtainer. Says
There is currently a lease on the container and no lease ID was specified in the request
Interesting, I didn’t run into that problem. Do you have a Disk under Virtual Machines – Disks that is orphaned?
Using Powershell you can go “Get-AzureDisks” to list all your disks. (steps here: http://www.biztalkgurus.com/biztalk_server/biztalk_blogs/b/biztalk/archive/2012/09/19/how-to-remove-an-orphaned-windows-azure-virtual-machine-disk-and-remove-a-lease-conflict-on-a-vhd-blob.aspx)
Did you close the tool down before you tried to delete the container?
If there is a pending copy operation I think you can run into issues... but sure off hand how to check that though. Did you try to copy anything into that container?
Stephen W. Thomas 8 Year BizTalk Server MVP http://www.BizTalkGurus.com
Steve, your tool was very useful! It allowed me to delete a .vhd that was stuck.
Now I'm having the same issue as Johne3223: "Now I am stuck with Stoarge with Container and no VHD. Cannot delete comtainer. Says There is currently a lease on the container and no lease ID was specified in the request."
Has anyone else run into this?
Good to hear.
I too have the stuck Containers. That just started happening a few weeks ago.
Since you are not charged for having an empty container or storage account, I have not looked into how to remove them. I just have 4 to 5 of them stacking up… for now.
I would assume you could remove it using PowerShell, but I have been focusing on other tasks at the moment.
One thing I do try to do is put all my VHD’s into the same storage account. This means never use the quick create as they creates a random store per VHD (didn’t a few weeks ago but does now).
Hope this helps.Stephen W. Thomas 8 Year BizTalk Server MVP http://www.BizTalkGurus.com
Make sure you load the types from Microsoft.WindowsAzure.StorageClient.dll before you run the BreakLease script. If you have Azure SDK 1.8 like me then you can do this:
Add-Type -Path 'C:\Program Files\Microsoft SDKs\Windows Azure\.NET SDK\2012-10\bin\Microsoft.WindowsAzure.StorageClient.dll'
Then run the following to make sure the types were loaded:
PS C:\Azure\Scripts> [Microsoft.WindowsAzure.CloudStorageAccount]
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True False CloudStorageAccount System.Object
You should be able to break the lease using my tool (http://www.biztalkgurus.com/windows_azure/m/windows_azure/37137.aspx) without needing a publishing file. Just the Storage Account details.
Hope this helps.
Stephen W. Thomas 8 Year BizTalk Server MVP http://www.BizTalkGurus.com
You can get the same code on MSDN here: http://code.msdn.microsoft.com/Windows-Azure-Virtual-907e1769
Not sure what's wrong with the link. It should be a direct download. This one might work better:
http://www.biztalkgurus.com/windows_azure/m/windows_azure/37137/download.aspx
In any event, no registration required and the source code is available for download.
Stephen W. Thomas 8 Year BizTalk Server MVP http://www.BizTalkGurus.com
|

