Tải bản đầy đủ
Objective 2.2: Create and manage a VM image or virtual hard disk

Objective 2.2: Create and manage a VM image or virtual hard disk

Tải bản đầy đủ

and the administrator credentials, or can some of these settings be “generalized” or “reusable”
so that they can be changed when the VM instance is provisioned from a template?
This notion surfaces important operating system disk terminology: specialized images and
generalized images. Think of these concepts as two different scenarios in which you might
provision a VM.
In the specialized image scenario, you are interested in creating a golden copy of a VM, or
in other words, a snapshot, from which you can create exact duplicates of the VM. You might
stop the VM, capture a snapshot of it in an image, re-create that exact VM somewhere else,
and then turn on the VM again. Any time you provision an instance of the image, it maintains
the identity it had at the time of the snapshot. It is like turning on the original VM from the
point in time at which the snapshot was taken, except that any modifications you make as the
VM runs do not alter the image from which it was created.
Compare this with the generalized images scenario, where you want to turn the VM you
have created into a template from which you can stamp out new cloned instances of the VM,
each of them unique with respect to certain settings in the operating system. For example, to
scale out a cluster, you add new instances of the template VMs, each of them similarly configured but uniquely identified. In this case, each instance has its own identity and is therefore
slightly different. The instances identify themselves as “VM-A,” “VM-B,” and “VM-C” instead
of always being “VM-A.” In fact, when you create VMs from images available in the Marketplace, you utilize generalized images.
A VM created from the Marketplace consists of a set of VHDs—an operating system disk
and zero or more data disks are attached to the VM. Each of these disk VHDs were created
from an image, which is also a VHD. So what is the difference between an image and a disk?
With an understanding of the difference between specialized and generalized images, you
can consider the steps necessary to create these two forms of images.
At the highest level, if you are starting with a VM created in Azure (such as one from the
Marketplace), you follow these steps:
1. Create the source VM. Start with a VM you created from an existing image, such as

one from the Marketplace.
2. Generalize the VM. To create a generalized image, you must take specific steps to

prepare the VM before you create an image from it. You do not perform these steps to
create a specialized VM.
3. Capture the VM image. With the VM in the desired state, take a snapshot of it by

capturing a VM image.
4. Instantiate instances of the image. With an image ready, you can launch specialized

instances that act like a copy of the original, right down to operating system details like
the administrator user name and password. Generalized images start up differently as
they configure themselves to take on new identities during their first start up and can
be configured to draw their administrator user name and password from an Azureprovided configuration during startup.
98

CHAPTER 2

Create and manage virtual machines

Similarly, if you are starting with a VM created on-premises, you follow these steps:
1. Upload the source VHDs to Azure. If you created your VM on-premises, for example

using Hyper-V, upload its constituent VHD disks to Azure.
2. Create disks from the VHDs. To attach a VHD to a VM, it must be created as a disk. It

can be an operating system disk if it is to be bootable or a data disk if not.
3. Create a VM. Create a new VM by attaching the operating system disk and any data

disks.
4. Generalize the VM. To create a generalized image, you must take specific steps to

prepare the VM before you create an image from it.
5. Capture the VM image. With the VM in the desired state, take a snapshot of it by

capturing a VM image.
6. Instantiate instances of the image. With an image ready, you can launch a specialized

instance that acts like a copy of the original. Instances of generalized images start up
differently as they configure themselves to take on new identities during their first
startup.
The sections that follow focus on a scenario in which you are uploading a VM from onpremises to show the contrast with provisioning VMs from the Marketplace, as covered in the
previous objective.

Uploading VHDs to Azure
If you have a VM on-premises that you would like to upload to Azure to serve as the basis for
an image, complete the following steps:
1. Ensure that your VM meets the requirements to run on Azure. This means that it must

be running an Azure-compatible guest operating system and that the disks are stored
in the VHD format (not the expanding VHDX format).
2. Turn off the VM so you can be certain you are capturing a consistent state of the VM.
3. Open the Azure PowerShell cmdlets and make sure that your default Azure Subscription

and Storage accounts are configured as the accounts in which to deploy your VM. You
can use the following three commands to download your publish settings file to disk
using the browser, import it into the Windows PowerShell context, and set the default
Subscription and Storage accounts:
Get-AzurePublishSettingsFile
Import-AzurePublishSettingsFile “\.publishsettings”
Set-AzureSubscription “ -CurrentStorageAccountName




Objective 2.2: Create and manage a VM image or virtual hard disk

CHAPTER 2

99

4. If you prefer not to deal with the downloading, storing, and securing of the

publish settings file, you can use Azure Active Directory to authenticate. Instead
of using Get-AzurePublishSettingsFile and Import-AzurePublishSettingsFile, run
Add-AzureAccount, log in to your Azure account, and then set the default Subscription
and Storage accounts:
Add-AzureAccount
Set-AzureSubscription “ -CurrentStorageAccountName


5. Within Blob storage, ensure you have a container that will hold the uploaded VHDs,

and then run the following Windows PowerShell cmdlet to upload each VHD to that
container:
Add-AzureVhd -Destination
http://.blob.core.windows.net//Name>.vhd -LocalFilePath C:\\.vhd

6. Repeat step 5 for every VHD belonging to your VM.

Creating disks
After you have uploaded all of the VHDs that make up your VM, you can directly create a disk
from any single VHD. This section covers how to create an operating system disk or data disk
from a VHD.

Creating an operating system disk or data disk
from a VHD (existing portal)
Using a single VHD file uploaded to Blob storage, you can use the existing portal to create
either an operating system disk or a data disk.
1. Navigate to the Disks tab in the Virtual Machines area in the management portal

accessed via https://manage.windowsazure.com.
2. Click Create on the command bar.
3. In the Create A Disk From A VHD dialog box, provide a name for the new disk.
4. Click the file area under VHD URL, and select the VHD you uploaded to Azure Storage

from the list that appears.
5. Indicate that the disk you have selected contains an operating system image and that

you intend to use it as a specialized disk by selecting This VHD Contains An Operating
System. If you do so, also indicate whether the operating system is Windows or Linux
using the Operating System Family drop-down list. Otherwise, leave the check box
clear to create the disk as a data disk.
6. Click the check mark to create the disk.
100

CHAPTER 2

Create and manage virtual machines

Creating a disk from a VHD (Preview portal)
Currently, you cannot create a disk from a VHD using the Preview portal.

Creating an operating system disk or data disk from a VHD
using Windows PowerShell
You can create a disk from a VHD using Windows PowerShell by running the Add-AzureDisk
cmdlet. To create a bootable Windows operating system disk from a VHD, use the following
syntax:
Add-AzureDisk -DiskName "" -MediaLocation
"http://.blob.core.azure.com//.vhd"
-Label "