用于 Azure VM 的临时 OS 磁盘Ephemeral OS disks for Azure VMs

临时 OS 磁盘在本地虚拟机 (VM) 存储中创建,不保存到远程 Azure 存储。Ephemeral OS disks are created on the local virtual machine (VM) storage and not saved to the remote Azure Storage. 临时 OS 磁盘适用于无状态工作负荷,在此类工作负荷中,应用程序可以容忍单个 VM 故障,但受 VM 部署时间或单个 VM 实例的映像重置的影响更大。Ephemeral OS disks work well for stateless workloads, where applications are tolerant of individual VM failures, but are more affected by VM deployment time or reimaging the individual VM instances. 使用临时 OS 磁盘时,通过 OS 磁盘进行读取/写入的延迟更低,VM 重置映像速度会更快。With Ephemeral OS disk, you get lower read/write latency to the OS disk and faster VM reimage.

临时磁盘 (ephemeral disk) 的重要功能包括:The key features of ephemeral disks are:

  • 适用于无状态应用程序。Ideal for stateless applications.
  • 可以与市场和自定义映像配合使用。They can be used with both Marketplace and custom images.
  • 能够将 VM 和规模集实例或其映像快速重置为原始启动状态。Ability to fast reset or reimage VMs and scale set instances to the original boot state.
  • 与临时磁盘一样降低延迟。Lower latency, similar to a temporary disk.
  • 临时 OS 磁盘免费,因此不需为 OS 磁盘支付存储费用。Ephemeral OS disks are free, you incur no storage cost for OS disk.
  • 它们在所有 Azure 区域中提供。They are available in all Azure regions.
  • 共享映像库支持临时 OS 磁盘。Ephemeral OS Disk is supported by Shared Image Gallery.

持久 OS 磁盘和临时 OS 磁盘的主要区别:Key differences between persistent and ephemeral OS disks:

持久 OS 磁盘Persistent OS Disk 临时 OS 磁盘Ephemeral OS Disk
OS 磁盘的大小限制Size limit for OS disk 2 TiB2 TiB 与 VM 大小相对应的缓存大小或 2TiB,具体取决于哪一个更小。Cache size for the VM size or 2TiB, whichever is smaller. 对于“缓存大小(GiB)”,请参阅 DSESMFSFor the cache size in GiB, see DS, ES, M, and FS
支持的 VM 大小VM sizes supported 全部All DSv1、DSv2、DSv3、Esv3、Fs、FsV2、MDSv1, DSv2, DSv3, Esv3, Fs, FsV2, M
磁盘类型支持Disk type support 托管和非托管 OS 磁盘Managed and unmanaged OS disk 仅托管 OS 磁盘Managed OS disk only
区域支持Region support 所有区域All regions 所有区域All regions
数据暂留Data persistence 写入 OS 磁盘的 OS 磁盘数据存储在 Azure 存储中OS disk data written to OS disk are stored in Azure Storage 写入 OS 磁盘的数据存储到本地 VM 存储,不保存到 Azure 存储。Data written to OS disk is stored to the local VM storage and is not persisted to Azure Storage.
“已停止-解除分配”状态Stop-deallocated state 可以先将 VM 和规模集实例停止-解除分配,然后再将其从“已停止-解除分配”状态重启VMs and scale set instances can be stop-deallocated and restarted from the stop-deallocated state 不能将 VM 和规模集实例停止-解除分配VMs and scale set instances cannot be stop-deallocated
专用 OS 磁盘支持Specialized OS disk support Yes No
OS 磁盘重设大小OS disk resize 在 VM 创建期间以及将 VM 停止-解除分配后均受支持Supported during VM creation and after VM is stop-deallocated 仅在 VM 创建期间受支持Supported during VM creation only
将大小重设为新的 VM 大小Resizing to a new VM size 保留 OS 磁盘数据OS disk data is preserved 删除 OS 磁盘上的数据并重新预配 OSData on the OS disk is deleted, OS is re-provisioned

大小要求Size requirements

