CreateOrUpdate: context deadline exceeded , while removing data disk

Tamer Mohamed 0 Reputation points
2026-07-05T02:01:53.84+00:00

I'm getting context deadline exceeded error while trying to detach disks from azure virtual machine.

Azure Virtual Machines
Azure Virtual Machines

An Azure service that is used to provision Windows and Linux virtual machines.


2 answers

Sort by: Most helpful
  1. TP 158.8K Reputation points Volunteer Moderator
    2026-07-05T02:37:17.9566667+00:00

    Hi,

    Have you tried force detach? You may use command similar to below in Azure Cloud Shell:

    az vm disk detach --resource-group my_resource_group --vm-name vm --name managed_disk_name --force-detach
    

    Please click Accept Answer and upvote if the above was helpful.

    Thanks.

    -TP

    Was this answer helpful?

    0 comments No comments

  2. AI answer

    2026-07-05T02:02:15.5733333+00:00

    context deadline exceeded during disk detach usually indicates the operation is timing out or blocked by an underlying lease or attachment state. Use the supported detach paths and then verify the disk/VHD lease is released.

    1. Detach the data disk from the VM (portal)
      • In Azure portal, go to Virtual Machines.
      • Select the VM that has the data disk.
      • Under Settings, select Disks.
      • On the Disks pane, to the far right of the data disk to detach, select the detach button (X icon).
      • Select Save at the top of the page.
      • The disk remains in storage but is no longer attached to the VM.
    2. Detach the data disk from the VM (PowerShell)
      • Make sure nothing is actively using the disk.
      • Run:
             $vm = Get-AzVM -ResourceGroupName "myResourceGroup" -Name "myVM"
             Remove-AzVMDataDisk -VM $vm -Name "myDisk"
             Update-AzVM -ResourceGroupName "myResourceGroup" -VM $vm
        
      • The disk stays in storage but is detached from the VM.
      • In regions where lower detach latency is available, call Remove-AzVMDataDisk explicitly to benefit from reduced latency.
    3. If the error occurs while deleting the underlying VHD/blob
      • Azure prevents deletion of a disk/blob that is still attached or leased.
      • Ensure the disk is detached as above, then wait a few minutes for the lease to clear.
      • To verify:
        • In the portal, browse to the storage account → container → blob (VHD).
        • In Blob properties, confirm Lease Status is Unlocked or Available.
      • If the lease is still active, re-check that the disk is not attached to any VM and retry after a short delay.
    4. If the VM deployment or update is failing due to a problematic disk
      • For API-based operations, set the toBeDetached flag for the failing data disk via the Compute REST API, or remove the failing data disk from the VM payload, then PATCH the VM:
             GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}?$expand=instanceView&api-version=2019-03-01
        
        Modify the disk section (set toBeDetached = true or remove the disk), then:
             PATCH https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}?api-version=2019-03-01
        
      • This clears failing disk attachments that can cause long-running or timed-out operations.

    If context deadline exceeded persists, validate that:

    • The disk is not being used by the guest OS (no active I/O).
    • The VM is in a healthy state (not stuck in failed updates).
    • The VHD/blob lease has transitioned to Unlocked/Available before attempting deletion or further operations.

    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.