更新托管磁盘的存储类型Update the storage type of a managed disk

Azure 托管磁盘有三种磁盘类型:高级 SSD、标准 SSD 和标准 HDD。There are three disk types of Azure managed disks: premium SSD, standard SSD, and standard HDD. 可以根据性能需求在三种 GA 磁盘类型(高级 SSD、标准 SSD 和标准 HDD)之间切换。You can switch between the three GA disk types (premium SSD, standard SSD, and standard HDD) based on your performance needs.

非托管磁盘不支持此功能。This functionality is not supported for unmanaged disks. 但是,可以轻松将非托管磁盘转换为托管磁盘,然后即可切换磁盘类型。But you can easily convert an unmanaged disk to a managed disk to be able to switch between disk types.

先决条件Prerequisites

  • 由于转换需要重启虚拟机 (VM),因此请在预先存在的维护时段内计划磁盘存储迁移。Because conversion requires a restart of the virtual machine (VM), you should schedule the migration of your disk storage during a pre-existing maintenance window.
  • 对于非托管磁盘,请先将其转换为托管磁盘,以便可以在存储选项之间切换。If your disk is unmanaged, first convert it to a managed disk so you can switch between storage options.

将 VM 的所有托管磁盘在高级类型与标准类型之间切换Switch all managed disks of a VM between Premium and Standard

此示例演示如何将 VM 的所有磁盘从标准存储转换为高级存储,或者从高级存储转换为标准存储。This example shows how to convert all of a VM's disks from Standard to Premium storage or from Premium to Standard storage. 若要使用高级托管磁盘,VM 必须使用支持高级存储的 VM 大小To use Premium managed disks, your VM must use a VM size that supports Premium storage. 此示例还切换到了支持高级存储的大小:This example also switches to a size that supports premium storage:

# Sign in the Azure China Cloud
Connect-AzAccount -Environment AzureChinaCloud

# Name of the resource group that contains the VM
$rgName = 'yourResourceGroup'

# Name of the your virtual machine
$vmName = 'yourVM'

# Choose between Standard_LRS and Premium_LRS based on your scenario
$storageType = 'Premium_LRS'

# Premium capable size
# Required only if converting storage from Standard to Premium
$size = 'Standard_DS2_v2'

# Stop and deallocate the VM before changing the size
Stop-AzVM -ResourceGroupName $rgName -Name $vmName -Force

$vm = Get-AzVM -Name $vmName -resourceGroupName $rgName

# Change the VM size to a size that supports Premium storage
# Skip this step if converting storage from Premium to Standard
$vm.HardwareProfile.VmSize = $size
Update-AzVM -VM $vm -ResourceGroupName $rgName

# Get all disks in the resource group of the VM
$vmDisks = Get-AzDisk -ResourceGroupName $rgName 

# For disks that belong to the selected VM, convert to Premium storage
foreach ($disk in $vmDisks)
{
    if ($disk.ManagedBy -eq $vm.Id)
    {
        $disk.Sku = [Microsoft.Azure.Management.Compute.Models.DiskSku]::new($storageType)
        $disk | Update-AzDisk
    }
}

Start-AzVM -ResourceGroupName $rgName -Name $vmName

在标准类型与高级类型之间切换单个托管磁盘Switch individual managed disks between Standard and Premium

对于开发/测试工作负荷,可以混合使用标准磁盘和高级磁盘来降低成本。For your dev/test workload, you might want a mix of Standard and Premium disks to reduce your costs. 可以选择仅升级需要更高性能的磁盘。You can choose to upgrade only those disks that need better performance. 此示例演示如何将单个 VM 磁盘从标准存储转换为高级存储,或者从高级存储转换为标准存储。This example shows how to convert a single VM disk from Standard to Premium storage or from Premium to Standard storage. 若要使用高级托管磁盘,VM 必须使用支持高级存储的 VM 大小To use Premium managed disks, your VM must use a VM size that supports Premium storage. 此示例还展示了如何切换到支持高级存储的大小:This example also shows how to switch to a size that supports Premium storage:

