Rediģēt

Kopīgot, izmantojot


How to detach a data disk from a Windows virtual machine

Applies to: ✔️ Windows VMs ✔️ Flexible scale sets

When you no longer need a data disk that's attached to a virtual machine, you can easily detach it. This removes the disk from the virtual machine, but doesn't remove it from storage.

Warning

If you detach a disk it is not automatically deleted. If you have subscribed to Premium storage, you will continue to incur storage charges for the disk. For more information, see Pricing and Billing when using Premium Storage.

If you want to use the existing data on the disk again, you can reattach it to the same virtual machine, or another one.

Prerequisites

None

Detach a data disk using PowerShell

You can hot remove a data disk using PowerShell, but make sure nothing is actively using the disk before detaching it from the VM.

In this example, we remove the disk named myDisk from the VM myVM in the myResourceGroup resource group. First you remove the disk using the Remove-AzVMDataDisk cmdlet. Then, you update the state of the virtual machine, using the Update-AzVM cmdlet, to complete the process of removing the data disk.

$VirtualMachine = Get-AzVM `
  -ResourceGroupName "myResourceGroup" `
  -Name "myVM"
Remove-AzVMDataDisk `
  -VM $VirtualMachine `
  -Name "myDisk"
Update-AzVM `
  -ResourceGroupName "myResourceGroup" `
  -VM $VirtualMachine

The disk stays in storage but is no longer attached to a virtual machine.

Lower latency

In select regions, the disk detach latency has been reduced, so you'll see an improvement of up to 15%. This is useful if you have planned/unplanned failovers between VMs, you're scaling your workload, or are running a high scale stateful workload such as Azure Kubernetes Service. However, this improvement is limited to the explicit disk detach command, Remove-AzVMDataDisk. You won't see the performance improvement if you call a command that may implicitly perform a detach, like Update-AzVM. You don't need to take any action other than calling the explicit detach command to see this improvement.

Lower latency is currently available in every public region except for:

  • Canada Central
  • Central US
  • East US
  • East US 2
  • South Central US
  • West US 2
  • Germany North
  • Jio India West
  • North Europe
  • West Europe

Detach a data disk using the portal

You can hot remove a data disk, but make sure nothing is actively using the disk before detaching it from the VM.

  1. In the left menu, select Virtual Machines.

  2. Select the virtual machine that has the data disk you want to detach.

  3. Under Settings, select Disks.

  4. In the Disks pane, to the far right of the data disk that you would like to detach, select the detach button to detach.

  5. Select Save on the top of the page to save your changes.

    The disk stays in storage but is no longer attached to a virtual machine. The disk isn't deleted.