Azure Managed Disk对原有的Page Blob进行了一次封装。使得Azure VM的Disk操作变得非常简单。本文将介绍实际操作中针对Manage Disk的一些操作。

一、创建Manage Disk

Manage Disk的创建,可以创建空磁盘,也可以从其他源创建Disk。

1 创建空磁盘

root@hw-surfacebook:~# az disk create -g hwtest -n hwempty01 --size-gb  --sku Standard_LRS
{\ Finished ..
"accountType": "Standard_LRS",
"creationData": {
"createOption": "Empty",
"imageReference": null,
"sourceResourceId": null,
"sourceUri": null,
"storageAccountId": null
},
"diskSizeGb": ,
"encryptionSettings": null,
"id": "/subscriptions/xxxx/resourceGroups/hwtest/providers/Microsoft.Compute/disks/hwempty01",
"location": "chinanorth",
"name": "hwempty01",
"osType": null,
"ownerId": null,
"provisioningState": "Succeeded",
"resourceGroup": "hwtest",
"tags": {},
"timeCreated": "2017-07-12T09:39:57.982040+00:00",
"type": "Microsoft.Compute/disks"
}

2 从其他源创建磁盘

可以通过存储账户中Page Blob创建Disk:

root@hw-surfacebook:~# az disk create -g hwfdsk -n hwmd01 --source https://h2portalvhdsn6t2ktgjscst.blob.core.chinacloudapi.cn/vhds/hwfdsk-hwfdsk-2017-06-23.vhd
{/ Finished ..
"accountType": "Premium_LRS",
"creationData": {
"createOption": "Import",
"imageReference": null,
"sourceResourceId": null,
"sourceUri": "https://h2portalvhdsn6t2ktgjscst.blob.core.chinacloudapi.cn/vhds/hwfdsk-hwfdsk-2017-06-23.vhd",
"storageAccountId": null
},
"diskSizeGb": null,
"encryptionSettings": null,
"id": "/subscriptions/xxxx/resourceGroups/hwfdsk/providers/Microsoft.Compute/disks/hwmd01",
"location": "chinanorth",
"name": "hwmd01",
"osType": null,
"ownerId": null,
"provisioningState": "Succeeded",
"resourceGroup": "hwfdsk",
"tags": {},
"timeCreated": "2017-06-23T14:52:46.629909+00:00",
"type": "Microsoft.Compute/disks"
}

二 复制Disk

Managed Disk的复制就是用Create的命令来实现的:

root@hw-surfacebook:~# az disk create -g hwtest -n mydisk03 --source mydisk02
{\ Finished ..
"accountType": "Premium_LRS",
"creationData": {
"createOption": "Copy",
"imageReference": null,
"sourceResourceId": null,
"sourceUri": "/subscriptions/xxxx/resourceGroups/hwtest/providers/Microsoft.Compute/disks/mydisk02",
"storageAccountId": null
},
"diskSizeGb": ,
"encryptionSettings": null,
"id": "/subscriptions/xxxx/resourceGroups/hwtest/providers/Microsoft.Compute/disks/mydisk03",
"location": "chinanorth",
"name": "mydisk03",
"osType": null,
"ownerId": null,
"provisioningState": "Succeeded",
"resourceGroup": "hwtest",
"tags": {},
"timeCreated": "2017-07-12T09:48:33.620377+00:00",
"type": "Microsoft.Compute/disks"
}

命令是把mydisk02复制到mydisk03。一般情况下,不指定managed disk的sku,都是Premium_LRS的。

3 跨Resource Group创建managed Disk:

root@hw-surfacebook:~# az disk create -g hwtest -n mydisk04 --source /subscriptions/xxxx/resourceGroups/HWFDSK/providers/Microsoft.Compute/disks/hwmd01
{/ Finished ..
"accountType": "Premium_LRS",
"creationData": {
"createOption": "Copy",
"imageReference": null,
"sourceResourceId": null,
"sourceUri": "/subscriptions/xxxx/resourceGroups/HWFDSK/providers/Microsoft.Compute/disks/hwmd01",
"storageAccountId": null
},
"diskSizeGb": ,
"encryptionSettings": null,
"id": "/subscriptions/xxxx/resourceGroups/hwtest/providers/Microsoft.Compute/disks/mydisk04",
"location": "chinanorth",
"name": "mydisk04",
"osType": null,
"ownerId": null,
"provisioningState": "Succeeded",
"resourceGroup": "hwtest",
"tags": {},
"timeCreated": "2017-07-12T10:01:17.520376+00:00",
"type": "Microsoft.Compute/disks"
}