# Sign in the Azure China Cloud
Connect-AzAccount -Environment AzureChinaCloud

$diskName = 'yourDiskName'
# resource group that contains the managed disk
$rgName = 'yourResourceGroupName'
# Choose between Standard_LRS and Premium_LRS based on your scenario
$storageType = 'Premium_LRS'
# Premium capable size 
$size = 'Standard_DS2_v2'

$disk = Get-AzDisk -DiskName $diskName -ResourceGroupName $rgName

# Get parent VM resource
$vmResource = Get-AzResource -ResourceId $disk.ManagedBy

# Stop and deallocate the VM before changing the storage type
Stop-AzVM -ResourceGroupName $vmResource.ResourceGroupName -Name $vmResource.Name -Force

$vm = Get-AzVM -ResourceGroupName $vmResource.ResourceGroupName -Name $vmResource.Name 

# Change the VM size to a size that supports Premium storage
# Skip this step if converting storage from Premium to Standard
$vm.HardwareProfile.VmSize = $size
Update-AzVM -VM $vm -ResourceGroupName $rgName

# Update the storage type
$disk.Sku = [Microsoft.Azure.Management.Compute.Models.DiskSku]::new($storageType)
$disk | Update-AzDisk

Start-AzVM -ResourceGroupName $vm.ResourceGroupName -Name $vm.Name

在 Azure 门户中将托管磁盘从标准类型转换为高级类型Convert managed disks from Standard to Premium in the Azure portal

执行以下步骤:Follow these steps:

  1. 登录到 Azure 门户Sign in to the Azure portal.
  2. 在门户上的“虚拟机”列表中选择 VM。Select the VM from the list of Virtual machines in the portal.
  3. 如果该 VM 未停止,请在 VM“概述”窗格的顶部选择“停止”,然后等待该 VM 停止。 If the VM isn't stopped, select Stop at the top of VM Overview pane, and wait for the VM to stop.
  4. 在 VM 对应的窗格中,从菜单中选择“磁盘”。In the pane for the VM, select Disks from the menu.
  5. 选择要转换的磁盘。Select the disk that you want to convert.
  6. 在菜单中选择“配置”。Select Configuration from the menu.
  7. 将“帐户类型”从“标准 HDD”更改为“高级 SSD”。 Change the Account type from Standard HDD to Premium SSD.
  8. 单击“保存”并关闭磁盘窗格。Click Save, and close the disk pane.

磁盘类型转换会瞬间完成。The disk type conversion is instantaneous. 可以在转换后启动 VM。You can start your VM after the conversion.

在标准 HDD 与标准 SSD 之间切换托管磁盘Switch managed disks between Standard HDD and Standard SSD

此示例演示如何将单个 VM 磁盘从标准 HDD 转换为标准 SSD,或者从标准 SSD 转换为标准 HDD:This example shows how to convert a single VM disk from Standard HDD to Standard SSD or from Standard SSD to Standard HDD:

# Sign in the Azure China Cloud
Connect-AzAccount -Environment AzureChinaCloud

$diskName = 'yourDiskName'
# resource group that contains the managed disk
$rgName = 'yourResourceGroupName'
# Choose between Standard_LRS and StandardSSD_LRS based on your scenario
$storageType = 'StandardSSD_LRS'

$disk = Get-AzDisk -DiskName $diskName -ResourceGroupName $rgName

# Get parent VM resource
$vmResource = Get-AzResource -ResourceId $disk.ManagedBy

# Stop and deallocate the VM before changing the storage type
Stop-AzVM -ResourceGroupName $vmResource.ResourceGroupName -Name $vmResource.Name -Force

$vm = Get-AzVM -ResourceGroupName $vmResource.ResourceGroupName -Name $vmResource.Name 

# Update the storage type
$disk.Sku = [Microsoft.Azure.Management.Compute.Models.DiskSku]::new($storageType)
$disk | Update-AzDisk

Start-AzVM -ResourceGroupName $vm.ResourceGroupName -Name $vm.Name

后续步骤Next steps

使用快照创建 VM 的只读副本。Make a read-only copy of a VM by using a snapshot.