You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/lab-services/how-to-enable-nested-virtualization-template-vm-using-script.md
+182-7Lines changed: 182 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: Enable nested virtualization on a template VM
3
3
titleSuffix: Azure Lab Services
4
-
description: Learn how to enable nested virtualization on a template VM in Azure Lab Services by using a script. Nested virtualization enables you to create a lab with multiple VMs inside it.
4
+
description: Learn how to enable nested virtualization on a template VM in Azure Lab Services. Nested virtualization enables you to create a lab with multiple VMs inside it.
5
5
services: lab-services
6
6
ms.service: lab-services
7
7
author: ntrogh
@@ -10,23 +10,33 @@ ms.topic: how-to
10
10
ms.date: 01/13/2023
11
11
---
12
12
13
-
# Enable nested virtualization on a template virtual machine in Azure Lab Services by using a script
13
+
# Enable nested virtualization on a template virtual machine in Azure Lab Services
14
14
15
-
Nested virtualization enables you to create a multi-VM environment inside a lab's template virtual machine. Publishing the template will provide each user in the lab with a virtual machine set up with multiple VMs within it. For more information about nested virtualization and Azure Lab Services, see [Enable nested virtualization on a template virtual machine in Azure Lab Services](how-to-enable-nested-virtualization-template-vm.md).
15
+
Nested virtualization enables you to create a multi-VM environment inside a lab's template virtual machine. Publishing the template provides each user in the lab with a VM that's set up with multiple VMs within it.
16
16
17
-
The steps in this article focus on setting up nested virtualization for Windows Server 2016, Windows Server 2019, or Windows 10. You will use a script to set up a template VM with Hyper-V. The following steps will guide you through how to use the [Lab Services Hyper-V scripts](https://github.com/Azure/LabServices/tree/main/ClassTypes/PowerShell/HyperV).
17
+
For more information about nested virtualization and Azure Lab Services, see [Nested virtualization on a template virtual machine](./concept-nested-virtualization-template-vm.md).
18
+
19
+
To enable nested virtualization on the template VM, you first connect to the VM by using a remote desktop (RDP) client. Then you can apply the configuration changes in either of two ways:
20
+
21
+
-[Enable nested virtualization by using a script](#enable-nested-virtualization-by-using-a-script).
22
+
-[Enable nested virtualization by using Windows tools](#enable-nested-virtualization-by-using-windows-tools).
18
23
19
24
>[!IMPORTANT]
20
-
>Select **Large (nested virtualization)** or **Medium (nested virtualization)** for the virtual machine size when creating the lab. Nested virtualization will not work otherwise.
25
+
>Select **Large (nested virtualization)** or **Medium (nested virtualization)** for the virtual machine size when creating the lab. Nested virtualization will not work otherwise.
21
26
22
27
## Prerequisites
23
28
24
29
- A lab plan and one or more labs. Learn how to [Set up a lab plan](tutorial-setup-lab-plan.md) and [Set up a lab](tutorial-setup-lab.md).
25
30
- Permission to edit the lab. Learn how to [Add a user to the Lab Creator role](tutorial-setup-lab-plan.md#add-a-user-to-the-lab-creator-role). For more role options, see [Lab Services built-in roles](administrator-guide.md#rbac-roles).
26
31
27
-
## Run script
32
+
## Enable nested virtualization by using a script
33
+
34
+
You can use a PowerShell script to set up nested virtualization on a template VM in Azure Lab Services. The following steps will guide you through how to use the [Lab Services Hyper-V scripts](https://github.com/Azure/LabServices/tree/main/ClassTypes/PowerShell/HyperV). The steps are intended for Windows Server 2016, Windows Server 2019, or Windows 10.
35
+
36
+
1. Follow these steps to [connect to and update the template machine](./how-to-create-manage-template.md#update-a-template-vm).
28
37
29
38
1. Launch **PowerShell** in **Administrator** mode.
39
+
30
40
1. You may have to change the execution policy to successfully run the script. Run the following command:
31
41
32
42
```powershell
@@ -42,15 +52,180 @@ The steps in this article focus on setting up nested virtualization for Windows
42
52
43
53
> [!NOTE]
44
54
> The script may require the machine to be restarted. Follow instructions from the script and re-run the script until **Script completed** is seen in the output.
55
+
45
56
1. Don't forget to reset the execution policy. Run the following command:
46
57
47
58
```powershell
48
59
Set-ExecutionPolicy default -force
49
60
```
50
61
62
+
You've now configured your template VM to use nested virtualization and create VMs inside it.
63
+
64
+
## Enable nested virtualization by using Windows tools
65
+
66
+
You can set up nested virtualization on a template VM in Azure Lab Services using Windows roles and tools directly. There are a few things needed on the template VM enable nested virtualization. The following steps describe how to manually set up a Lab Services machine template with Hyper-V. Steps are intended for Windows Server 2016 or Windows Server 2019.
67
+
68
+
First, follow these steps to [connect to the template virtual machine by using a remote desktop client](./how-to-create-manage-template.md#update-a-template-vm).
69
+
70
+
### 1. Enable the Hyper-V role
71
+
72
+
The following steps describe the actions to enable Hyper-V on Windows Server using Server Manager. After enabling Hyper-V, Hyper-V manager is available to add, modify, and delete client VMs.
73
+
74
+
1. In **Server Manager**, on the Dashboard page, select **Add Roles and Features**.
75
+
76
+
2. On the **Before you begin** page, select **Next**.
77
+
3. On the **Select installation type** page, keep the default selection of Role-based or feature-based installation and then select **Next**.
78
+
4. On the **Select destination server** page, select Select a server from the server pool. The current server will already be selected. Select Next.
79
+
5. On the **Select server roles** page, select **Hyper-V**.
80
+
6. The **Add Roles and Features Wizard** pop-up will appear. Select **Include management tools (if applicable)**. Select the **Add Features** button.
81
+
7. On the **Select server roles** page, select **Next**.
82
+
8. On the **Select features page**, select **Next**.
83
+
9. On the **Hyper-V** page, select **Next**.
84
+
10. On the **Create Virtual Switches** page, accept the defaults, and select **Next**.
85
+
11. On the **Virtual Machine Migration** page, accept the defaults, and select **Next**.
86
+
12. On the **Default Stores** page, accept the defaults, and select **Next**.
87
+
13. On the **Confirm installation selections** page, select **Restart the destination server automatically if required**.
88
+
14. When the **Add Roles and Features Wizard** pop-up appears, select **Yes**.
89
+
15. Select **Install**.
90
+
16. Wait for the **Installation progress** page to indicate that the Hyper-V role is complete. The machine may restart in the middle of the installation.
91
+
17. Select **Close**.
92
+
93
+
### 2. Enable the DHCP role
94
+
95
+
When you create a client VM, it needs an IP address in the Network Address Translation (NAT) network. You'll create the NAT network in a later step.
96
+
97
+
To assign the IP addresses automatically, configure the lab VM template as a DHCP server:
98
+
99
+
1. In **Server Manager**, on the **Dashboard** page, select **Add Roles and Features**.
100
+
2. On the **Before you begin** page, select **Next**.
101
+
3. On the **Select installation type** page, select **Role-based or feature-based installation** and then select **Next**.
102
+
4. On the **Select destination server** page, select the current server from the server pool and then select **Next**.
103
+
5. On the **Select server roles** page, select **DHCP Server**.
104
+
6. The **Add Roles and Features Wizard** pop-up will appear. Select **Include management tools (if applicable)**. Select **Add Features**.
105
+
106
+
>[!NOTE]
107
+
>You may see a validation error stating that no static IP addresses were found. This warning can be ignored for our scenario.
108
+
109
+
7. On the **Select server roles** page, select **Next**.
110
+
8. On the **Select features** page, select **Next**.
111
+
9. On the **DHCP Server** page, select **Next**.
112
+
10. On the **Confirm installation selections** page, select **Install**.
113
+
11. Wait for the **Installation progress page** to indicate that the DHCP role is complete.
114
+
12. Select Close.
115
+
116
+
### 3. Enable the Routing and Remote Access role
117
+
118
+
Next, enable the [Routing service](/windows-server/remote/remote-access/remote-access#routing-service) to enable routing network traffic between the VMs on the template VM.
119
+
120
+
1. In **Server Manager**, on the **Dashboard** page, select **Add Roles and Features**.
121
+
122
+
2. On the **Before you begin** page, select **Next**.
123
+
3. On the **Select installation type** page, select **Role-based or feature-based installation** and then select **Next**.
124
+
4. On the **Select destination server** page, select the current server from the server pool and then select **Next**.
125
+
5. On the **Select server roles** page, select **Remote Access**. Select **OK**.
126
+
6. On the **Select features** page, select **Next**.
127
+
7. On the **Remote Access** page, select **Next**.
128
+
8. On the **Role Services** page, select **Routing**.
129
+
9. The **Add Roles and Features Wizard** pop-up will appear. Select **Include management tools (if applicable)**. Select **Add Features**.
130
+
10. Select **Next**.
131
+
11. On the **Web Server Role (IIS)** page, select **Next**.
132
+
12. On the **Select role services** page, select **Next**.
133
+
13. On the **Confirm installation selections** page, select **Install**.
134
+
14. Wait for the **Installation progress** page to indicate that the Remote Access role is complete.
135
+
15. Select **Close**.
136
+
137
+
### 4. Create virtual NAT network
138
+
139
+
Now that you've installed all the necessary roles, you can create the NAT network. The creation process will involve creating a switch and the NAT network, itself.
140
+
141
+
A NAT network assigns a public IP address to a group of VMs on a private network to allow connectivity to the internet. In this case, the group of private VMs consists of the nested VMs. The NAT network allows the nested VMs to communicate with one another.
142
+
143
+
A switch is a network device that handles receiving and routing of traffic in a network.
144
+
145
+
#### Create a new virtual switch
146
+
147
+
To create a virtual switch in Hyper-V:
148
+
149
+
1. Open **Hyper-V Manager** from Windows Administrative Tools.
150
+
151
+
2. Select the current server in the left-hand navigation menu.
152
+
3. Select **Virtual Switch Manager…** from the **Actions** menu on the right-hand side of the **Hyper-V Manager**.
153
+
4. On the **Virtual Switch Manager** pop-up, select **Internal** for the type of switch to create. Select **Create Virtual Switch**.
154
+
5. For the newly created virtual switch, set the name to something memorable. For this example, we'll use 'LabServicesSwitch'. Select **OK**.
155
+
6. A new network adapter will be created. The name will be similar to 'vEthernet (LabServicesSwitch)'. To verify open the **Control Panel**, select **Network and Internet**, select **View network status and tasks**. On the left, select **Change adapter settings**.
156
+
157
+
#### Create a NAT network
158
+
159
+
To create a NAT network on the lab template VM:
160
+
161
+
1. Open the **Routing and Remote Access** tool from Windows Administrative Tools.
162
+
163
+
2. Select the local server in the left navigation page.
164
+
3. Choose **Action** -> **Configure and Enable Routing and Remote Access**.
165
+
4. When **Routing and Remote Access Server Setup Wizard** appears, select **Next**.
166
+
5. On the **Configuration** page, select **Network address translation (NAT)** configuration. Select **Next**.
167
+
168
+
>[!WARNING]
169
+
>Do not choose the 'Virtual private network (VPN) access and NAT' option.
170
+
171
+
6. On **NAT Internet Connection** page, choose 'Ethernet'. Don't choose the 'vEthernet (LabServicesSwitch)' connection we created in Hyper-V Manager. Select **Next**.
172
+
7. Select **Finish** on the last page of the wizard.
173
+
8. When the **Start the service** dialog appears, select **Start Service**.
174
+
9. Wait until service is started.
175
+
176
+
### 5. Update network adapter settings
177
+
178
+
Next, associate the IP address of the network adapter with the default gateway IP of the NAT network you created earlier. In this example, assign an IP address of 192.168.0.1, with a subnet mask of 255.255.255.0. Use the virtual switch that you created earlier.
179
+
180
+
1. Open the **Control Panel**, select **Network and Internet**, select **View network status and tasks**.
181
+
182
+
2. On the left, select **Change adapter settings**.
183
+
3. In the **Network Connections** window, double-click on 'vEthernet (LabServicesSwitch)' to show the **vEthernet (LabServicesSwitch) Status** details dialog.
184
+
4. Select the **Properties** button.
185
+
5. Select **Internet Protocol Version 4 (TCP/IPv4)** item and select the **Properties** button.
186
+
6. In the **Internet Protocol Version 4 (TCP/IPv4) Properties** dialog:
187
+
188
+
- Select **Use the following IP address**.
189
+
- For the IP address, enter 192.168.0.1.
190
+
- For the subnet mask, enter 255.255.255.0.
191
+
- Leave the default gateway and DNs servers blank.
192
+
193
+
>[!NOTE]
194
+
> The range for the NAT network will be, in CIDR notation, 192.168.0.0/24. This range provides usable IP addresses from 192.168.0.1 to 192.168.0.254. By convention, gateways have the first IP address in a subnet range.
195
+
196
+
7. Select OK.
197
+
198
+
### 6. Create DHCP Scope
199
+
200
+
Next, you can add a DHCP scope. In this case, our NAT network is 192.168.0.0/24 in CIDR notation. This range provides usable IP addresses from 192.168.0.1 to 192.168.0.254. The scope you create must be in that range of usable addresses, excluding the IP address you assigned in the previous step.
201
+
202
+
1. Open **Administrative Tools** and open the **DHCP** administrative tool.
203
+
2. In the **DHCP** tool, expand the node for the current server and select **IPv4**.
204
+
3. From the Action menu, choose **New Scope…**.
205
+
4. When the **New Scope Wizard** appears, select **Next** on the **Welcome** page.
206
+
5. On the **Scope Name** page, enter 'LabServicesDhcpScope' or something else memorable for the name. Select **Next**.
207
+
6. On the **IP Address Range** page, enter the following values.
208
+
209
+
- 192.168.0.100 for the Start IP address
210
+
- 192.168.0.200 for the End IP address
211
+
- 24 for the Length
212
+
- 255.255.255.0 for the Subnet mask
213
+
214
+
7. Select **Next**.
215
+
8. On the **Add Exclusions and Delay** page, select **Next**.
216
+
9. On the **Lease Duration** page, select **Next**.
217
+
10. On the **Configure DHCP Options** page, select **Yes, I want to configure these options now**. Select **Next**.
218
+
11. On the **Router (Default Gateway)**
219
+
12. Add 192.168.0.1, if not done already. Select **Next**.
220
+
13. On the **Domain Name and DNS Servers** page, add 168.63.129.16 as a DNS server IP address, if not done already. 168.63.129.16 is the IP address for an Azure static DNS server. Select **Next**.
221
+
14. On the **WINS Servers** page, select **Next**.
222
+
15. One the **Activate Scope** page, select **Yes, I want to activate this scope now**. Select **Next**.
223
+
16. On the **Completing the New Scope Wizard** page, select **Finish**.
224
+
225
+
51
226
## Conclusion
52
227
53
-
Now your template machine is ready to create Hyper-V virtual machines. See [Create a Virtual Machine in Hyper-V](/windows-server/virtualization/hyper-v/get-started/create-a-virtual-machine-in-hyper-v) for instructions on how to create Hyper-V virtual machines. Also, see [Microsoft Evaluation Center](https://www.microsoft.com/evalcenter/) to check out available operating systems and software.
228
+
Now your template machine is ready to create Hyper-V virtual machines. See [Create a Virtual Machine in Hyper-V](/windows-server/virtualization/hyper-v/get-started/create-a-virtual-machine-in-hyper-v) for instructions on how to create Hyper-V virtual machines. Also, see [Microsoft Evaluation Center](https://www.microsoft.com/evalcenter/) to check out available operating systems and software.
0 commit comments