更改 Azure 托管磁盘的磁盘类型
适用于:✔️ Linux VM ✔️ Windows
Azure 托管磁盘有四种磁盘类型:Azure 超级磁盘、高级 SSD、标准 SSD 和标准 HDD。 可以根据性能需求轻松在高级 SSD、标准 SSD 和标准 HDD 之间进行切换。 尚无法与超级磁盘进行切换,必须部署一个新磁盘。
非托管磁盘不支持此功能。 但是,可以轻松通过 CLI 或 PowerShell 将非托管磁盘转换为托管磁盘,然后即可切换磁盘类型。
在开始之前
由于转换需要重启虚拟机 (VM),因此请在预先存在的维护时段内计划磁盘迁移。
限制
- 每天只能更改两次磁盘类型。
- 只能更改托管磁盘的磁盘类型。 如果是非托管磁盘,请通过 CLI 或 PowerShell 将其转换为托管磁盘,以在磁盘类型之间进行切换。
将 VM 的所有托管磁盘从一个帐户切换到另一个帐户
此示例展示了如何将 VM 的所有磁盘转换为高级存储。 不过,通过在此示例中更改 $storageType 变量,可以将 VM 的磁盘类型转换为标准 SSD 或标准 HDD。 若要使用高级托管磁盘,VM 必须使用支持高级存储的 VM 大小。 此示例还切换到了支持高级存储的大小:
# Name of the resource group that contains the VM
$rgName = 'yourResourceGroup'
# Name of the your virtual machine
$vmName = 'yourVM'
# Choose between Standard_LRS, StandardSSD_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
更改单个托管磁盘的类型
对于开发/测试工作负荷,可以混合使用标准磁盘和高级磁盘来降低成本。 可以选择仅升级需要更高性能的磁盘。 此示例展示了如何将单个 VM 磁盘从标准存储转换为高级存储。 不过,通过在此示例中更改 $storageType 变量,可以将 VM 的磁盘类型转换为标准 SSD 或标准 HDD。 若要使用高级托管磁盘,VM 必须使用支持高级存储的 VM 大小。 此示例还展示了如何切换到支持高级存储的大小:
$diskName = 'yourDiskName'
# resource group that contains the managed disk
$rgName = 'yourResourceGroupName'
# Choose between Standard_LRS, StandardSSD_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
迁移到超级磁盘
目前,只能通过快照将现有磁盘迁移到超级磁盘。 超级磁盘有其自身的一组限制。 例如,它不能用作 OS 磁盘,并且并非在所有区域中都可用。 有关详细信息,请参阅相关文章的超级磁盘 GA 范围和限制部分。
重要
将标准 HDD、标准 SSD 或高级 SSD 迁移到超级磁盘时,逻辑扇区大小必须为 512。
以下脚本将标准 HDD、标准 SSD 或高级 SSD 的快照迁移到超级磁盘。
$diskName = "yourDiskNameHere"
$resourceGroupName = "yourResourceGroupNameHere"
$snapshotName = "yourDesiredSnapshotNameHere"
# Valid values are 1, 2, or 3
$zone = "yourZoneNumber"
#Provide the size of the disks in GB. It should be greater than the VHD file size.
$diskSize = '128'
#Provide the storage type. Use UltraSSD_LRS.
$storageType = 'UltraSSD_LRS'
#Provide the Azure region (e.g. chinanorth) where Managed Disks will be located.
#This location should be same as the snapshot location
#Get all the Azure location using command below:
#Get-AzLocation
#Select the same location as the current disk
#Note that Ultra Disks are only supported in a select number of regions
$location = 'chinanorth3'
#When migrating a Standard HDD, Standard SSD, or Premium SSD to an Ultra Disk, the logical sector size must be 512
$logicalSectorSize=512
# Get the disk that you need to backup by creating an incremental snapshot
$yourDisk = Get-AzDisk -DiskName $diskName -ResourceGroupName $resourceGroupName
# Create an incremental snapshot by setting the SourceUri property with the value of the Id property of the disk
$snapshotConfig=New-AzSnapshotConfig -SourceUri $yourDisk.Id -Location $yourDisk.Location -CreateOption Copy -Incremental
$snapshot = New-AzSnapshot -ResourceGroupName $resourceGroupName -SnapshotName $snapshotName -Snapshot $snapshotConfig
$diskConfig = New-AzDiskConfig -SkuName $storageType -Location $location -CreateOption Copy -SourceResourceId $snapshot.Id -DiskSizeGB $diskSize -LogicalSectorSize $logicalSectorSize -Zone $zone
New-AzDisk -Disk $diskConfig -ResourceGroupName $resourceGroupName -DiskName $diskName
后续步骤
使用快照创建 VM 的只读副本。