· 6 years ago · Oct 12, 2019, 09:06 PM
1Main contentChapter Contents
26-2d
3Generation 1 and Generation 2 VMs
4When you create a VM with the New Virtual Machine Wizard or the New-VM PowerShell cmdlet, you have the option of creating a generation 1 or generation 2 VM. Generation 2 VMs are based on revised virtual hardware specifications, so they have enhanced VM capabilities and support for newer standards:
5
6Unified Extensible Firmware Interface (UEFI) firmware instead of traditional PC BIOS—Enhances the VM’s hardware environment and removes the 2.2 TB partition limit for the boot volume. Also supports PXE boot with synthetic device drivers as well as booting from a SCSI virtual disk. The guest OS must be a 64-bit OS.
7
8Device support—Removes support for legacy network adapters, IDE controllers, legacy keyboards, and floppy disk controllers. Adds support for booting from software-based devices, using virtual machine bus (VMBus), SCSI devices, and a new software-based DVD drive. Generation 2 VMs don’t support booting from a physical DVD device; you must use an ISO file or a network boot to start an installation.
9
10Network boot with IPv6—Generation 1 VMs could network boot only with IPv4.
11
12VHDX-only support—Generation 2 VMs support only VHDX hard disk files, but you can convert a VHD file to VHDX with the Convert-VHD PowerShell cmdlet.
13
14GPT boot—Generation 2 VMs can boot to a boot disk that uses a GUID Partitioning Table (GPT) partitioning scheme.
15
16Disk expansion—A VHDX disk can be expanded while the VM is online, including the boot volume.
17
18Reduced attack surface—By removing legacy devices and adding the secure boot feature, security is improved for generation 2 VMs.
19
20Secure boot—Prevents unauthorized code from running during a system boot.
21
22There are other changes, but this list contains the most important improvements. Converting a generation 1 VM to generation 2 is possible, but you can’t use a generation 2 VM on Hyper-V versions before Windows Server 2012 R2. In addition, generation 2 VMs support only Windows 8 or Windows Server 2012 and later guest OSs.
23
24Activity 6-1
25Resetting Your Virtual Environment
26Time Required: 5 minutes
27
28Objective: Reset your virtual environment by applying the InitialConfig checkpoint or snapshot.
29
30Required Tools and Equipment: ServerHyperV
31
32Description: Apply the InitialConfig checkpoint or snapshot to ServerHyperV.
33
341
35Be sure that ServerHyperV is shut down. In your virtualization program, apply the InitialConfig checkpoint or snapshot to ServerHyperV.
36
372
38Close your virtual machine environment.
39
40Activity 6-2
41Creating a Virtual Machine
42Time Required: 10 minutes
43
44Objective: Create a new virtual machine using PowerShell.
45
46Required Tools and Equipment: ServerHyperV
47
48Description: The Hyper-V role is installed on your server and you are ready to create a virtual machine. In Chapter 2, you created a virtual machine using Hyper-V Manager. In this activity, you create a VM using PowerShell.
49
501
51Sign in to ServerHyperV as Administrator.
52
532
54Open a PowerShell window. You will create a new virtual machine named VMTest1 with 1 GB of RAM and a 40 GB virtual hard disk located in C:\VMs\VMTest1.
55
563
57In PowerShell, type New-VM VMTest1 -MemoryStartupBytes 1GB -NewVHDPath C:\VMs\VMTest1\VMTest1.vhdx -NewVHDSizeBytes 40GB and press Enter. By default, a generation 1 VM is created unless you specify otherwise using the -Generation 2 parameter. In addition, a network adapter is created, but it is not connected to a virtual switch.
58
594
60Next, you connect the network adapter to the virtual switch named PrivateNet. Type Connect-NetworkAdapter VMTest1 -Name “Network Adapter” -SwitchName PrivateNet, and press Enter.
61
625
63You need to point the virtual DVD to an ISO file if you want to install an OS on it. You point the DVD drive to an ISO file on the host at path C:\isos\w2k16.iso. Type SetVMDvdDrive VMTest1 -Path C:\isos\w2k16.iso and press Enter.
64
656
66To see information about the new VM, type Get-VM VMTest1 and press Enter. You see just a summary of the VM. To see more details, type Get-VM VMTest1 | fl * and press Enter. That command tells PowerShell to show all the properties of the VM in a list format (fl means Format-List, and the asterisk * means all properties). You can also see the VM and its settings in Hyper-V Manager. Open Hyper-V Manager, if desired, and verify that your VM can be seen and managed there.
67
687
69One of the nice things about using PowerShell to manage VMs is that you can get detailed information about VMs and create scripts for a number of management functions. For example, you can start all VMs that are currently turned off. Type Get-VM | Where-Object {$_.State -eq “Off”} | Start-VM and press Enter. All VMs that are currently off are started. You can access most of the properties of a VM by using the syntax &_.PropertyName. For example, in the cmdlet you just entered the PropertyName is State.
70
718
72Next, you can stop all the running VMs. Type Get-VM | Where-Object {$_.State -eq “Running”} | Stop-VM -Force and press Enter. The -Force parameter causes the VM to be turned off even if the OS is locked or there is no OS installed.
73
749
75You will delete this VM since you will use the premade VMs named ServerVM1 and ServerVM2 for the remainder of the Hyper-V activities. Type Remove-VM VMTest1 -Force and press Enter. Removing a VM doesn’t delete the virtual disk it was using. To delete the virtual disk, just use the del command. Type del C:\VMs\VMTest1\VMTest1.vhdx and press Enter.
76
7710
78Stay signed in to ServerHyperV and continue to the next activity.
79
80Activity 6-3
81Working with Virtual Machines in Hyper-V Manager
82Time Required: 25 minutes
83
84Objective: Explore Hyper-V Manager.
85
86Required Tools and Equipment: ServerHyperV, ServerVM1 virtual machine
87
88Description: In this activity, you work with Hyper-V Manager to become familiar with managing virtual machines in Windows Server 2016. You create a checkpoint, make some changes to the OS, and revert to the checkpoint.
89
901
91Sign in to ServerHyperV as Administrator, if necessary.
92
932
94Open Server Manager, and click Tools, Hyper-V Manager from the menu.
95
963
97Right-click the ServerVM1 virtual machine and click Connect.
98
994
100Power on ServerVM1 by clicking the Start toolbar icon or clicking Action, Start from the menu. While Windows is booting, close the Virtual Machine Connection console. Notice that in Hyper-V Manager, the VM’s CPU use changes as Windows boots, and the VM’s screenshot in the bottom pane changes periodically.
101
1025
103Double-click the VM’s screenshot at the bottom of Hyper-V Manager to open the Virtual Machine Connection console for the VM. After Windows finishes booting, click the Ctrl+Alt+Delete toolbar icon (the leftmost icon) to send a Ctrl+Alt+Delete keystroke to the VM, and sign in as Administrator.
104
105Tip tip
106To see a description of any toolbar icon, hover your mouse pointer over it.
107
1086
109Start Notepad, and type your name in a new text document. Don’t close Notepad or save the file yet. In the Virtual Machine Connection console menu, click the Save toolbar icon or click Action, Save.
110
1117
112Close the Virtual Machine Connection console. In Hyper-V Manager, notice that the State column for the VM shows Saved (or Saving if it hasn’t finished saving). After it has finished saving, open the Virtual Machine Connection console by double-clicking ServerVM1. Start the VM by clicking the Start toolbar icon. You’re right where you left off in Notepad.
113
1148
115Save the Notepad file to your desktop as file1.txt, and then exit Notepad.
116
1179
118Click the Checkpoint toolbar icon or click Action, Checkpoint from the menu. When you’re prompted to enter a name, type BeforeDeletingFile1, and then click Yes. You see a message titled “Production checkpoint created.” Read the information in the message, which informs you that the running application state was not included in the checkpoint. Production checkpoints are a new feature in Windows Server 2016 and are discussed later in this chapter. Click OK.
119
12010
121After the checkpoint is finished, minimize the VM, and note in Hyper-V Manager that the checkpoint is listed in the Checkpoints section. Maximize the VM, and delete file1 from your desktop. Empty the Recycle Bin so that you know the file is really gone.
122
12311
124Click the Revert toolbar icon or click Action, Revert from the menu.
125
12612
127Click Revert when prompted. The VM displays a message that it’s reverting and the VM is turned off. Start the VM and sign in. When the desktop is displayed again, you should see the Notepad file back on the desktop. Close the Virtual Machine Connection console.
128
129Note clip
130The VM was turned off when you reverted the checkpoint because it is a Production checkpoint that doesn’t save the running state of the VM. If it had been a regular checkpoint, the VM would have stayed on and you would have been returned to the running state when you took the checkpoint.
131
132
13313
134In Hyper-V Manager, right-click ServerVM1 and click Shutdown. When prompted, click the Shut Down button. The Status column displays Shutting Down Virtual Machine. Close the Virtual Machine Connection console.
135
13614
137After the VM state changes to Off, delete the checkpoint by right-clicking BeforeDeletingFile1 in the Checkpoints section and clicking Delete Checkpoint. Click Delete to confirm.
138
13915
140Stay signed in to ServerHyperV if you’re continuing to the next activity.
141
142Activity 6-4
143Exporting and Importing a VM
144Time Required: 30 minutes
145
146Objective: Export a VM and then import it using PowerShell.
147
148Required Tools and Equipment: ServerHyperV
149
150Description: In this activity, you practice exporting and importing a VM using PowerShell. You will work with the VM named InstallCore because it takes much less time to export and import it, and it takes less disk space.
151
1521
153On ServerHyperV, open a PowerShell window.
154
1552
156Type Export-VM InstallCore -Path C:\ExportVMs\ and press Enter. PowerShell will create the ExportVMs folder for you.
157
1583
159When the export has completed, type dir C:\ExportVMs and press Enter. You see a folder named InstallCore. Type dir C:\ExportVMs\InstallCore and press Enter. You see the three folders that contain the exported VM. Type dir “C:\ExportVMs\InstallCore\Virtual Machines” and press Enter. Be sure to include the quotation marks (“) since there is a space in the path. You see the two files that have the configuration information of your exported VM. Make a note of the first character of the file name (both file names are the same except for the extension).
160
1614
162Now, you will import the VM using the following cmdlet. In the path parameter, be sure to use quotation marks, type the first character of the configuration file name in place of the X, and press the Tab key where it says <Tab> so that PowerShell will finish the path with the configuration file name. Type Import-VM -Copy -GenerateNewID -Path “C:\ExportVMs\InstallCore\VirtualMachines\X<Tab> and press Enter. Note that had you not included the GenerateNewID option, you would have received an error about a duplicate identifier.
163
164Tip tip
165You can use the Tab key in any path when typing PowerShell cmdlets or command prompt commands. Windows will always display the first file or folder name it finds that starts with the character or characters you type. For example, if you type dir c:\ex<Tab>, Windows will complete that part of the path with C:\ExportVMs\, assuming a folder with that name exists.
166
1675
168Verify the new virtual machine by typing Get-VM and pressing Enter. Note that there are now two VMs with the name InstallCore. The next thing you would do is rename the imported VM. To do that in PowerShell, you’d need to use the virtual machine ID since you can’t distinguish them by name. For now, open Hyper-V Manager.
169
1706
171The VM you just imported will be listed second since it has a later creation date. To verify, click each VM and look in the bottom pane where the creation date is shown. Delete the second virtual machine named InstallCore by right-clicking it and clicking Delete. Click Delete to confirm. Note that deleting the VM in Hyper-V only deletes the configuration file, not the virtual hard disk.
172
1737
174Stay signed in and continue to the next activity.
175
176
177Change font size
178Asmall fontAmedium fontAlarge font
179Add Bookmark to this Page
180Print
181help?