In this exercise, you prepare the base image that you will deploy to Windows Azure.
In Hyper-V Server, you create a new virtual machine and perform a default installation of Windows Server 2008 R2. After booting the virtual machine, you log in, install and configure the required OS features, and then install the Windows Azure VM Role Integration Components. In a more realistic scenario, at this point, you would typically install additional software.
Once you have installed and configured all the required software, you apply the System Preparation Tool (sysprep.exe) to generalize the image, shut it down, and then you upload it to Windows Azure.
Next, you create a service model and configure it to use the deployed image, generate a service package, and then deploy it to your subscription using the Windows Azure Management Portal.
Task 1 – Building a Base Virtual Machine Image
In this task, you create a virtual machine in Hyper-V to build a base image of Windows Server 2008 R2.
- Open Hyper-V Manager in the Start menu and connect to your Hyper-V Server.
Hyper-V Manager console
- In Hyper-V Manager, right-click the server name, point to New, and then select Virtual Machine. Click Next at the welcome screen to start the New Virtual Machine Wizard.
Creating a new virtual machine to prepare an image
- In the Specify Name and Location step, set the name to VM Role and then click Next.
Choosing the name of the new virtual machine
- In the Assign Memory step, set the amount of memory to 2048 MB and then click Next.
Configuring the amount memory assigned to the virtual machine
- Next, in the Configure Networking step, select Local Area Connection – Virtual Network and then click Next.
Configuring networking options for the virtual machine
Note:The network connection will be used by the virtual machine to access Windows Update and apply required updates.
- Now, in the Connect Virtual Disk step, select the option labeled Create a virtual hard disk. Set the Name of the disk to baseimage.vhd, change the location to a suitable folder in your Hyper-V server, set the disk Size to 30GB, and then click Next to continue.
Creating a new virtual hard disk
Note:The VHD size must fit the quota allocated for the chosen VM size for you role. In this case, setting the size to 30GB allows you to deploy the VM in a “small” role.
If you already have a VHD file with a clean installation of Windows Server 2008 R2, you may use that instead. To do this, select the option labeled Use an existing virtual hard disk and browse to the location of the VHD file. Note that the image file must contain a single partition with the OS installation and must not include a recovery partition.
Note:If you use an existing image, after you create the virtual machine, you may skip the OS installation section of this task and proceed to the next task.
Using an existing virtual hard disk
- In the Installation Options step, choose the option that is the most suitable for the type of setup media that you have, and then click Next.
Installing an operating system from the setup media
Note:To create a base image for the Virtual Machine Role, you require setup media for Windows Server 2008 R2 Enterprise Edition. Click here to download trial software.
Completing the Virtual Machine Wizard
- Click Finish to create the virtual machine.
- In Hyper-V Manager, in the results pane, under Virtual Machines, right-click the name of the newly created virtual machine and then select Connect.
Note:If Hyper-V manager does not list the virtual machine, you may need to right-click the server name and select Refresh.
- In the toolbar of the Virtual Machine Connection window, click the Start icon.
Starting the virtual machine in Hyper-V
Note:Virtual Machine Connection is a tool that you use to connect to a virtual machine so that you can install or interact with the guest operating system.
- Start the virtual machine to launch the Windows Server 2008 R2 installation procedure.
Note:If the installation does not start automatically, you may have specified an incorrect location of the setup media for Windows Server 2008 R2 in the Installation Options page of the New Virtual Machine wizard.
- Install Windows Server 2008 R2 Enterprise edition using default settings. The only special requirement for a valid VM Role image is to allocate the entire virtual hard disk file to a single partition where you install the operating system. To avoid creating a recovery partition during the installation, follow these steps:
- Choose the Custom (advanced) installation type to select the partition where you will install Windows.
- Press Shift + F10 to open a command prompt during GUI-mode setup.
- At the command prompt, enter the following commands:
diskpart select disk 0 create partition primary exit
- Close the command prompt window.
- Install Windows in the newly created partition.
Task 2 – Preparing the Base Image for Deployment
Typically, VM roles are best suited for deploying legacy systems that involve complex installation and configuration procedures or for those applications whose setup you cannot script; otherwise, a web or worker role together with start-up tasks typically provide a simpler solution and the benefit of lower management requirements. For the scope of this lab, because the objective is simply to confirm that you can deploy and start a VM Role image successfully, you will enable the Web Server role in your virtual machine. Note, however, that a web role with full-IIS support provides equivalent functionality and that you would not normally use a VM role for this purpose.
In this task, you prepare the image containing a default installation of Windows Server 2008 R2 Enterprise that you created in the previous task by installing the components required for deployment to Windows Azure.
- If necessary, in Hyper-V Manager, open a new Virtual Machine Connection window, and sign-in to the virtual machine that you created previously.
- In the guest operating system, if not already open, start Server Manager from All Programs | Administrative Tools.
- Select the Roles node and then click Add Roles.
Adding a new server role
- In the Server Roles step, select the Web Server (IIS) role in the list and click Next.
Installing the Web Server role
- In the Web Server (IIS) step, click Next.
Web Server (IIS) step
- In the Role Services step, click Next without selecting any additional components.
Configuring Web Server role components
- In the Confimation step, ensure that the Web Server role is included in the list of services and then click Install.
Confirming the installation selections
- Wait for the installation to complete and then click Close.
Successful installation of the Web Server role
- Next, in Server Manager, select the Features node and then click Add Features.
Installing additional features
- In the Features step, expand .NET Framework 3.5.1 Features, select.NET Framework 3.5.1 and then click Next.
Installing the .NET Framework prerequisite
Note:The VM Role Integration Components require .NET Framework 3.5.1. You will install these components in the next task.
- In the Confirmation step, click Install.
Confirming the installation of the .NET Framework features
- In the Results step, click Close.
Successful installation of the .NET Framework feature
- Open the Windows Update control panel from Start | All Programs | Windows Update.
- In the Windows Update page, select Change Settings.
Changing Windows Update settings
- In the Change Settings page, select the option labeled Never check for updates (not recommended) and then click OK.
Disabling Windows Updates in the VM Role image
- Next, click Check for updates and install all available updates.
Installing Windows Updates before deploying the VM Image
If prompted, you may need to reboot and repeat the check for updates in case there are additional updates to install.
Task 3 – Installing the Windows Azure VM Role Integration Components
In this task, you install the Windows Azure VM Role Integration Components.
- In the Virtual Machine Connection window, in the Media menu, point to DVD Drive and then select Insert Disk. In the Open dialog, browse to the location of the ISO file for the VM Role Integration Components, wavmroleic.iso, and then click Open.
Connecting the VM Role Integration Components installation ISO file to the virtual CD/DVD drive
Note:If you have not installed the Windows Azure SDK in your Hyper-V server, you will need to copy the wavmroleic.iso file from another computer were you installed the SDK to the Hyper-V server’s hard disk. You will find this file in the iso folder of the Windows Azure SDK installation directory.
- After you connect the ISO file to the DVD drive of the virtual machine, wait for the AutoPlaydialog to appear and then click Open folder to view files using Windows Explorer.
Browsing the VM Role Integration Components ISO file
Note:If the AutoPlay feature is not enabled, open a Windows Explorer window and browse to the CD/DVD drive.
- In the Windows Explorer window, locate the WaIntegrationComponents-x64.msi (Windows Installer) file and double-click it to start the installation.
Launching the installation of the VM Role Integration Components
- At the Welcome screen, click Next to proceed.
Windows Azure VM Role Integration Components Setup Welcome screen
- In the Operating System Configuration step, enter an Administrator Password, confirm it, and then click Next.
Configuring the administrator password
- Click Install to begin the installation of the Integration Components.
Beginning the installation of the VM Role Integration Components
- When prompted to install device software, click Install to proceed.
Installing required device drivers
- Wait for the installation to complete, which should only take a few seconds.
Monitoring the progress of the installation
- Click Finish to exit the setup program.
Successful installation of the VM Role Integration Components
- Once the installation of the components has finished, you will be prompted to restart the system. Click Yes to continue.
Restarting the system to complete the installation of the integration components
- Wait for the system to restart and log in to the guest machine once again.
- Now, inside the VM, open the Start menu, type %windir%\system32\sysprep\sysprep.exe and then press Enter to launch the System Preparation Tool. Set the System Cleanup Action to“Enter System Out-of-Box Experience (OOBE)”, check the option labeled Generalize, set theShutdown Options to Shutdown, and then press OK.
Launching the System Preparation Tool
Note:The Sysprep tool (Sysprep.exe) prepares the image by cleaning up various user and machine settings and log files, as well as removing any hardware-dependent information.
- Wait for the system to completely shutdown. Your image is now ready for deployment.
Task 4 – Uploading the Disk Image to Windows Azure
In this task, you upload the VHD file to the Management Portal.
- Open a Windows Azure SDK Command Promptas an administrator from Start | All Programs | Windows Azure SDK v1.x.
- At the command prompt, execute the following command line, where:
<YOUR-SUBSCRIPTION-ID> ID of your Windows Azure subscription that you obtain from the Management Portal <YOUR- CERTIFICATE-THUMBPRINT> Thumbprint of the management certificate that you can generate in Visual Studio and upload to the Management Portal (see Appendix A: Configuring your Windows Azure Management Portal Credentials in Visual Studio – will post soon ) <PATH-TO-VHD-FILE> Path to the disk image file, baseimage.vhd,that you built in Hyper-V <HOSTED-SERVICE-LOCATION> Windows Azure data center location where the hosted service will be deployed (choose, “East Asia”, “North Central US”, “North Europe”, “South Central US”, “Southeast Asia”, “West Europe”)
Windows Azure Command Prompt
csupload Add-VMImage -Connection "SubscriptionId=<YOUR-SUBSCRIPTION-ID>; CertificateThumbprint=<YOUR-CERTIFICATE-THUMBPRINT>" -Description "Base image Windows Server 2008 R2" -LiteralPath "<PATH-TO-VHD-FILE>" -Name baseimage.vhd -Location <HOSTED-SERVICE-LOCATION>
Note:The –Connection parameter contains settings required to access and manage your subscription. If you regularly use the csupload tool, you may store this connection string in your local disk using the Set-Connection command and then execute commands without specifying the connection details each time.
- Press Enter to start execution.
- In the Windows Azure VHD Verification Tool dialog, click OK to allow the VHD to be mounted. If the AutoPlay dialog appears, close it.
Mounting the VHD for verification
Initially, the tool executes a preparation phase where it mounts the VHD file and verifies it. It then processes the file to create a smaller compressed copy. The file it generates has a .prepedextension and it stores it by default in the same folder as the original image file. To change the folder where csupload stores this file, use the –TempLocation parameter and then specify the path to the alternate location.
Preparation phase of the csupload tool
- After the preparation phase completes, the tool creates a new blob to hold the image file and then begins to upload the compressed image to your Windows Azure account.
Uploading phase of the csupload tool
Note:Base image files are typically large and, depending on the speed of your Internet connection, may take a significant amount of time to upload.
- In the Management Portal, select the Hosted Services, Storage Accounts & CDN tab, and thenVM Images. Notice that the list includes the baseimage.vhd file that you are currently uploading and that its status is shown as Pending.
Available VM Images including the image currently being uploaded
- Wait for the upload to complete, which may take several hours, if your connection is not very fast.
VM image successfully uploaded to Windows Azure
- Examine the status of the VM role image in the Management Portal and verify that it has now changed to Committed.
Image committed successfully after finishing the upload
Task 5 – Creating the Service Model
After completing the previous task, you now have a VM image deployed to your Windows Azure account. In this task, you create a service model and configure it to reference this image.
- Start Microsoft Visual Studio 2010.
- In Visual Studio, create a new Windows Azure Project. You may choose any language, Visual C# or Visual Basic, because you will only use Visual Studio to create the service model and generate the service package. Set the name of the project to MyVMRole, change the location to theSource folder of the lab, ensure that the option labeled Create directory for solution is checked, and set the solution name to Begin. Click OK to create the project.
Creating a new Windows Azure Project
- In the New Windows Azure Project dialog, click OK without adding any roles. You will create a Virtual Machine role in the following steps.
Creating a project to host the Virtual Machine Role
- Once the solution is created, right-click the Roles folder inside the MyVMRole project, point toAdd, and then select New Virtual Machine Role.
Adding a new Virtual Machine Role to the project
Note:Currently, access to VM Role is available through an invite-only beta program. If you enroll in this program, you will receive instructions for enabling the required functionality in the Windows Azure Tools for Visual Studio; otherwise, you may not see the required menu option.
- In the properties window for the new role, select the Virtual Hard Disk tab. To show the window, expand the Roles node in Solution Explorer and then double-click the VMRole1 role.
- Before you can choose an image to use for your VM role, you need to configure Visual Studio to access your Windows Azure account. If you have used Visual Studio previously to deploy service packages to Windows Azure, you may already have created the required credentials. (For instructions on how to do this, see Appendix A: Configuring your Windows Azure Management Portal Credentials in Visual Studio will post soon.)
- Once you configure the credentials, choose them in the drop down list labeled Select or create your Windows Azure account credentials. After you do this, Visual Studio accesses your subscription and retrieves a list of available virtual machine images.
- Expand the drop down list labeled Select VHD and choose the image named baseimage.vhd, which contains the installation of Window Server 2008 R2 Enterprise Edition that you uploaded earlier.
Choosing a VHD for your virtual machine role
Note:The drop down lists every VHD that you upload to your subscription.
- Configure an endpoint to allow external connections to the Web server in the VM Role. To do this, in the role properties window, switch to the Endpoints tab. Click Add Endpoint to create a new entry in the endpoints list. Set the name of the endpoint to HttpIn, select Input in the Typecolumn, http as the Protocol and type 80 for both Public Port and Private Port values.
Configuring an external endpoint for the virtual machine role
Note:In this lab, you enable the Web Server feature in the VM image to provide a simple mechanism to determine when the role starts successfully; hence the need to declare the input endpoint.
- Next, configure the Remote Desktop connections for your role. To do this, right-click theMyVMRole cloud service project in Solution Explorer and select Package. In the Package Windows Azure Application dialog box, check Enable Remote Desktop for all Roles. It will prompt the Remote Desktop Configuration dialog.
Preparing for deployment
- Expand the drop down list labeled Create or select a certificate to encrypt the user credentialsand select Create.
- In the Create Certificate dialog, enter a name to identify the certificate, for example,AzureRemote, and then click OK.
Creating a certificate for Remote Desktop connections
- Now, back in the Remote Desktop Configuration dialog, choose the newly created certificate from the drop down list, enter the name of the user that you will use to connect remotely to your role–this can be any name of your choice–enter a password and confirm it, and leave the account expiration date unchanged.
Configuring Remote Desktop settings
- Before you close the dialog, click View next to the certificate drop down list. In the Certificatedialog, switch to the Details tab and click Copy to File. Follow the wizard to export the certificate to a file, making sure that you choose the option to export the private key. Save the resulting file to a suitable location in your hard disk. You will need to upload this file to the Management Portal later, once you create a hosted service for your role.
- Click OK to close the Remote Desktop Configuration.
- Finally, create a package to deploy your virtual machine role. To do this, click Package and then wait until Visual Studio creates it. Once the package is ready, Visual Studio opens a window showing the folder that contains the generated files.
Creating a service package in Visual Studio
Task 6 – Creating the Hosted Service and Deploying the Package
In this task, you create a new hosted service for your Virtual Machine role and then deploy the service package.
- Return to the browser window showing the Management Portal.
- Create a hosted service for your virtual machine role. To do this, select the Hosted Services, Storage Accounts & CDN tab followed by Hosted Services, and then click New Hosted Serviceon the ribbon.
Creating a hosted service for your virtual machine
- In the Create a new Hosted Service dialog, enter a Service Name, for example, MyVMRole, and the URL that you wish to assign to the service. Remember that this URL is public, therefore, it needs to be unique and can only contain characters that are valid in a URL. The dialog validates the name as you type it and warns you if the name you choose has already been taken. Pick the region where you want to host the service from the drop down list labeled Choose a region and ensure that it is the same region where you uploaded the VM image in the previous task. Finally, in the Deploy pane, select the option labeled Do not deploy, and then click OK.
Configuring the hosted service
- Upload the certificate used to encrypt the Remote Desktop password to the newly created service. To do this, expand the node for your hosted service to display and select theCertificates node and then click Add Certificate on the ribbon.
Configuring service certificates
- In the Upload an X.509 Certificate dialog, click Browse and navigate to the location where you stored the certificate for Remote Desktop that you created and exported during the previous task, enter the assigned password, confirm it, and then click Create.
Uploading the Remote Desktop certificate to the service
- Once you create the service, select it in the items pane of the Management Portal page, and then click New Production Deployment on the ribbon.
Creating a new deployment for the service
- In the Create a new Deployment dialog, click Browse Locally next to the Package Location text box and then navigate to the location where Visual Studio generated the service package during the previous task. You should have a Windows Explorer window already open showing the correct location. Choose the service package file with a .cspkg extension and click Open. Repeat the same procedure to choose the Configuration File with a .cscfg extension in the same location. Finally, enter a label to identify your deployment, and click OK.
Deploying a service package for the Virtual Machine role
- Once you start the deployment, you can monitor its progress in the Management Portal’s UI. Observe the various states that the deployment undergoes as the role starts up and initializes.
Viewing the status of the hosted service
- Wait until the status of the deployment is shown as Ready.
Hosted service successful start
- To verify that the role started successfully, open the home page of your VM role in your browser. You can find its URL in the Properties window of your deployment, which corresponds to the web server (port 80) endpoint that you defined while creating the service model.
Accessing the input endpoint of the VM role
- Verify that you can access the default page in IIS, as shown in the image below.
Accessing the web server running in the VM role