如何从 Windows 虚拟机分离数据磁盘How to detach a data disk from a Windows virtual machine

当不再需要附加到虚拟机的数据磁盘时,可以轻松地分离它。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.

警告

如果用户分离磁盘,它不会自动删除。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.

使用 PowerShell 分离数据磁盘Detach a data disk using PowerShell

可以使用 PowerShell 热删除数据磁盘,但在从 VM 中分离磁盘之前,请确保没有任何设备正在使用该磁盘。You can hot remove a data disk using PowerShell, but make sure nothing is actively using the disk before detaching it from the VM.

在此示例中,我们从 myResourceGroup 资源组的 VM myVM 中删除名为 myDisk 的磁盘。In this example, we remove the disk named myDisk from the VM myVM in the myResourceGroup resource group. 首先,使用 Remove-AzVMDataDisk cmdlet 删除磁盘。First you remove the disk using the Remove-AzVMDataDisk cmdlet. 然后,使用 Update-AzVM cmdlet 更新虚拟机的状态,完成数据磁盘删除过程。Then, you update the state of the virtual machine, using the Update-AzVM cmdlet, to complete the process of removing the data disk.

Connect-AzAccount -Environment AzureChinaCloud
$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.

使用门户分离数据磁盘Detach a data disk using the portal

可以热删除数据磁盘,但在从 VM 中分离该磁盘之前,请确保没有任何设备正在活跃地使用该磁盘。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. 在“磁盘”窗格的顶部,选择“编辑”。At the top of the Disks pane, select Edit.
  5. 在“磁盘”窗格中,在要分离的数据磁盘的最右侧,选择“分离”。In the Disks pane, to the far right of the data disk that you would like to detach, select Detach.
  6. 选择页面顶部的“保存”以保存更改。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.

后续步骤Next steps

要重新使用数据磁盘,只需将其附加到其他 VM 即可If you want to reuse the data disk, you can just attach it to another VM