When architecting solutions in the cloud that leverage compute, it is very common to need to rapidly deploy Windows or Linux servers, which fit a specific purpose.
VM images allow you to have a Windows or Linux server, which is pre-configured with applications, software, security, and more. We can then speed up (and automate) the deployment of VMs, which are built from these images and are ready for use.
Within this lab, you’ll gain experience creating a custom VM image from a Windows virtual machine.
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- Configure a Virtual Machine with IIS
Use the Azure Portal to perform the following tasks. Please log in with the credentials provided to you for this lab.
Please be aware you will need an RDP client to connect to the Windows server. To connect to
vm1
, use the credentials provided on the lab page.Connect to VM1 Using RDP
- Navigate to the Virtual Machines services page.
- Open the existing VM called vm1.
- Click on the Connect option in the command bar, and select RDP.
- Use the RDP file with your preferred RDP client.
Note: You may choose to copy the public IP address and connect via RDP manually with your RDP client, instead of using the RDP file.
Configure a Web Server
- Click Start, Windows PowerShell, then Windows PowerShell.
- Type the command:
Install-WindowsFeature -name Web-Server -IncludeManagementTools
Create a Basic HTML Page
- Click Start, Windows PowerShell, then Windows PowerShell.
- Type the command:
ConvertTo-Html -InputObject (Get-Date) | Out-File C:inetpubwwwrootindex.html
You can test that the webserver is working by opening http://locahost in Internet Explorer. It should display the test HTML page you just created (date-time).
Remain connected to the server by RDP for the next task.
- Generalize the Windows Server
Ensure you are still connected to VM1 using RDP, as per the previous task.
Perform Sysprep
- Right-click the start menu.
- Click on Run.
- Type the following:
%WINDIR%system32sysprep
. - Click OK to open the folder.
- Double-click on the
sysprep.exe
file. - Use the following settings:
- System Cleanup Action: Enter System Out-of-Box Experience (OOBE)
- Generalize: tick the tickbox
- Shutdown Options: Shutdown
- NOTE: When you click OK, the computer will generalize and then shutdown
- Click OK.
Note: The above task can be completed in with the following command-line option if preferred:
%WINDIR%system32sysprepsysprep.exe /generalize /shutdown /oobe
.- Create an Image of the Virtual Machine
Use the Azure Portal to perform the following tasks. Please login with the credentials provided to you for this lab.
Convert VM1 to an Image
- Navigate to the Virtual Machines services page.
- Open the existing VM called vm1.
- Check that the Status is showing as stopped.
- Use the RDP file with your preferred RDP client.
- Click on the Capture option in the command menu, and use the following settings:
- Name:
vmimage1
- Resource group: leave the default selected
- Automatically delete this virtual machine: no
- Type the virtual machine name:
vm1
- Click on Create.
- Name:
Note: You will no longer be able to start vm1 after completing this step.
- Create a VM using the VM Image
Use the Azure Portal to perform the following tasks. Please login with the credentials provided to you for this lab.
Create a VM from the Image
- Navigate to the Images services page.
- Click on vmimage1, which we just created.
- Click on the + Create VM option in the command menu, and use the following settings:
- Basics
- Subscription: leave as-is
- Resource group: leave as-is
- Virtual machine name: vm2
- Region: leave as-is
- Availability options: none
- Image: leave as-is
- Size: B2s
- Administrator account: use the provided VM credentials
- Public inbound ports: none
- License Type: Windows Server
- Would you like to use an existing Windows Server license?: No
- Click on Next: Disks.
- Disks
- Leave as-is
- Click on Next: Networking
- Leave as-is
- Networking
- Virtual network: vnet1
- Subnet: subnet1
- Public IP: leave as-is
- NIC network security group: None
- Click on Review + create.
- Click on Create.
- Basics
Note: We have network security already associated with vnet1. This will allow RDP access to vm2.
Test the VM
- Connect to the VM using the steps followed earlier.
Ensure you use the new public IP address for vm2. - Once connected, you can verify the VM is created from the image by performing the following test:
- Test: Open
http://localhost
in Internet Explorer
Result: You should see the page we created earlier.
- Test: Open
The above test validates that your new server has (a) IIS configuration from vm1, and (b) the index.html file you generated on vm1.