部署 VM 和实例的映像时,其大小上限取决于 VM 缓存的大小。You can deploy VM and instance images up to the size of the VM cache. 例如,市场中的标准 Windows Server 映像大约为 127 GiB,这意味着所需 VM 大小的缓存大于 127 GiB。For example, Standard Windows Server images from the marketplace are about 127 GiB, which means that you need a VM size that has a cache larger than 127 GiB. 在此示例中,Standard_DS2_v2 的缓存大小为 86 GiB,不够大。In this case, the Standard_DS2_v2 has a cache size of 86 GiB, which is not large enough. Standard_DS3_v2 的缓存大小为 172 GiB,足够大。The Standard_DS3_v2 has a cache size of 172 GiB, which is large enough. 在此示例中,Standard_DS3_v2 是 DSv2 系列中能够用于此映像的最小大小。In this case, the Standard_DS3_v2 is the smallest size in the DSv2 series that you can use with this image. 市场中的基本 Linux 映像以及 [smallsize] 所表示的 Windows Server 映像通常为大约 30 GiB,可以使用大多数可用的 VM 大小。Basic Linux images in the Marketplace and Windows Server images that are denoted by [smallsize] tend to be around 30 GiB and can use most of the available VM sizes.

临时磁盘还要求 VM 大小支持高级存储。Ephemeral disks also require that the VM size supports Premium storage. 大小通常(但并非总是)在名称中包含 s,例如 DSv2 和 EsV3。The sizes usually (but not always) have an s in the name, like DSv2 and EsV3. 有关详细信息,请参阅 Azure VM 大小,其中详述了哪些大小支持高级存储。For more information, see Azure VM sizes for details around which sizes support Premium storage.

PowerShellPowerShell

若要将临时磁盘用于 PowerShell VM 部署,请在 VM 配置中使用 Set-AzVMOSDiskTo use an ephemeral disk for a PowerShell VM deployment, use Set-AzVMOSDisk in your VM configuration. -DiffDiskSetting 设置为 Local,将 -Caching 设置为 ReadOnlySet the -DiffDiskSetting to Local and -Caching to ReadOnly.

Set-AzVMOSDisk -DiffDiskSetting Local -Caching ReadOnly

对于规模集部署,请在配置中使用 Set-AzVmssStorageProfile cmdlet。For scale set deployments, use the Set-AzVmssStorageProfile cmdlet in your configuration. -DiffDiskSetting 设置为 Local,将 -Caching 设置为 ReadOnlySet the -DiffDiskSetting to Local and -Caching to ReadOnly.

Set-AzVmssStorageProfile -DiffDiskSetting Local -OsDiskCaching ReadOnly

CLICLI

若要将临时磁盘用于 CLI VM 部署,请将 az vm create 中的 --ephemeral-os-disk 参数设置为 true,将 --os-disk-caching 参数设置为 ReadOnlyTo use an ephemeral disk for a CLI VM deployment, set the --ephemeral-os-disk parameter in az vm create to true and the --os-disk-caching parameter to ReadOnly.

az vm create \
  --resource-group myResourceGroup \
  --name myVM \
  --image UbuntuLTS \
  --ephemeral-os-disk true \
  --os-disk-caching ReadOnly \
  --admin-username azureuser \
  --generate-ssh-keys

对于规模集,请对 az-vmss-create 使用相同的 --ephemeral-os-disk true 参数,并将 --os-disk-caching 参数设置为 ReadOnlyFor scale sets, you use the same --ephemeral-os-disk true parameter for az-vmss-create and set the --os-disk-caching parameter to ReadOnly.

门户Portal

在 Azure 门户中,可以选择在部署 VM 时使用临时磁盘,方法是:打开“磁盘”选项卡的“高级”部分。 对于“使用临时 OS 磁盘”选项,请选择“是”。 In the Azure portal, you can choose to use ephemeral disks when deploying a VM by opening the Advanced section of the Disks tab. For Use ephemeral OS disk select Yes.

显示单选按钮的屏幕截图,该按钮选中后即可使用临时 OS 磁盘

