How do I delete an Azure storage account containing a leased blob?
Asked Answered
H

11

159

I was playing with Windows Azure durable virtual machines. In the end, I deleted the virtual machine (successfully) and tried to delete the associated storage account.

The request to delete the storage account fails.

On the Preview Portal (manage.windowsazure.com) when I delete the storage account I get this error:

Failed to delete Storage account 'portalvhdscwtwycpsxxxxx'

Details:

Storage account portalvhdscwtwycpsxxxxx has 1 container(s) which have an active image and/or disk artifacts. Ensure those artifacts are removed from the image repository before deleting this storage account.

On the previous portal (windows.azure.com) I get this error:

Submit Failed

Storage account portalvhdscwtwycpsxxxxx has 1 container(s) which have an active image and/or disk artifacts. Ensure those artifacts are removed from the image repository before deleting this storage account.

Trying to delete the blob itself (a 30GB VHD) on Azure Storage Explorer I get this error:

There is currently a lease on the blob and no lease ID was specified in the request.

So my assessment is that this blob is leased (by the previous, now deleted virtual machine) and I can't delete it unless I can get this lease ID.

The question is: how can I delete this blob and, consequently, the storage account?

Hem answered 10/6, 2012 at 13:17 Comment(0)
H
334

The key to the solution is the message that the container has an active disk artifact and the advice to remove it from the repository.

The procedure to remove the disk image from the blob repository is:

After that, the storage account can be deleted.

Notes:

  • This applies even if you've already deleted all of your Virtual Machines and it shows 0; there still will be artifacts under the disks tab.
  • Disks are detached from a deleted VM asynchronously, it may take a few minutes after the VM is deleted for this field to clear up.

See also: Unable to delete VHD, “There is currently a lease on the blob…”

Hem answered 10/6, 2012 at 13:17 Comment(7)
One important note: the delete button does not work properly with IE9. I couldn't follow this with IE, but with Chrome I had no problems.Brotherinlaw
@PaulKeister It's buggy on Firefox 17.0.1 as well. I had to try a few times.Flanna
In addition to @DavideIcardi's comment: on this thread on MSDN forum it is explained that the blob lease is released asynchronously and this operation could last at most 2 hours.Edaphic
I have this same issue, but under virtual machines/disks it says "No disks have been created. To get started, click Create a disk.". There are two VM images under images, but they can't be deleted... ideas anyone..?Gangling
In the new management portal the process is different - see: #34363404Hartley
I had to go to the old portal > Storage > choose storage account from list > click Containers tab at the top > click vhds > choose the blob to delete. Now you can delete the storage account.Overrate
ditto @chdev77. I also had to go to the old portal in order for the disks to show up. Wow that was annoying as hell!Jolly
M
17

Unfortunately, Fernando's answer didn't work for me, since the storage was "orphan", as I deleted its VM before deleting the storage. I couldn't find a way to do it from the portal so I've installed azure-cli, and after authentication ran the following commands:

azure storage account delete <my-account>

This fails, and the error message contains the name of culprit, e.g.:

error: Storage account <my-account> has some active image(s) and/or disk(s), e.g. <my-image>. Ensure these image(s) and/or disk(s) are removed before deleting this storage

Then I deleted the offending image

azure vm disk delete <my-image>

And tried again to delete the storage, this time successfully.

azure storage account delete <my-account>

Maidamaidan answered 14/12, 2015 at 13:34 Comment(1)
Had the exact same problem. I had a bunch of orphaned disks and images that you cannot delete in the portal. If only I had found this answers four months ago!Trussing
F
12

Unfortunately there is the case where the VM was deleted but Disks shows the VM attached to the blob (a 30GB VHD) precluding the deletion. Also there is the case of using the Azure Storage Explorer you find an orfan but leased VHD blob that can't be deleted and there is no reference on the Preview Portal.

