如何通过脚本或命令创建不带OS磁盘的Azure虚拟机
如何创建不带OS磁盘的Azure虚拟机
可以通过Azure CLI或ARM模板直接创建不带OS磁盘的Azure虚拟机,以下是具体操作方法:
Azure CLI 方法
- 先创建资源组(若已有可用资源组可跳过此步骤):
az group create --name myResourceGroup --location eastus - 创建不带OS磁盘的虚拟机,可同时附加空数据磁盘:
说明:az vm create --resource-group myResourceGroup --name myVM --size Standard_DS1_v2 --os-type none --attach-data-disks myDataDisk --data-disk-sizes-gb 100--os-type none参数用于指定不创建OS磁盘,--attach-data-disks和--data-disk-sizes-gb用于附加指定大小的空数据磁盘。
ARM 模板方法
编写如下ARM模板(保存为 vm-no-osdisk.json),模板中仅定义数据磁盘,不包含OS磁盘配置:
{ "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "resources": [ { "type": "Microsoft.Compute/virtualMachines", "apiVersion": "2023-03-01", "name": "myVM", "location": "[resourceGroup().location]", "properties": { "hardwareProfile": { "vmSize": "Standard_DS1_v2" }, "storageProfile": { "dataDisks": [ { "name": "myDataDisk", "diskSizeGB": 100, "lun": 0, "createOption": "Empty" } ] }, "networkProfile": { "networkInterfaces": [ { "id": "[resourceId('Microsoft.Network/networkInterfaces', 'myNIC')]" } ] }, "osProfile": { "computerName": "myVM", "adminUsername": "azureuser", "adminPassword": "P@ssw0rd123!" } } }, { "type": "Microsoft.Network/networkInterfaces", "apiVersion": "2023-04-01", "name": "myNIC", "location": "[resourceGroup().location]", "properties": { "ipConfigurations": [ { "name": "ipconfig1", "properties": { "subnet": { "id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', 'myVNet', 'default')]" }, "privateIPAllocationMethod": "Dynamic" } } ] } }, { "type": "Microsoft.Network/virtualNetworks", "apiVersion": "2023-04-01", "name": "myVNet", "location": "[resourceGroup().location]", "properties": { "addressSpace": { "addressPrefixes": [ "10.0.0.0/16" ] }, "subnets": [ { "name": "default", "properties": { "addressPrefix": "10.0.0.0/24" } } ] } } ] }
使用Azure CLI部署模板:
az deployment group create --resource-group myResourceGroup --template-file vm-no-osdisk.json
注意事项
- 不带OS磁盘的虚拟机无法直接启动,因为缺少操作系统。这类VM通常用于特殊场景,比如后续手动附加自定义OS磁盘,或作为纯数据存储节点使用。
内容的提问来源于stack exchange,提问作者Rasool
相关产品推荐
相关产品推荐