如果使用临时磁盘的选项灰显,则可能是因为选择的 VM 大小没有大于 OS 映像的缓存大小,或者不支持高级存储。If the option for using an ephemeral disk is greyed out, you might have selected a VM size that does not have a cache size larger than the OS image or that doesn't support Premium storage. 返回到“基本信息”页,尝试选择另一 VM 大小。 Go back to the Basics page and try choosing another VM size.

也可通过门户创建使用临时 OS 磁盘的规模集。You can also create scale-sets with ephemeral OS disks using the portal. 只需确保所选 VM 大小具有足够大的缓存大小,然后在“使用临时 OS 磁盘”中选择“是”即可。 Just make sure you select a VM size with a large enough cache size and then in Use ephemeral OS disk select Yes.

显示单选按钮的屏幕截图,该按钮选中后即可使用规模集的临时 OS 磁盘

规模集模板部署Scale set template deployment

创建一个使用临时 OS 磁盘的规模集时,其过程很简单,就是将 diffDiskSettings 属性添加到模板中的 Microsoft.Compute/virtualMachineScaleSets/virtualMachineProfile 资源类型。The process to create a scale set that uses an ephemeral OS disk is to add the diffDiskSettings property to the Microsoft.Compute/virtualMachineScaleSets/virtualMachineProfile resource type in the template. 另外,对于临时 OS 磁盘,必须将缓存策略设置为 ReadOnlyAlso, the caching policy must be set to ReadOnly for the ephemeral OS disk.

{ 
  "type": "Microsoft.Compute/virtualMachineScaleSets", 
  "name": "myScaleSet", 
  "location": "China East 2", 
  "apiVersion": "2018-06-01", 
  "sku": { 
    "name": "Standard_DS2_v2", 
    "capacity": "2" 
  }, 
  "properties": { 
    "upgradePolicy": { 
      "mode": "Automatic" 
    }, 
    "virtualMachineProfile": { 
       "storageProfile": { 
        "osDisk": { 
          "diffDiskSettings": { 
                "option": "Local" 
          }, 
          "caching": "ReadOnly", 
          "createOption": "FromImage" 
        }, 
        "imageReference":  { 
          "publisher": "Canonical", 
          "offer": "UbuntuServer", 
          "sku": "16.04-LTS", 
          "version": "latest" 
        } 
      }, 
      "osProfile": { 
        "computerNamePrefix": "myvmss", 
        "adminUsername": "azureuser", 
        "adminPassword": "P@ssw0rd!" 
      } 
    } 
  } 
}  

VM 模板部署VM template deployment

可以通过模板部署使用临时 OS 磁盘的 VM。You can deploy a VM with an ephemeral OS disk using a template. 创建一个使用临时 OS 磁盘的 VM 时,其过程很简单,就是将 diffDiskSettings 属性添加到模板中的 Microsoft.Compute/virtualMachines 资源类型。The process to create a VM that uses ephemeral OS disks is to add the diffDiskSettings property to the Microsoft.Compute/virtualMachines resource type in the template. 另外,对于临时 OS 磁盘,必须将缓存策略设置为 ReadOnlyAlso, the caching policy must be set to ReadOnly for the ephemeral OS disk.

{ 
  "type": "Microsoft.Compute/virtualMachines", 
  "name": "myVirtualMachine", 
  "location": "China East 2", 
  "apiVersion": "2018-06-01", 
  "properties": { 
       "storageProfile": { 
            "osDisk": { 
              "diffDiskSettings": { 
                "option": "Local" 
              }, 
              "caching": "ReadOnly", 
              "createOption": "FromImage" 
            }, 
            "imageReference": { 
                "publisher": "MicrosoftWindowsServer", 
                "offer": "WindowsServer", 
                "sku": "2016-Datacenter-smalldisk", 
                "version": "latest" 
            }, 
            "hardwareProfile": { 
                 "vmSize": "Standard_DS2_v2" 
             } 
      }, 
      "osProfile": { 
        "computerNamePrefix": "myvirtualmachine", 
        "adminUsername": "azureuser", 
        "adminPassword": "P@ssw0rd!" 
      } 
    } 
 } 

