Azure VM-vhd

Azure VM-vhd


Troubleshoot classic storage resource deletion errors

This article provides troubleshooting guidance when one of the following errors occurs trying to delete Azure classic storage account, container, or *.vhd page blob file.

This article only covers issues with classic storage resources. If a user deletes a classic virtual machine using the Azure portal, PowerShell or CLI then the Disks aren't automatically deleted. The user gets the option to delete the "Disk" resource. In case the option isn't selected, the "Disk" resource will prevent deletion of the storage account, container and the actual *.vhd page blob file.

More information about Azure disks can be found here. Azure prevents deletion of a disk that is attached to a VM to prevent corruption. It also prevents deletion of containers and storage accounts, which have a page blob that is attached to a VM.

What is a "Disk"?

A "Disk" resource is used to mount a .vhd page blob file to a virtual machine, as an OS disk or Data disk. An OS disk or Data disk resource, until deleted, will continue to hold a lease on the.vhd file. Any storage resource in the path shown in below image can't be deleted if a "Disk" resource points to it.

Steps while deleting a classic virtual machine

 Important

Classic VMs will be retired on March 1, 2023.

If you use IaaS resources from ASM, please complete your migration by March 1, 2023. We encourage you to make the switch sooner to take advantage of the many feature enhancements in Azure Resource Manager.

For more information, see Migrate your IaaS resources to Azure Resource Manager by March 1, 2023.

  1. Delete the classic virtual machine.
  2. If the "Disks" checkbox is selected, the disk lease (shown in image above) associated with the page blob .vhd is broken. The actual page blob.vhd file will still exist in the storage account.
  1. Once the disk(s) lease is broken, the page blob(s) itself can be deleted. A storage account or container can be deleted once all "Disk" resource present in them are deleted.

 Note

If user deletes the VM but not the VHD, storage charges will continue to accrue on the page blob *.vhd file. The charges will be in line with the type of storage account, check the pricing page for more details. If user no longer intends to use the VHD(s), delete it/them to avoid future charges.

Unable to delete storage account

When user tries to delete a classic storage account that is no longer needed, user may see the following behavior.

Azure portal

User navigates to the classic storage account on the Azure portal and clicks Delete, user will see the following message:

With disk(s) "attached" to a virtual machine

With disk(s) "unattached" to a virtual machine

Azure PowerShell

User tries to delete a storage account, that is no longer being used, by using classic PowerShell cmdlets. User will see the following message:

Remove-AzureStorageAccount -StorageAccountName myclassicaccount

Remove-AzureStorageAccount : BadRequest: Storage account myclassicaccount has some active image(s) and/or disk(s), e.g. myclassicaccount. Ensure these image(s) and/or disk(s) are removed before deleting this storage account.

Unable to delete storage container

When user tries to delete a classic storage blob container that is no longer needed, user may see the following behavior.

Azure portal

Azure portal wouldn't allow the user to delete a container if a "Disk(s)" lease exists pointing to a *.vhd page blob file in the container. It's by design to prevent accidental deletion of a vhd(s) file with Disk(s) lease on them.

Azure PowerShell

If the user chooses to delete using PowerShell, it will result in the following error.

Remove-AzureStorageContainer -Context $context -Name vhds

Remove-AzureStorageContainer : The remote server returned an error: (412) There is currently a lease on the container and no lease ID was specified in the request.. HTTP Status Code: 412 - HTTP Error Message: There is currently a lease on the container and no lease ID was specified in the request.

Unable to delete a vhd

After deleting the Azure virtual machine, user tries to delete the vhd file (page blob) and receive the message below:

Azure portal

On the portal, there could be two experiences depending on the list of blobs selected for deletion.

  1. If only "Leased" blobs are selected, then the Delete button doesn't show up.
  2. If a mix of "Leased" and "Available" blobs are selected, the "Delete" button shows up. But the "Delete" operation will leave behind the page blobs, which have a Disk lease on them.Azure PowerShell

If the user chooses to delete using PowerShell, it will result in the following error.
Remove-AzureStorageBlob -Context $context -Container vhds -Blob "classicvm-os-8698.vhd"
Remove-AzureStorageBlob : The remote server returned an error: (412) There is currently a lease on the blob and no lease ID was specified in the request.. HTTP Status Code: 412 - HTTP Error Message: There is currently a lease on the blob and no lease ID was specified in the request.
Resolution steps
To remove classic Disks
Follow these steps on the Azure portal:

  1. Navigate to the Azure portal.
  2. Navigate to the Disks(classic).
  3. Click the Disks tab

4. Select your data disk, then click Delete Disk.

5. Retry the Delete operation that previously failed.

6. A storage account or container can't be deleted as long as it has a single Disk.

To remove classic Images

Follow these steps on the Azure portal:

  1. Navigate to the Azure portal.
  2. Navigate to OS images (classic).
  3. Delete the image.
  4. Retry the Delete operation that previously failed.
  5. A storage account or container can't be deleted as long as it has a single Image.
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us