首页 技术 正文
技术 2022年11月21日
0 收藏 589 点赞 4,967 浏览 2821 个字

One of the great features of Windows Azure is VHD mobility. Simply put it means you can upload and download VHDs to and from the cloud.


Note: If you are used to using CSUpload.exe for uploading VHDs you should switch to PowerShell. CSUpload.exe has been marked as deprecated and will likely not ship in future SDKs.

Technical Notes

A few things to point out while I’m here. Currently, Windows Azure only supports the VHD file format in a fixed disk format.
That being said the Add-AzureVHD cmdlet supports converting a dynamic VHD on upload to a fixed VHD so you do not have to worry about converting them up front.

Also, both the Add-AzureVHD and Save-AzureVHD cmdlets have intrinsic knowledge of the VHD file format and during upload or download only copy the written bytes and skip the empty. This is a huge optimization!

So let’s jump right in using PowerShell. This page assumes your PowerShell client is already setup to access your Windows Azure subscription. If this is not the case read through the Getting Started with Windows Azure PowerShell Cmdlets first.

Uploading a VHD

import-module azure
select-azuresubscription "mysubscriptionname"
 
$sourceVHD = "D:\StorageDemos\myvhd.vhd"
$destinationVHD = "https://mwwestus1.blob.core.windows.net/uploads/myvhd.vhd"
 
Add-AzureVhd -LocalFilePath $sourceVHD -Destination $destinationVHD `
-NumberOfUploaderThreads 5

As you can see the code to upload a VHD to your Windows Azure Storage Account is pretty simple.

To make the VHD usable you need to register it with Windows Azure.

Register VHD as a Data Disk

# Register as a plan old data disk
Add-AzureDisk -DiskName 'mydatadisk' -MediaLocation $destinationVHD `
-Label 'mydatadisk'

When the code above is run the uploaded VHD will be registered in Windows Azure as a data disk named ‘mydatadisk’. Refresh the portal and you will see it in the Disks list and it will also be available for attaching to a virtual machine.

If you are uploading a VHD with an operating system on it you need to tell that to Windows Azure.

Register VHD as an OS Disk

This code registers the disk as bootable. Meaning you can now create a virtual machine and specify this disk as the boot disk.

# Register as a plan old data disk
Add-AzureDisk -DiskName 'myosdisk' -MediaLocation $destinationVHD `
-Label 'myosdisk' -OS Windows # or Linux

Creating a VM from uploaded VHDs

As I mentioned above you can specify a disk to boot from instead of provisioning from an image. The PowerShell code to do so is simple. You can of course add disks and endpoints in between New-AzureVMConfig and New-AzureVM as well.

New-AzureVMConfig -DiskName 'myosdisk' -Name 'myvm1' -InstanceSize Small |
Add-AzureDataDisk -Import -DiskName 'mydatadisk' -LUN 0 |
New-AzureVM -ServiceName 'mycloudsvc' -Location 'West US'

Now that you have seen how to upload VHD’s to the cloud let’s walk through the equally simple download process.

Downloading a VHD from Windows Azure

The same pattern as Add-AzureVHD just reversed!

select-azuresubscription "mysubscriptionname"
 
$sourceVHD = "https://mwwestus1.blob.core.windows.net/uploads/mydatadisk.vhd"
$destinationVHD = "D:\StorageDemos\mydatadisk-downloaded.vhd"
 
Save-AzureVhd -Source $sourceVHD -LocalFilePath $destinationVHD `
-NumberOfThreads 5

That’s it! Uploading and downloading VHDs to Windows Azure is fast and simple.

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,103
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,579
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,427
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,199
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,834
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,917