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

在某些情况下,在 Azure 资源管理器部署中尝试删除 Azure 存储帐户、容器或 blob 时,可能会遇到下列错误之一:In certain scenarios, you may encounter one of the following errors occur while you are trying to delete an Azure storage account, container, or blob in an Azure Resource Manager deployment:

无法删除存储帐户“StorageAccountName”。错误:正在使用存储帐户的项目,因此无法删除该存储帐户。Failed to delete storage account 'StorageAccountName'. Error: The storage account cannot be deleted due to its artifacts being in use.

无法删除 # 个容器(共 # 个):
vhds:目前容器上有租用,但请求中未指定任何租用 ID。
Failed to delete # out of # container(s):
vhds: There is currently a lease on the container and no lease ID was specified in the request.

无法删除 # 个 blob (共 # 个):
BlobName.vhd:目前 blob 上有租用,但请求中未指定任何租用 ID。
Failed to delete # out of # blobs:
BlobName.vhd: There is currently a lease on the blob and no lease ID was specified in the request.

Azure VM 中使用的 VHD 是在 Azure 的标准或高级存储帐户中作为页 Blob 存储的 .vhd 文件。The VHDs used in Azure VMs are .vhd files stored as page blobs in a standard or premium storage account in Azure. 有关 Azure 磁盘的详细信息,请参阅托管磁盘简介For more information about Azure disks, see our Introduction to managed disks.

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 that have a page blob that is attached to a VM.

如果收到上述错误之一,请遵循以下过程,删除存储帐户、容器或 blob:The process to delete a storage account, container, or blob when receiving one of these errors is:

  1. 发现附加到 VM 的 blobIdentify blobs attached to a VM
  2. 删除附加有 OS 磁盘 的 VMDelete VMs with attached OS disk
  3. 将所有数据磁盘 与剩余 VM 拆离Detach all data disk(s) from remaining VM(s)

完成上述步骤后,重试删除存储帐户、容器或 blob。Retry deleting the storage account, container, or blob after these steps are completed.

第 1 步:发现附加到 VM 的 blobStep 1: Identify blob attached to a VM

场景 1:删除 Blob - 识别附加的 VMScenario 1: Deleting a blob - identify attached VM

  1. 登录 Azure 门户Sign in to the Azure portal.

  2. 在“中心”菜单上,选择“所有资源” 。On the Hub menu, select All resources. 转到存储帐户,在“Blob 服务” 下,选择“容器” ,并导航到要删除的 blob。Go to the storage account, under Blob Service select Containers , and navigate to the blob to delete.

  3. 如果 blob 的“租用状态” 为“已租用” ,则右键单击并选择“编辑元数据” ,打开“blob 元数据”窗格。If the blob Lease State is Leased , then right-click and select Edit Metadata to open Blob metadata pane.

    门户的屏幕截图,其中突出显示了存储帐户 blob 和右键单击后出现的“编辑元数据”

  4. 在“blob 元数据”窗格中,查看并记录 MicrosoftAzureCompute_VMName 的值。In Blob metadata pane, check and record the value for MicrosoftAzureCompute_VMName. 此值是 VHD 附加到的 VM 名称。This value is the name of the VM that the VHD is attached to. (如果看不到此字段,请参阅“重要提示” )(See important if this field does not exist)

  5. 在“blob 元数据”窗格中,查看并记录 MicrosoftAzureCompute_DiskType 的值。In Blob metadata pane, check and record the value of MicrosoftAzureCompute_DiskType. 此值确定了附加磁盘是 OS 磁盘,还是数据磁盘(如果此字段不存在,请参阅“重要提示” )。This value identifies if the attached disk is OS or data disk (See important if this field does not exist).

    门户屏幕截图,其中打开了存储“blob 元数据”窗格

  6. 如果 blob 磁盘类型为 OSDisk ,请按照第 2 步:删除 VM 以拆离 OS 磁盘操作。If the blob disk type is OSDisk follow Step 2: Delete VM to detach OS disk. 否则,如果 blob 磁盘类型为 DataDisk ,请按照第 3 步:将数据磁盘与 VM 拆离操作。Otherwise, if the blob disk type is DataDisk follow the steps in Step 3: Detach data disk from the VM.

重要

如果 blob 元数据中没有 MicrosoftAzureCompute_VMName 和 MicrosoftAzureCompute_DiskType ,表明 blob 为显式租用,未附加到 VM。If MicrosoftAzureCompute_VMName and MicrosoftAzureCompute_DiskType do not appear in the blob metadata, it indicates that the blob is explicitly leased and is not attached to a VM. 必须先中断租用,然后才能删除租用的 blob。Leased blobs cannot be deleted without breaking the lease first. 若要中断租用,请右键单击 blob 并选择“中断租用” 。To break lease, right-click on the blob and select Break lease. 如果租用的 blob 未附加到 VM,则会阻止删除 blob,但不会阻止删除容器或存储帐户。Leased blobs that are not attached to a VM prevent deletion of the blob, but do not prevent deletion of container or storage account.

