【Azure】复制虚拟机--托管磁盘

在很多场景下,许多用户希望可以保留目前虚拟机的用户信息和按照信息等内容的前提下,创建出更多的虚拟机来供其或者团队使用。

目前Azure就具备这个功能---虚拟机磁盘的复制,通过这个可以实现我们企业要求的每个人都必须按照同样的登录名和密码登录虚拟机,不同的人,不同的创建习惯。

接下来我们看一下基于Azure的虚拟机磁盘复制的操作步骤。

  1. 通过Azure CLI登录你的Azure订阅

az cloud set -n AzureChinaCloud

Switched active cloud to 'AzureChinaCloud'.

Active subscription switched to 'Microsoft Azure Enterprise 试用版 (dd602a13-395b-40b6-9fca-406fcc838a7e)'.

azure login -e AzureChinaCloud -u xxxxx@xxxxxx.partner.onmschina.cn

info: Executing command login

Password: *********

info: Added subscription Microsoft Azure Enterprise 试用版

+

info: login command OK

  1. 创建需要复制的虚拟机,并进行deallocate。

az vm deallocate --resource-group myResourceGroup --name myVM

  1. 获得需要复制的虚拟机的磁盘名称

az disk list -g hostimagegroup --output table

Name ResourceGroup Location Zones Sku OsType SizeGb ProvisioningState

----------------------------------------------------- --------------- ---------- ------- ----------- -------- -------- -------------------

hostimagevm_OsDisk_1_4fb8ba111a004085918be499eba5e9a1 hostimagegroup chinanorth Premium_LRS Linux 31 Succeeded

  1. 复制操作系统盘

az disk create -g hostimagegroup -n mycopydisk --source hostimagevm_OsDisk_1_4fb8ba111a004085918be499eba5e9a1

{/ Finished ..

"creationData": {

"createOption": "Copy",

"imageReference": null,

"sourceResourceId": "/subscriptions/xxxxxxx/resourceGroups/hostimagegroup/providers/Microsoft.Compute/disks/hostimagevm_OsDisk_1_4fb8ba111a004085918be499eba5e9a1",

"sourceUri": null,

"storageAccountId": null

},

"diskSizeGb": 31,

"encryptionSettings": null,

"id": "/subscriptions/xxxxxx/resourceGroups/hostimagegroup/providers/Microsoft.Compute/disks/mycopydisk",

"location": "chinanorth",

"managedBy": null,

"name": "mycopydisk",

"osType": "Linux",

"provisioningState": "Succeeded",

"resourceGroup": "hostimagegroup",

"sku": {

"name": "Premium_LRS",

"tier": "Premium"

},

"tags": {},

"timeCreated": "2018-02-19T15:59:36.852484+00:00",

"type": "Microsoft.Compute/disks",

"zones": null

}

复制完成后查看到新的磁盘

az disk list -g hostimagegroup --output table

Name ResourceGroup Location Zones Sku OsType SizeGb ProvisioningState

----------------------------------------------------- --------------- ---------- ------- ----------- -------- -------- -------------------

hostimagevm_OsDisk_1_4fb8ba111a004085918be499eba5e9a1 hostimagegroup chinanorth Premium_LRS Linux 31 Succeeded

mycopydisk hostimagegroup chinanorth Premium_LRS Linux 31 Succeeded

  1. 创建PIP和NIC

我这里将新的虚拟机创建到源虚拟机的子网里面。

az network public-ip create --resource-group hostimagegroup --location chinanorth --name myCopyPublicIP --dns-name mycopypublicdns --allocation-method static --idle-timeout 4

az network nic create --resource-group hostimagegroup --location chinanorth --name myNic --vnet-name hostimagegroup-vnet --subnet default --public-ip-address myCopyPublicIP

  1. 创建虚拟机

az vm create -g hostimagegroup -n mycopiedvm --nics myNic --size Standard_DS1 --os-type linux --attach-os-disk mycopydisk

大功告成

原文地址:https://www.cnblogs.com/smallfox/p/8454697.html