排查经典存储资源删除错误Troubleshoot classic storage resource deletion errors

请遵循本文中的指导排查在尝试删除 Azure 存储帐户、容器或 *.vhd 页 Blob 文件时发生的以下错误之一。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. 如果用户使用 Azure 门户、PowerShell 或 CLI 删除经典虚拟机,则磁盘不会自动删除。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. 如果未选择该选项,则“磁盘”资源会阻止删除存储帐户、容器和实际的 *.vhd 页 Blob 文件。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.

若要详细了解 Azure 磁盘,请单击此处More information about Azure disks can be found here. Azure 阻止删除附加到 VM 的磁盘,以防发生损坏。Azure prevents deletion of a disk that is attached to a VM to prevent corruption. 它还会阻止删除包含附加到 VM 的页 Blob 的容器和存储帐户。It also prevents deletion of containers and storage accounts, which have a page blob that is attached to a VM.

什么是“磁盘”?What is a "Disk"?

“磁盘”资源用于将 *.vhd 页 Blob 文件作为 OS 磁盘或数据磁盘装载到虚拟机。A "Disk" resource is used to mount a *.vhd page blob file to a virtual machine, as an OS disk or Data disk. OS 磁盘或数据磁盘资源在删除之前,会一直在 *.vhd 文件中保留一个租约。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

  1. 删除经典虚拟机。Delete the classic virtual machine.

  2. 如果已选中“磁盘”复选框,则与页 Blob *.vhd 关联的磁盘租约(如上图所示)将会中断。If the "Disks" checkbox is selected, the disk lease (shown in image above) associated with the page blob *.vhd is broken. 实际的页 Blob *.vhd 文件仍在存储帐户中存在。The actual page blob *.vhd file will still exist in the storage account. 门户屏幕截图,其中显示(经典)虚拟机的“删除”错误窗格已打开Screenshot of the portal, with the virtual machine (classic) "Delete" error pane open

  3. 中断磁盘租约后,可以删除页 Blob 本身。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

如果用户删除 VM 但不删除 VHD,页 Blob *.vhd 文件仍会产生存储费用。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. 如果用户不再打算使用 VHD,请将其删除以免将来产生费用。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 门户Azure portal

当用户在 Azure 门户中导航到经典存储帐户并单击“删除”时,会看到以下消息: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 PowerShellAzure PowerShell

用户尝试通过经典 PowerShell cmdlet 删除不再使用的存储帐户。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 myclassicaccountRemove-AzureStorageAccount -StorageAccountName myclassicaccount

Remove-AzureStorageAccount :BadRequest:存储帐户 myclassicaccount 包含一些活动的映像和/或磁盘,例如 Remove-AzureStorageAccount : BadRequest: Storage account myclassicaccount has some active image(s) and/or disk(s), e.g. myclassicaccount。myclassicaccount.删除此存储帐户前,请确保删除这些映像和/或磁盘。Ensure these image(s) and/or disk(s) are removed before deleting this storage account.

无法删除存储容器Unable to delete storage container

当用户尝试删除不再需要的经典存储 Blob 容器时,可能会看到以下行为。When user tries to delete a classic storage blob container that is no longer needed, user may see the following behavior.

Azure 门户Azure portal

如果存在指向容器中 *.vhd 页 Blob 文件的“磁盘”租约,则 Azure 门户不允许用户删除该容器。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. 这是设计使然,目的是防止意外删除包含磁盘租约的 vhd(s) 文件。It's by design to prevent accidental deletion of a vhd(s) file with Disk(s) lease on them.

门户屏幕截图,其中显示存储容器“列表”窗格已打开

Azure PowerShellAzure PowerShell

如果用户选择使用 PowerShell 进行删除,则会导致以下错误。If the user chooses to delete using PowerShell, it will result in the following error.

Remove-AzureStorageContainer -Context $context -Name vhdsRemove-AzureStorageContainer -Context $context -Name vhds

Remove-AzureStorageContainer :远程服务器返回了错误:(412)容器中当前包含租约,但请求中未指定任何租约 ID。HTTP 状态代码:412 - HTTP 错误消息:容器中当前包含租约,但请求中未指定任何租约 ID。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.

无法删除 VHDUnable to delete a vhd

删除 Azure 虚拟机后,用户尝试删除 vhd 文件(页 Blob)时收到以下消息:After deleting the Azure virtual machine, user tries to delete the vhd file (page blob) and receive the message below:

Azure 门户Azure portal

在门户中,可能会根据选择删除的 Blob 列表提供两种体验。On the portal, there could be two experiences depending on the list of blobs selected for deletion.

  1. 如果仅选择“已租用”Blob,则不会显示“删除”按钮。If only "Leased" blobs are selected, then the Delete button doesn't show up. 门户屏幕截图,其中显示容器 Blob“列表”窗格已打开Screenshot of the portal, with the container blob "list" pane open

  2. 如果同时选择了“已租用”和“可用”Blob,则会显示“删除”按钮。If a mix of "Leased" and "Available" blobs are selected, the "Delete" button shows up. 但是,“删除”操作会留下包含磁盘租约的页 Blob。But the "Delete" operation will leave behind the page blobs, which have a Disk lease on them. 门户屏幕截图,其中显示容器 Blob“列表”窗格已打开 门户屏幕截图,其中显示选定 Blob 的“删除”窗格已打开Screenshot of the portal, with the container blob "list" pane open Screenshot of the portal, with the selected blob "delete" pane open

Azure PowerShellAzure PowerShell

如果用户选择使用 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 -Context $context -Container vhds -Blob "classicvm-os-8698.vhd"

Remove-AzureStorageBlob :远程服务器返回了错误:(412) Blob 中当前包含租约,但请求中未指定任何租约 ID。HTTP 状态代码:412 - HTTP 错误消息:Blob 中当前包含租约,但请求中未指定任何租约 ID。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

在 Azure 门户中执行以下步骤:Follow these steps on the Azure portal:

  1. 导航到 Azure 门户Navigate to the Azure portal.

  2. 导航到“磁盘(经典)”。Navigate to the Disks(classic).

  3. 单击“磁盘”选项卡。门户屏幕截图,其中显示容器 Blob“列表”窗格已打开Click the Disks tab. Screenshot of the portal, with the container blob "list" pane open

  4. 选择用户的数据磁盘,并单击“删除磁盘”。Select your data disk, then click Delete Disk. 门户屏幕截图,其中显示容器 Blob“列表”窗格已打开Screenshot of the portal, with the container blob "list" pane open

  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

在 Azure 门户中执行以下步骤:Follow these steps on the Azure portal:

  1. 导航到 Azure 门户Navigate to the Azure portal.
  2. 导航到“OS 映像(经典)”。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.