方案 2:删除容器 - 发现容器内附加到 VM 的所有 blobScenario 2: Deleting a container - identify all blob(s) within container that are attached to VMs

  1. 登录 Azure 门户Sign in to the Azure portal.

  2. 在“中心”菜单上,选择“所有资源” 。On the Hub menu, select All resources. 转到存储帐户,在“Blob 服务” 下,选择“容器” ,并找到要删除的容器。Go to the storage account, under Blob Service select Containers , and find the container to be deleted.

  3. 单击打开容器,列出容器内的 blob。Click to open the container and the list of blobs inside it will appear. 在列表中发现“blob 类型”为“页 blob” 且“租用状态”为“已租用” 的所有 blob。Identify all the blobs with Blob Type = Page blob and Lease State = Leased from this list. 按照方案 1 操作,发现与其中每个 blob 相关联的 VM。Follow Scenario 1 to identify the VM associated with each of these blobs.

    门户屏幕截图,其中突出显示了存储帐户 blob 和值为“已租用”的“租用状态”

  4. 按照第 2 步第 3 步操作,删除附加有 OSDisk 的 VM,并拆离 DataDisk 。Follow Step 2 and Step 3 to delete VM(s) with OSDisk and detach DataDisk.

方案 3:删除存储帐户 - 发现存储帐户内附加到 VM 的所有 blobScenario 3: Deleting storage account - identify all blob(s) within storage account that are attached to VMs

  1. 登录 Azure 门户Sign in to the Azure portal.
  2. 在“中心”菜单上,选择“所有资源” 。On the Hub menu, select All resources. 转到存储帐户,在“blob 服务” 下,选择“Blob” 。Go to the storage account, under Blob Service select Blobs.
  3. 在“容器” 窗格中,找到“租用状态” 为“已租用” 的所有容器,并按照方案 2 对每个状态为“已租用” 的容器执行操作。In Containers pane, identify all containers where Lease State is Leased and follow Scenario 2 for each Leased container.
  4. 按照第 2 步第 3 步操作,删除附加有 OSDisk 的 VM,并拆离 DataDisk 。Follow Step 2 and Step 3 to delete VM(s) with OSDisk and detach DataDisk.

第 2 步:删除 VM 以拆离 OS 磁盘Step 2: Delete VM to detach OS disk

如果 VHD 为 OS 磁盘,必须先删除 VM,然后才能删除附加的 VHD。If the VHD is an OS disk, you must delete the VM before the attached VHD can be deleted. 完成以下步骤后,无需对附加到同一 VM 的数据磁盘执行其他任何操作:No additional action will be required for data disks attached to the same VM once these steps are completed:

  1. 登录 Azure 门户Sign in to the Azure portal.
  2. 在“中心”菜单上,选择“虚拟机” 。On the Hub menu, select Virtual Machines.
  3. 选择 VHD 附加到的 VM。Select the VM that the VHD is attached to.
  4. 确保没有任何对象正主动使用该虚拟机,并确保不再需要该虚拟机。Make sure that nothing is actively using the virtual machine, and that you no longer need the virtual machine.
  5. 在“虚拟机详细信息” 窗格顶部,选择“删除” ,再单击“是” 进行确认。At the top of the Virtual Machine details pane, select Delete , and then click Yes to confirm.
  6. 应删除 VM,但可以保留 VHD。The VM should be deleted, but the VHD can be retained. 不过,VHD 不得再附加到 VM,也不得再有租用。However, the VHD should no longer be attached to a VM or have a lease on it. 可能需要几分钟才能释放租约。It may take a few minutes for the lease to be released. 若要验证租用是否已解除,请转到 blob 位置,再检查“blob 属性” 窗格中的“租用状态” 是否为“可租用” 。To verify that the lease is released, browse to the blob location and in the Blob properties pane, the Lease Status should be Available.

第 3 步:将数据磁盘与 VM 拆离Step 3: Detach data disk from the VM

如果 VHD 是数据磁盘,请从 VM 分离 VHD 以删除租约:If the VHD is a data disk, detach the VHD from the VM to remove the lease:

  1. 登录 Azure 门户Sign in to the Azure portal.

  2. 在“中心”菜单上,选择“虚拟机” 。On the Hub menu, select Virtual Machines.

  3. 选择 VHD 附加到的 VM。Select the VM that the VHD is attached to.

  4. 在“虚拟机详细信息”窗格中,选择“磁盘”。Select Disks on the Virtual Machine details pane.

  5. 选择 VHD 附加到的要删除的数据磁盘。Select the data disk to be deleted the VHD is attached to. 可以检查 VHD 的 URL,从而确定磁盘中附加的 blob。You can determine which blob is attached in the disk by checking the URL of the VHD.

  6. 可以单击磁盘来检查“VHD URI” 字段中的路径,从而验证 blob 位置。You can verify the blob location by clicking on the disk to check the path in VHD URI field.

  7. 选择“磁盘”窗格顶部的“编辑”。Select Edit on the top of Disks pane.

  8. 单击要删除的数据磁盘的拆离图标 。Click detach icon of the data disk to be deleted.

    门户的屏幕截图,其中打开了存储“Blob 元数据”窗格,并突出显示要删除的数据磁盘的拆离图标。

  9. 选择“保存”。 Select Save. 此时该磁盘将与 VM 分离,并且 VHD 将不再租用。The disk is now detached from the VM, and the VHD is no longer leased. 可能需要几分钟才能释放租约。It may take a few minutes for the lease to be released. 若要验证租用是否已解除,请转到 blob 位置,再检查“blob 属性” 窗格中的“租用状态” 值是否为“已解锁” 或“可租用” 。To verify that the lease has been released, browse to the blob location and in the Blob properties pane, the Lease Status value should be Unlocked or Available.