三 下载Managed Disk

如果想把Managed Disk下载下来,需要通过开放managed Disk的SAS访问权限。具体命令如下:

root@hw-surfacebook:~# az disk grant-access -g hwtest -n mydisk03 --duration-in-seconds
{/ Finished ..
"accessSas": "https://md-xplvtgf1jcgg.blob.core.chinacloudapi.cn/ttq410wsfkk5/abcd?sv=2016-05-31&sr=b&si=31fc2e57-dcd6-4cf1-ba2a-33fb44d560a4&sig=j2JwhG8Gx51sVwOdm%2BNIPEOfTAWiZsoW82XpEjTcAHA%3D"
}
这种情况下,已经Attach到VM的Disk是不能开机的。如果开放了SAS的访问权限,又需要开机,需要把这个权限取消掉。具体命令如下:
root@hw-surfacebook:~# az disk revoke-access -g hwtest -n mydisk03
{/ Finished ..
"endTime": "2017-07-12T09:56:37.555156+00:00",
"error": null,
"name": "acdf95b5-d658-4a17-b680-31f48c8b8927",
"startTime": "2017-07-12T09:56:37.336370+00:00",
"status": "Succeeded"
}

四 更改managed Disk的sku

前面提到过,managed disk在不指定sku的情况下,默认都是SSD的。如果需要转换成HDD的Disk,命令如下:

root@hw-surfacebook:~# az disk update -g hwtest -n mydisk03 --sku Standard_LRS
{
"accountType": "Standard_LRS",
"creationData": {
"createOption": "Copy",
"imageReference": null,
"sourceResourceId": null,
"sourceUri": "/subscriptions/xxxx/resourceGroups/hwtest/providers/Microsoft.Compute/disks/mydisk02",
"storageAccountId": null
},
"diskSizeGb": ,
"encryptionSettings": null,
"id": "/subscriptions/xxxx/resourceGroups/hwtest/providers/Microsoft.Compute/disks/mydisk03",
"location": "chinanorth",
"name": "mydisk03",
"osType": null,
"ownerId": null,
"provisioningState": "Succeeded",
"resourceGroup": "hwtest",
"tags": {},
"timeCreated": "2017-07-12T09:48:33.620377+00:00",
"type": "Microsoft.Compute/disks"
}

或者在创建的时候就指定SKU:

root@hw-surfacebook:~# az disk create -g hwtest -n mydisk05 --source mydisk04 --sku Standard_LRS
{/ Finished ..
"accountType": "Standard_LRS",
"creationData": {
"createOption": "Copy",
"imageReference": null,
"sourceResourceId": null,
"sourceUri": "/subscriptions/xxxx/resourceGroups/hwtest/providers/Microsoft.Compute/disks/mydisk04",
"storageAccountId": null
},
"diskSizeGb": ,
"encryptionSettings": null,
"id": "/subscriptions/xxxx/resourceGroups/hwtest/providers/Microsoft.Compute/disks/mydisk05",
"location": "chinanorth",
"name": "mydisk05",
"osType": null,
"ownerId": null,
"provisioningState": "Succeeded",
"resourceGroup": "hwtest",
"tags": {},
"timeCreated": "2017-07-12T10:03:20.170081+00:00",
"type": "Microsoft.Compute/disks"
}

五 对managed disk做snapshot