Fromma answered 11/6, 2012 at 1:19 Comment(4)
His answer is not correct in ALL circumstances. I currently have three (3) "Disks" that are listed under the section "Virtual Machines -> Disks", that cannot be deleted (hence the blob cannot be deleted). I have no idea how to get rid of them as the only current way I know of is to use the portal. kieselmediagroup.blob.core.windows.net/misc/2012-08-21_1019.pngSlattern
As already noted by @Slattern sometime you are not able to delete the disk also if you have already deleted the corresponding virtual machine. In my experience seems to be just a timing problem. Try to wait some minutes and you should be able to delete it.Quake
I've waited 3 months... should I continue waiting for the timing issue?Mccormack
You can find VHD disk image under Browse (in the new portal)Sheppard
A
8

Go to virtual machines, then click on discs. Mark the disc and choose delete disc at the bottom. You can now choose if you want to keep or delete the corresponding vhd.

It is important first to delete the disc via virtual machines not to delete via storage.

Achaean answered 29/11, 2012 at 7:50 Comment(1)
I think many of you have RTFM and not the question. These are orphaned leased locked vhd's... I have same issue, where I have NOTHING on Azure but two VHD's and they won't delete as they are leased and locked (which is a bug, as there is nothing to lease them to)Mccormack
M
5

You can use Iaas Management Studio : break the lease, delete the blob, then remove the orphaned image.

Matrass answered 8/12, 2013 at 12:46 Comment(0)
T
5

In my case, storage could not be deleted because of vmimages.

Use power shell command

get-azurevmimage | Where-Object -Property Category -in -Value "user"

to list all images To delete ALL YOU IMAGES use the following script:

get-azurevmimage | Where-Object -Property Category -in -Value "user" |   
foreach {
        echo "remove $($_.ImageName)"
        Remove-AzureVMImage –ImageName $($_.ImageName)
        }
Tony answered 17/11, 2014 at 19:1 Comment(1)
You can delete images from Images tab (inside virtual machines section) on Classic Azure Management Portal too.Mailbag
P
4

As F.M. has already stated; there is a scenario where when deleting a VM the disk still shows as attached to the VM even though the VM has been deleted.

