将 Azure 托管磁盘存储从标准类型转换为高级类型,或者从高级类型转换为标准类型Convert Azure managed disks storage from Standard to Premium or Premium to Standard

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.

本文介绍如何使用 Azure CLI 将托管磁盘从标准类型转换为高级类型,或者从高级类型转换为标准类型。This article shows how to convert managed disks from Standard to Premium or Premium to Standard by using the Azure CLI. 若要安装或升级 CLI 工具,请参阅安装 Azure CLITo install or upgrade the tool, see Install Azure CLI.

准备阶段Before you begin

  • 磁盘转换需要重启虚拟机 (VM),因此请在预先存在的维护时段内计划磁盘存储迁移。Disk conversion requires a restart of the virtual machine (VM), so schedule the migration of your disk storage during a pre-existing maintenance window.
  • 对于非托管磁盘,请先转换为托管磁盘,以便可以在存储选项之间切换。For unmanaged disks, first convert to managed disks 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.

备注

在 Azure China 中使用 Azure CLI 2.0 之前,请首先运行 az cloud set -n AzureChinaCloud 更改云环境。Before you can use Azure CLI 2.0 in Azure China, please run az cloud set -n AzureChinaCloud first to change the cloud environment. 如果要切换回全局 Azure,请再次运行 az cloud set -n AzureCloudIf you want to switch back to Global Azure, run az cloud set -n AzureCloud again.


#resource group that contains the virtual machine
rgName='yourResourceGroup'

#Name of the virtual machine
vmName='yourVM'

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

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

#Deallocate the VM before changing the size of the VM
az vm deallocate --name $vmName --resource-group $rgName

#Change the VM size to a size that supports Premium storage 
#Skip this step if converting storage from Premium to Standard
az vm resize --resource-group $rgName --name $vmName --size $size

#Update the SKU of all the data disks 
az vm show -n $vmName -g $rgName --query storageProfile.dataDisks[*].managedDisk -o tsv \
| awk -v sku=$sku '{system("az disk update --sku "sku" --ids "$1)}'

#Update the SKU of the OS disk
az vm show -n $vmName -g $rgName --query storageProfile.osDisk.managedDisk -o tsv \
| awk -v sku=$sku '{system("az disk update --sku "sku" --ids "$1)}'

az vm start --name $vmName --resource-group $rgName

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

对于开发/测试工作负荷,可以混合使用标准磁盘和高级磁盘来降低成本。For your dev/test workload, you might want to have 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 switches to a size that supports Premium storage.


#resource group that contains the managed disk
rgName='yourResourceGroup'

#Name of your managed disk
diskName='yourManagedDiskName'

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

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

#Get the parent VM Id 
vmId=$(az disk show --name $diskName --resource-group $rgName --query managedBy --output tsv)

#Deallocate the VM before changing the size of the VM
az vm deallocate --ids $vmId 

#Change the VM size to a size that supports Premium storage 
#Skip this step if converting storage from Premium to Standard
az vm resize --ids $vmId --size $size

# Update the SKU
az disk update --sku $sku --name $diskName --resource-group $rgName 

az vm start --ids $vmId 

在标准 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.


#resource group that contains the managed disk
rgName='yourResourceGroup'

#Name of your managed disk
diskName='yourManagedDiskName'

#Choose between Standard_LRS and StandardSSD_LRS based on your scenario
sku='StandardSSD_LRS'

#Get the parent VM ID 
vmId=$(az disk show --name $diskName --resource-group $rgName --query managedBy --output tsv)

#Deallocate the VM before changing the disk type
az vm deallocate --ids $vmId 

# Update the SKU
az disk update --sku $sku --name $diskName --resource-group $rgName 

az vm start --ids $vmId 

使用 Azure 门户在标准类型与高级类型之间切换托管磁盘Switch managed disks between Standard and Premium in Azure portal

执行以下步骤:Follow these steps:

  1. 登录到 Azure 门户Sign in to the Azure portal.
  2. 在“虚拟机”列表中选择 VM。Select the VM from the list of Virtual machines.
  3. 如果该 VM 未停止,请在 VM“概述”窗格的顶部选择“停止”,然后等待该 VM 停止。 If the VM isn't stopped, select Stop at the top of the 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”,或者从“高级 SSD”更改为“标准 HDD”。 Change the Account type from Standard HDD to Premium SSD or from Premium SSD to Standard HDD.
  8. 选择“保存”并关闭磁盘窗格。Select Save, and close the disk pane.

磁盘类型会即时更新。The update of the disk type is instantaneous. 转换后,可以重启 VM。You can restart your VM after the conversion.

后续步骤Next steps

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