• No results found

Creating images and disks from a virtual hard disk

In document Oops, page not found. (Page 112-116)

A virtual hard disk ile must have a disk or image associated in Azure in order for it to be mounted to an Azure virtual machine. When you create a virtual machine, an image, or create a data disk on an existing virtual machine, this association is created for you automatically. You can view the existing disks and custom images in your subscription using Windows PowerShell or the current management portal (http://manage.windowsazure.com).

Objective 2.2: Implement images and disks CHAPTER 2 93 FIGURE 2-20 Viewing the available custom images in the management portal

You have already seen how to use the Get-AzureVMImage and Get-AzureDisk cmdlets to view existing images and disks associated in your subscription in Objective 2.1. To associate an existing virtual hard disk (.vhd) ile as an operating system disk using the management portal, click the Create button at the bottom of the page on the Disks tab. The dialog box that opens allows you to browse to the virtual hard disk ile and select the next to The VHD Contains An Operating System check box, as shown in Figure 2-21. To associate a data disk, the same dialog box is used, but you do not select the check box.

FIGURE 2-21 Associating a virtual hard disk with an operating system disk using the management portal

To associate a virtual hard disk (.vhd) ile as a disk (not an image) in Azure using Windows PowerShell, use the Add-AzureDisk cmdlet. The Add-AzureDisk cmdlet requires the DiskName, MediaLocation, and Label parameters, and optionally the OS parameter. If you are registering a disk with an operating system, specify Windows or Linux as the value for the OS parameter.

In the following example, the Add-AzureDisk cmdlet registers the disk named MyOSDisk with the underlying virtual hard disk ile in the container named Uploads, within the storage account speciied in the $storage variable.

$storage = "[storage account name]"

$storagePath = "https://$storage.blob.core.windows.net/uploads/myosdisk.vhd"

94 CHAPTER 2 Implement virtual machines

$diskName = "MyOSDisk"

$label = "MyOSDisk"

Add-AzureDisk -DiskName $diskName -Label $label -MediaLocation $storagePath -OS Windows

When the call to Add-AzureDisk completes, a virtual machine can be created by passing the

$diskName variable to the DiskName parameter of New-AzureVMConig instead of ImageName.

If the virtual hard disk ile only has data on it, you would create it using the same tech-nique except omitting the OS parameter as the following example demonstrates.

$storage = "[storage account name]"

$storagePath = "https://$storage.blob.core.windows.net/uploads/mydatadisk.vhd"

$diskName = "MyDataDisk"

$label = "MyDataDisk"

Add-AzureDisk -DiskName $diskName -Label $label -MediaLocation $storagePath

Registering a virtual hard disk ile as an image is a similar process. Using the manage-ment portal, browse to the virtual hard disk in the Azure Storage account, specify the name, description, and operating system type. If you are creating a Windows image and you ran Sysprep on the virtual machine, select the I Have Run Sysprep On The Virtual Machine check box. This will create a generalized image. To create a specialized image, do not select the check box.

FIGURE 2-22 Associating a virtual hard disk with an operating system image using the management portal

A signiicant difference between creating images based on Windows or Linux, is that Linux images are required to have the Azure Agent installed prior to associating the virtual hard disk ile with an image. The Agent can be installed using the yum or rpm package managers, or manually from https://github.com/Azure/WALinuxAgent. Associating a Linux-based image with a virtual hard disk is the same process as Windows except in the management portal

Objective 2.2: Implement images and disks CHAPTER 2 95 the check box will say I Have Ran Waagent -Deprovision On The Virtual Machine, instead of

mentioning Sysprep.

To accomplish the same task using Windows PowerShell, as shown in Figure 2-22, use the Add-AzureVMImage cmdlet. The minimum parameters that are required are the ImageName, MediaLocation, and the OS parameter, as shown in the following example.

$storage = "[storage account name]"

$storagePath = https://$storage.blob.core.windows.net/uploads/myosimage.vhd

$imageName = "MyGeneralizedImage"

$label = "MyGeneralizedImage"

Add-AzureVMImage -ImageName $imageName ` -MediaLocation $storagePath ` -OS Windows

The Add-AzureVMImage cmdlet supports several optional parameters to help describe the image. Many of these properties are used by the platform images but are available for your own custom images if you want to use them.

TABLE 2-5 Capabilities for virtual machine creation using the Azure PowerShell cmdlets

EULA Optional end user license agreement text

ImageFamily Optional value that can be used for grouping images into an image family.

Label Optional label for the image.

PrivacyUri Optional URI to a page that describes privacy policy.

PublishedDate The date the image was published.

RecommendedVMSize The recommended size of the virtual machine for this speciic image. When this is set the management portal will automatically set this value as the default size when creating a virtual machine from the image.

Here is an example of creating an image using all of the optional parameters when creat-ing a new image from an existcreat-ing virtual hard disk.

$storage = "[storage account name]"

$storage = "examref1"

96 CHAPTER 2 Implement virtual machines EXAM TIP

There are two Azure PowerShell cmdlets for creating a virtual machine image. The Save-AzureVMImage cmdlet creates an image from an existing virtual machine and supports both Generalized and Specialized image types. The Add-AzureVMImage cmdlet creates an image from an existing virtual hard disk ile (operating system disk only) and only supports generalized images.

In document Oops, page not found. (Page 112-116)