For me this happened because I had a set a spending limit. When the spending limit is hit, your services are disabled. Any VPN gateways you have created and VMs will be deleted. Then to top it off the disks attached to the deleted VMs still think they are attached :(

I have found this blog that explains the issue and shows how to use powershell to resolve.

Hope this helps other users.

Preter answered 14/1, 2013 at 13:13 Comment(1)
great! your link brought me to a tool that he made a few days later which allows you to "unlease" your vhd: biztalkgurus.com/biztalk_server/biztalk_blogs/b/biztalk/archive/…Gilliangilliard
P
0

For those who rely on GUI to manage Azure and have no idea to use PowerShell or do the other answers, you can now delete the stuck storage account by checking "Delete unattached images" when trying to delete the storage.

It will automatically delete the storage without much hassle.

Pledgee answered 10/6, 2012 at 13:17 Comment(1)
I've done this just now, but forgot the exact wording of the checkbox.Pledgee
G
0

Do check before deleting your storage account; there must be the associated virtual machine(s), Disks and Images for each storage account you created. Go to Azure portal

Select Virtual Machines tab on left pane Click on Instances Images and Disks

Note that, Individual Virtual machines has its attached disks which show on Disks area.Before deleting a Virtual machine, delete the associated disks first and delete the virtual machine has the disk second.Then delete the storage account last. Also look out for Network in the same left-hand side pane if any associated with the account you want to delete.

In the new updated Azure portal, many of the above-stated config pages are changed. You can see Images and Disks options in "All resources" pane. In the newer version of an Azure portal, you can easily identify VMs its associated Disks and its Storage account clearly on its adjacent vertical panes all in one page with different icon images.

Gabie answered 9/2, 2016 at 6:25 Comment(0)
Q
0

Sometimes we via the new portal to delete azure storage account, but we can’t delete it and get this error:” Failed to delete storage account 'jason1disks796'. Error: The storage account cannot be deleted due to its artifacts being in use.

We can use PowerShell to list all the VHD blobs of the storage account(ARM module):

PS > Login-AzureRmAccount
PS > $RGName = "jason1"
PS > $SAName = "jason1disks796"
PS > $ConName = "vhds"
PS > $TempObj = New-Object -TypeName PSCustomObject
PS > $TempObj |Add-Member -Name BlobName -MemberType NoteProperty -Value $null
PS > $TempObj |Add-Member -Name LeaseState -MemberType NoteProperty -Value $null
PS > $Keylist = Get-AzureRmStorageAccountKey -ResourceGroupName $RGName -StorageAccountName $SAName
PS > $Key = $Keylist[0].Value
PS > $Ctx = New-AzureStorageContext -StorageAccountName $SAName -StorageAccountKey $Key
PS > Get-AzureStorageContainer -Context $ctx
CloudBlobContainer : Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer
Permission         : Microsoft.WindowsAzure.Storage.Blob.BlobContainerPermissions
PublicAccess       : Off
LastModified       : 1/19/2017 1:27:21 AM +00:00
ContinuationToken  :
Context            : Microsoft.WindowsAzure.Commands.Common.Storage.AzureStorageContext
Name               : vhds
PS > $List = Get-AzureStorageBlob -Blob *.vhd -Container $ConName -Context $Ctx
PS > $List | ForEach-Object { $TempObj.BlobName = $_.Name; $TempObj.LeaseState = $_.ICloudBlob.Properties.LeaseState; $TempObj }

BlobName              LeaseState
--------              ----------
SQL20170119092405.vhd     Leased

PS > Get-AzureStorageBlob -Blob * -Container $con -Context $ctx | Remove-AzureStorageBlob
PS > Remove-AzureRmStorageAccount -ResourceGroupName $RGname -Name $SAName

If your storage account is in the ASM module, you can use this script to remove storage account:

Add-AzureAccount
$SAName = "jason1161"
$ConName = "vhds"
$TempObj = New-Object -TypeName PSCustomObject
$TempObj |Add-Member -Name BlobName -MemberType NoteProperty -Value $null
$TempObj |Add-Member -Name LeaseState -MemberType NoteProperty -Value $null
$Keylist = Get-AzureStorageKey -StorageAccountName $SAName
$Key = $Keylist.primary
$Ctx = New-AzureStorageContext -StorageAccountName $SAName -StorageAccountKey $Key
$List = Get-AzureStorageBlob -Blob *.vhd -Container $ConName -Context $Ctx
$List | ForEach-Object { $TempObj.BlobName = $_.Name; $TempObj.LeaseState = $_.ICloudBlob.Properties.LeaseState; $TempObj }
PS > Get-AzureStorageBlob -Blob * -Container $con -Context $ctx | Remove-AzureStorageBlob
PS > Remove-AzureStorageAccount -Name $SAName

Besides, there is another scenario, there is no container or blob in this storage account (an empty storage account, we can’t find blob or container in this storage account via PowerShell or portal), when we use portal to delete the storage account, and the error message” Failed to delete storage account 'jason1disks796'. Error: The storage account cannot be deleted due to its artifacts being in use”. In this scenario we can create a new VM and specify the storage account to the problematic Storage Account, then delete it again.

Quinquevalent answered 19/1, 2017 at 8:51 Comment(0)
R
0

on the new portal search disk (classic) and delete the disk

Radiometer answered 12/1 at 8:54 Comment(2)
Adding a screenshot of what should be done would increase the quality of your answerOzalid
This really seems like more of a comment on the top-voted answer rather than a new answer—and especially without more details. It’s essentially stating that the interface referenced by other answers is now under a new label (“Classic”), but then to follow the (more detailed) directions stated by other contributors.Mondrian

© 2022 - 2024 — McMap. All rights reserved.