root@hw-surfacebook:~# az snapshot create -g hwtest -n hwsnapshot01 --source mydisk01
{/ Finished ..
"accountType": "Standard_LRS",
"creationData": {
"createOption": "Copy",
"imageReference": null,
"sourceResourceId": null,
"sourceUri": "/subscriptions/xxxx/resourceGroups/hwtest/providers/Microsoft.Compute/disks/mydisk01",
"storageAccountId": null
},
"diskSizeGb": ,
"encryptionSettings": null,
"id": "/subscriptions/xxxx/resourceGroups/hwtest/providers/Microsoft.Compute/snapshots/hwsnapshot01",
"location": "chinanorth",
"name": "hwsnapshot01",
"osType": null,
"ownerId": null,
"provisioningState": "Succeeded",
"resourceGroup": "hwtest",
"tags": {},
"timeCreated": "2017-07-13T05:31:54.692171+00:00",
"type": "Microsoft.Compute/snapshots"
}

从Snapshot创建Disk:

root@hw-surfacebook:~# az disk create -g hwtest -n mydisk06 --source hwsnapshot01
{- Finished ..
"accountType": "Premium_LRS",
"creationData": {
"createOption": "Copy",
"imageReference": null,
"sourceResourceId": null,
"sourceUri": "/subscriptions/xxxx/resourceGroups/hwtest/providers/Microsoft.Compute/snapshots/hwsnapshot01",
"storageAccountId": null
},
"diskSizeGb": ,
"encryptionSettings": null,
"id": "/subscriptions/xxxx/resourceGroups/hwtest/providers/Microsoft.Compute/disks/mydisk06",
"location": "chinanorth",
"name": "mydisk06",
"osType": null,
"ownerId": null,
"provisioningState": "Succeeded",
"resourceGroup": "hwtest",
"tags": {},
"timeCreated": "2017-07-13T05:33:57.468651+00:00",
"type": "Microsoft.Compute/disks"
}

五 用已有的managed disk创建VM

有了managed disk,创建VM就非常简单了,用Azure Cli创建的命令如下:

root@hw-surfacebook:~# az vm create -g hwtest -n hwtest06 --attach-os-disk mydisk06 --vnet-name hwtest --subnet Subnet- --os-type Linux
{- Finished ..
"fqdns": "",
"id": "/subscriptions/xxxx/resourceGroups/hwtest/providers/Microsoft.Compute/virtualMachines/hwtest06",
"location": "chinanorth",
"macAddress": "00-17-FA-00-C7-FA",
"powerState": "VM running",
"privateIpAddress": "10.3.0.5",
"publicIpAddress": "139.219.104.221",
"resourceGroup": "hwtest"
}

总结:

有了managed Disk,很多针对VM Disk的操作变得简单很多。

最新文章

  1. 通过rpc访问比特币核心钱包
  2. 各种排序学习归纳总结(Java)
  3. Python TCP服务器
  4. DCMTK3.6.1(MD支持库)安装说明
  5. Cpk
  6. Java实现八皇后
  7. 转:C语言申请内存时堆栈大小限制
  8. windowsxp系统下SVN添加新用户
  9. PXE+kickstart网络安装CentOS7.4系统及过程中各种报错
  10. typedef如何显示变量类型名
  11. BZOJ 3544: [ONTAK2010]Creative Accounting [set]
  12. 下拉框的change事件
  13. [struts2学习笔记] 第二节 使用Maven搞定管理和构造Struts 2 Web应用程序的七个步骤
  14. java.text.DateFormat 线程不安全问题
  15. 递归实现列出当前工程下所有.Java文件
  16. vue.js响应式原理解析与实现
  17. 2017-2018-2 20155314《网络对抗技术》Exp3 免杀原理与实践
  18. 按钮JButton,单选按钮JRadioButton,复选框JCheckBox
  19. python 版本升级
  20. free 释放内存

热门文章

  1. list— 把数组中的值赋给一组变量
  2. 20145231《Java程序设计》课程总结
  3. 深入理解JVM1
  4. 斯坦福机器学习视频笔记 Week9 异常检测和高斯混合模型 Anomaly Detection
  5. 在Java项目中部署使用Memcached[转]
  6. 出现GC overhead limit exceeded 的解决方案
  7. 【转】java中静态方法和非静态方法的存储
  8. write.table函数语法:
  9. 绑定自己Self
  10. The import java.util cannot be resolved