使用 REST 重置 VM 映像Reimage a VM using REST

可以通过 REST API 重置使用临时 OS 磁盘的虚拟机实例的映像,详见下面的说明,只需通过 Azure 门户转到 VM 的“概览”窗格即可。You can reimage a Virtual Machine instance with ephemeral OS disk using REST API as described below and via Azure Portal by going to Overview pane of the VM. 对于规模集,已经可以通过 Powershell、CLI 和门户来重置映像。For scale sets, reimaging is already available through Powershell, CLI, and the portal.

POST https://management.chinacloudapi.cn/subscriptions/{sub-
id}/resourceGroups/{rgName}/providers/Microsoft.Compute/VirtualMachines/{vmName}/reimage?a pi-version=2018-06-01" 

常见问题Frequently asked questions

问:本地 OS 磁盘的大小是多少?Q: What is the size of the local OS Disks?

A:我们支持的平台和自定义映像的大小上限取决于 VM 缓存大小,其中的 OS 磁盘的所有读取/写入操作都将在本地进行,使用与虚拟机相同的节点。A: We support platform and custom images, up to the VM cache size, where all read/writes to the OS disk will be local on the same node as the Virtual Machine.

问:可以重设临时 OS 磁盘的大小吗?Q: Can the ephemeral OS disk be resized?

A:不可以。预配临时 OS 磁盘以后,就不能重设其大小。A: No, once the ephemeral OS disk is provisioned, the OS disk cannot be resized.

问:是否可以将托管磁盘附加到临时 VM?Q: Can I attach a Managed Disks to an Ephemeral VM?

A:是的,可以将托管数据磁盘附加到使用临时 OS 磁盘的 VM。A: Yes, you can attach a managed data disk to a VM that uses an ephemeral OS disk.

问:临时 OS 磁盘是否支持所有 VM 大小?Q: Will all VM sizes be supported for ephemeral OS disks?

A:否。支持除 B 系列、N 系列和 H 系列大小之外的所有高级存储 VM 大小(DS、ES、FS 和 M)。A: No, all Premium Storage VM sizes are supported (DS, ES, FS and M) except the B-series, N-series, and H-series sizes.

问:是否可以对现有的 VM 和规模集应用临时 OS 磁盘?Q: Can the ephemeral OS disk be applied to existing VMs and scale sets?

A:否。只能在 VM 和规模集创建期间使用临时 OS 磁盘。A: No, ephemeral OS disk can only be used during VM and scale set creation.

问:是否可以在规模集中混合使用临时 OS 磁盘和常规 OS 磁盘?Q: Can you mix ephemeral and normal OS disks in a scale set?

A:否。不能在同一规模集中混合使用临时 OS 磁盘实例和持久 OS 磁盘实例。A: No, you can't have a mix of ephemeral and persistent OS disk instances within the same scale set.

问:是否可以通过 Powershell 或 CLI 创建临时 OS 磁盘?Q: Can the ephemeral OS disk be created using Powershell or CLI?

A:是的,可以通过 REST、模板、PowerShell 或 CLI 创建使用临时 OS 磁盘的 VM。A: Yes, you can create VMs with Ephemeral OS Disk using REST, Templates, PowerShell and CLI.

问:临时 OS 磁盘不支持哪些功能?Q: What features are not supported with ephemeral OS disk?

A:临时磁盘不支持:A: Ephemeral disks do not support:

  • 捕获 VM 映像Capturing VM images
  • 磁盘快照Disk snapshots
  • Azure 磁盘加密Azure Disk Encryption
  • Azure 备份Azure Backup
  • Azure Site RecoveryAzure Site Recovery
  • OS 磁盘交换OS Disk Swap

后续步骤Next steps

可以使用 Azure CLI 创建具有临时 OS 磁盘的 VM。You can create a VM with an ephemeral OS disk using the Azure CLI.