Windows 11

How to setup Hyper-V in Windows 10 or windows 11?

How to setup Hyper-V in Windows 10 or windows 11?

When is a PC not a PC? When it’s a virtual machine.
A virtual machine (sometimes called a VM) is, effectively, a computer within a computer. It runs in an isolated session on the host computer, under the control of a system-level software layer called a hypervisor. The operating system running within the virtual machine is called the guest operating system. A VM can run the same software as a physical PC and can interact over a virtual network with other PCs and with web-based services. Crucially, a VM doesn’t require any hardware beyond what’s already part of the host PC.
Business editions of Windows 10—Pro, Enterprise, and Education—include a built-in hypervisor and associated management tools that are collectively part of a feature set called Hyper-V. This option is especially useful for developers, IT pros, and researchers in scenarios like the following:

  • If you need to run a program that was written for an earlier version of Windows and does not work properly in Windows 10, you can run it in a virtual machine using that older version of Windows.
  • Developers who need to test their programs in different Windows versions or under different resource configurations can set up a virtual machine for each target platform or configuration.
  • Security researchers and curious users who want to test software of unknown provenance or explore potentially dangerous websites can reduce the risks by working within the confines of a virtual machine (assuming it’s properly isolated from the host and the host network). If a virus or other malware is found, the host machine remains unscathed, and the virtual machine can be rolled back to a safe state.
  • IT pros and enthusiasts who want to test a new prerelease version of Windows or experiment with an alternative non-Microsoft operating system such as Linux can do so in a virtual machine. This way, they can try the software without having to dedicate a physical machine or risking their main system.
  • Authors of books like this one can use virtual machines not only to test various setups but also to capture images of screens that would be impossible to grab using ordinary screen-capture tools (for example, images showing sign-in screens or even Windows setup before Windows itself is fully functional).

A new feature called Windows Sandbox, introduced in Windows 10 version 1903, allows you to create a lightweight Windows 10 virtual machine on the fly, with no configuration. A Windows Sandbox session uses Hyper-V to create a pristine VM, isolated from the Windows 10 host, where you can test a program or visit a website without compromising your main system. When you close the Sandbox, every trace vanishes completely.
We cover this feature in more detail later in this chapter. There are, of course, some jobs for which Hyper-V virtual machines are inappropriate. Any task that requires direct access to physical hardware, such as the use of a GPU to encode and decode video files, should be reserved for physical hardware. Likewise, any workload that depends on low latency and precise timing is likely to perform unacceptably in a VM.
Virtual machines are also highly portable. You can move a VM to a new host by simply copying a few files.
To use Hyper-V, your system must meet certain minimum requirements, and you might need to enable the Hyper-V feature, as described in the next section. After that is done, you use Hyper-V Manager to create virtual machines. With enough system resources, you can then run one or more virtual machines, each operating independently of the others. Because they function as independent computers, each virtual machine can run a different version of Windows—32-bit or 64-bit, old or new, server or desktop—or even other operating systems that work on PC-compatible hardware.

GETTING STARTED WITH HYPER-V ON WINDOWS 10

Hyper-V (or, more accurately, the Hyper-V role) has long been a power feature in server editions of Microsoft Windows, allowing IT managers to use a single physical machine to host various server roles, each in its own virtual machine. Since the release of Windows 8 in 2012, Microsoft has included so-called Client Hyper-V in Pro, Enterprise, and Education editions of Windows, to the great delight of IT professionals, developers, security researchers, and tech enthusiasts.
The feature sets of Client Hyper-V and its counterpart in Windows Server 2016 overlap but are not a perfect match. In Windows 10, Client Hyper-V gains some additional features, such as production checkpoints, better support of older operating systems, and the ability for users to change memory and other settings without first shutting down a virtual machine. Feature updates since the original release of Windows 10 have added support for Secure Boot and Trusted Platform Modules in VMs; nested virtualization, allowing virtual environments to host additional virtual machines; a Quick Create tool for setting up a VM; better memory allocation; and a Default Switch option that makes virtual network connections easier to manage on laptop PCs.
The Hyper-V platform includes the Hyper-V hypervisor and a group of services that do the work of managing virtual hardware, connecting to virtual networks, and running virtual machines. In particular, the Virtual Machine Management Service (Vmms.exe) and the Hyper-V Host Computer Service (Vmmcompute.exe) both run under the credentials of the currently signed-in user; other parts of the Hyper-V infrastructure run under local system and service accounts, allowing VMs to run even when no user is signed in.
Separate from the hypervisor and related Hyper-V services, Client Hyper-V includes a set of management tools. Two of them are worth calling out here:

  • Hyper-V Manager (Virtmgmt.msc) A Microsoft Management Console snap-in that provides management access to the virtualization platform. Using Hyper-V Manager, you can create a new virtual machine; adjust the configuration of an existing VM; configure virtual networking and storage hardware; import, export, and share VMs; and adjust the settings of the Hyper-V platform itself.
  • Virtual Machine Connection (Vmconnect.exe) A Windows desktop program that allows you to interact with a running virtual machine using the keyboard and mouse on the host PC. The application can run in a window, in which its contents act as a virtual monitor for the VM, or in full-screen mode, where the virtual machine’s display takes over the host PC’s display.

SETTING UP HYPER-V

Before you get started with Hyper-V, be sure your computer meets the system requirements. Because each virtual machine uses system resources on a par with a standalone computer, the requirements are somewhat steep:

  • A CPU with Hyper-V features enabled Your computer must have a 64-bit processor that supports virtualization in the firmware and has Hardware-Enforced Data Execution Prevention enabled. Most 64-bit processors sold by Intel and AMD in the past decade have this capability. In addition, support for Second-Level Address Translation (SLAT) is required.
  • A 64-bit version of Windows 10 Pro, Enterprise, or Education Hyper-V is unavailable on 32-bit versions and is also not part of Windows 10 Home.
  • At least 4 GB of RAM With 4 GB of total RAM, you can probably run one or two low-resource virtual machines simultaneously. In our experience, you need at least 8 GB of total RAM for satisfactory performance with one or more virtual machines running Windows.
  • Copious disk space Each virtual machine is stored in files on your hard drive. The size can vary considerably depending on how you configure your virtual machines (for example, the operating system and the size of the VM’s virtual hard disks), how many checkpoints you save, and so on—but expect to use at least 20 GB of disk storage for each virtual machine.

With those prerequisites in place, you’re ready to turn on the Hyper-V features, which are installed but are off by default. To do so, open Windows Features, shown in Figure 16-1. (In the search box, type features and then click Turn Windows Features On Or Off.)

Figure 16-1 To select all the Hyper-V-related entries, select the top-level Hyper-V check box.
Click the plus sign by the top-level Hyper-V entry to show all the subentries. If your computer does not fully support Hyper-V, the Hyper-V Hypervisor entry is not available.
Select Hyper-V (which also selects all the available subentries) to enable it, and then click OK. After a few moments, Windows asks you to restart your computer.
Alternatively, you can enable Hyper-V by using Windows PowerShell. Use this cmdlet:

Enable-WindowsOptionalFeature –Online –
FeatureName Microsoft-Hyper-V –All

USING HYPER-V MANAGER

Hyper-V Manager is the program you use to create, configure, manage, and run virtual machines. When you start Hyper-V Manager, the initial view, shown here, might leave you scratching your head. You’re faced with a barren console window that has only one available action:

The trick is to select a “server” (in this case, your local computer) in the left pane, the console tree. (On computers that do not have Hyper-V Platform enabled, the only option is to choose Connect To Server from the Actions pane, which allows you to connect to a different virtualization server.) That action reveals far more information and options, as shown in Figure 16-2.

Figure 16-2 The bottom of the Hyper-V Manager window shows details about the currently selected virtual machine, with available actions for that VM on the right.
When you select a Hyper-V host in the console tree (in this case, your PC running Windows 10 Pro, Enterprise, or Education), the center pane lists the virtual machines available on that host and shows a bit of information about the current state of each one. Below that, you’ll see a list of checkpoints for the selected virtual machine. (A checkpoint captures the configuration and data of a virtual machine at a point in time. For more information, see “Working with checkpoints” later in this chapter.) At the bottom of the center pane, the Summary, Memory, and Networking tabs show additional details about the selected virtual machine. Here you can see at a glance what IP address has been assigned to the virtual machine, how much memory is in use, and so on. The thumbnail image on the Summary tab also provides a convenient launching method for the virtual machine; double-click it to connect to that virtual machine.
As in other console applications, the right pane shows available actions for the items selected in the left and center panes. Figure 16-2, for example, shows the actions that apply to the Hyper-V host running on the local computer named XPS9560-ENT and to the virtual machine named VM-1809.

WHATʼS IN A VIRTUAL MACHINE?

Creating and configuring a virtual machine isn’t particularly different from building a physical PC, except that instead of snapping memory modules into motherboards and connecting disk drives to SATA ports, you assemble virtual components using Hyper-V management tools. In fact, every virtual machine created using Hyper-V is built from the same small group of virtual components. With one noteworthy exception, the CPU, your virtual machine is unable to directly access hardware that’s part of the host PC.
You can see all of those components by opening Device Manager within a virtual machine. Figure 16-3, for example, shows Device Manager expanded to show a virtual disk, a virtual DVD-ROM drive, a virtual keyboard, a virtual storage controller, and an assortment of virtual system devices on a virtual motherboard.

Figure 16-3 Virtual machines are made up of virtual components, as you can see when you open Device Manager from within a Windows 10 VM, as we’ve done here.
In most cases, it’s considerably easier to upgrade a virtual PC than it is to perform the corresponding task on a physical PC. To add more virtual memory or a second virtual storage device, for example, all you need to do is shut down the VM and adjust a few settings in that VM.
We’ll get to the tools for creating and reconfiguring VMs later in this chapter. In the remainder of this section, we explain how Hyper-V stores the different pieces that make up a VM.
The most basic building block is the virtual machine configuration file, which is stored in a binary format using the .vmcx file extension. By default, these configuration files are stored in %ProgramData%\Microsoft\Windows\Hyper-V; you can specify an alternate location when you create a new VM, and you can move configuration files to a different folder or drive using Hyper-V Manager. (%ProgramData% is an environment variable that is set to C:\ProgramData on a standard Windows installation.)
Other files stored in the same location include .vmgs and .vmrs files, which contain information about the current state of a running VM, and the smart paging file, which supplements dynamic memory when you restart a VM.
The information contained in the configuration file instructs Hyper-V how to allocate resources to specific types of virtual hardware, as outlined in the next four sections.

Machine generation

In Windows 10, Hyper-V supports two types of machines. This choice is new to the Hyper-V client in Windows 10 and offers some trade-offs between compatibility and features.

  • Generation 1 supports a wide range of guest operating systems, including most versions of Windows (32-bit and 64-bit) and Linux. The virtual hardware in a generation 1 virtual machine is typical of that found in BIOS-based PCs for many years.
  • Generation 2 supports only 64-bit Windows versions: among desktop operating systems, Windows 8, Windows 8.1, and Windows 10 are supported; support for Windows Server as a guest operating system is restricted to Windows Server 2012 and later versions. Generation 2 also supports newer versions of many Linux distributions.

In addition, generation 2 removes support for attaching physical DVD drives and other older hardware to a virtual machine. But a generation 2 virtual machine has modern UEFI-based firmware, which enables Secure Boot and booting from a network adapter, SCSI hard drive, or virtual DVD. In addition, generation 2 virtual machines enable new Hyper-V features, such as the ability to adjust memory or add a network adapter while the virtual machine is running. A new feature that first appeared in Windows 10 version 1703 adds a Zoom Level command to the View menu in a Virtual Machine Connection window for generation 2 machines; with this command, you can set the display scaling to 100%, 125%, 150%, or 200%.
As we explain later in this chapter, you must make the choice of generation at the time you create a VM, and you can’t change it after that initial selection.

Memory

Like its physical counterpart, a virtual machine needs memory. When a VM is running, the memory assigned to that VM is reserved by Hyper-V and can’t be used by the host PC. If you assign a fixed amount of memory to a VM configuration, running that VM can put significant memory pressure on the host PC. If your host PC has 16 GB of RAM, for example, and you set the RAM value to 8 GB for a VM, your host PC is effectively limited to 8 GB for Windows and all other activities when that VM is running, even if the VM is using only a fraction of the memory assigned to it.
To ease this pressure, Hyper-V in Windows 10 includes a feature called dynamic memory, which allows you to make more efficient use of the memory in the host PC.
When you enable the Dynamic Memory option for a VM, you assign two additional values for memory: Minimum RAM and Maximum RAM. That configuration allows the VM to grab physical memory when it needs it (especially when starting up) but releases that memory when it’s no longer in use so that it’s available for the host PC.
Figure 16-4 shows memory usage in a VM that is configured with 4096 MB (4 GB) of RAM, with Dynamic Memory enabled, Minimum RAM set to 2048, and Maximum RAM set to 8192.

Figure 16-4 Unlike a physical PC, virtual machines can be configured with dynamic memory. This VM is allowed to use a minimum of 2.0 GB and a maximum of 8.0 GB of RAM.
In that Task Manager window, you can see the RAM configuration, 4.0 GB, in the upper-right corner. That’s the amount of RAM that was allocated at startup, exactly as it would look on a physical PC with 4 GB of RAM. In this VM, however, you can see from the Memory Usage scale that only 2.0 GB of physical RAM from the host PC is in use. The Maximum Memory value at the bottom right shows that this VM is ready and able to increase its RAM to 8.0 GB if necessary (and if that physical RAM is available on the host PC).
Dynamic Memory is an excellent way to conserve memory when running Hyper-V on a system with limited physical RAM. If you have ample system resources and want to occasionally run VMs with a fixed amount of RAM, leave that option disabled.

Storage controllers and virtual disks

Every Hyper-V virtual machine includes a virtual storage controller. On a Generation 1 VM, this virtual component mimics a legacy IDE controller. On a Generation 2 VM, it acts like a SCSI controller.
Part of the basic configuration of a VM is, of course, a virtual hard disk that attaches to that virtual controller. Hyper-V in Windows 10 supports three virtual disk file formats: the legacy VHD format, the newer VHDX format, and a specialized VHD Set format for shared virtual hard disks.
The legacy VHD format is limited to a total size of 2 TB. VHDX files, on the other hand, can be as large as 64 TB, provide better data resiliency, and support advanced 4K sector technology; you can also expand a VHDX file on the fly without having to shut down the VM in which it’s being used. VHD Set files work only on Windows 10 and Windows Server 2016; this format is primarily intended for use with failover clusters of multiple virtual machines running Windows Server 2016 or later.
An important attribute of a virtual disk that distinguishes it from a physical disk is the disk type, which can be one of the following three choices:

  • Fixed size This type of virtual disk uses exactly as much disk space on the Hyper-V host as its configured size. The size of the VHD file doesn’t change based on the amount of data stored within it.
  • Dynamically expanding Choose this disk type when you want to conserve physical disk space on the Hyper-V host and the workloads you plan to use on the VM are not disk-intensive. The virtual disk file starts out small and grows as you add data to it within the VM. (You can’t, of course, overturn the laws of physics; as your virtual hard disk expands, it will use a corresponding amount of physical disk space.)
  • Differencing This advanced disk type starts with a parent disk that remains intact; any changes you make in this virtual disk affect only the file containing the child disk and can be reverted easily.

On a generation 2 virtual machine, you also have the option to share a virtual disk file that already exists. If you have a spare physical disk partition available, you can create a virtual disk and attach that physical drive to it directly. This option offers excellent performance but is impractical on most desktop configurations.
Generation 1 VMs also allow the use of virtual DVDs, which are most useful when you want to mount an ISO file to install a new operating system in the VM. If you’re feeling especially nostalgic, you can even create a virtual floppy disk.

Networking

Support for basic networking in Hyper-V requires two components: a virtual network adapter, configured separately for each VM, and a virtual switch, which is managed by the Hyper-V platform. The default virtual network adapter is called a Hyper-V specific network adapter and is available for both generation 1 and generation 2 machines. In generation 1 machines only, you can install a legacy network adapter capable of booting directly to a network and running unsupported operating systems.
By default, a new virtual machine is set up as a standalone computer with no network connection. It can’t connect to the internet or to other computers on your network. That disconnected configuration might be useful for some testing scenarios, but for most situations, you’ll probably want to give your virtual machines access to a network connection.
To do that, you must first configure the virtual network adapter to connect to a virtual switch; that action connects the virtual network adapter in your virtual machine to the physical network adapter in your physical computer, thereby allowing the VM to connect to the outside world. For each virtual switch you configure, Hyper-V creates a corresponding virtual network adapter on the host PC that handles communication to other hosts and to the internet. Here, for example, is what the virtual adapter for the default switch looks like in Network Connections in Control Panel:

In current versions of Hyper-V on Windows 10, every VM has access to a preconfigured default network switch that communicates with the host PC and other PCs using Network Address Translation (NAT). To use this switch, when you get to the point in creating a new virtual machine where you configure networking, simply select Default Switch from the drop-down list.
You can create additional custom switches to accommodate other network configurations, and then choose the type of virtual switch you need for each VM, at startup time or while the VM is running.
To create a virtual switch or make changes to an existing one, open Hyper-V Manager and then, in the Actions pane (or on the Action menu), click or tap Virtual Switch Manager. Then select the type of switch you want to create:

  • External This is the correct choice for a VM that you want to use as if it were another PC on your local network. This configuration binds the virtual switch to your computer’s physical network adapter so that you can access your physical network. Assuming your physical network adapter is connected to the internet, your virtual machines using this type of switch also have internet access.
  • Internal An internal virtual switch allows connections among virtual machines on the host PC using the same virtual switch; those VMs can also connect to the host PC and to the internet using the virtual network adapter (vEthernet) on the host PC.
  • Private Use a private virtual switch to set up a network that comprises only the virtual machines running on your physical computer and using the same virtual switch. This network is isolated from all physical computers, including the Hyper-V host on which it’s installed.

When you click or tap Create Virtual Switch, you’re asked for more details, as shown in Figure 16-5. Click OK to complete the switch creation.

Figure 16-5 If your computer has more than one physical network adapter, specify the one you want to use for a new switch under External Network.

USING WINDOWS SANDBOX FOR INSTANT VMS

When you just want to check out a suspicious web link or test an unknown program and you want to keep everything completely separate from your host machine, you need Windows Sandbox. This feature, which is available in Windows 10 Pro, Enterprise, and Education, uses hardware-based virtualization and the Windows 10 hypervisor to build an extremely lightweight and clean virtual machine that’s ready in seconds. When you close the sandbox, every trace of it is discarded, and your next session starts from the same clean baseline.
Although Windows Sandbox uses the same underlying technology as Hyper-V, it runs independently. To use the feature, you first have to enable hardware virtualization ; after that task is complete, open the Windows Features dialog box, select the check box to the left of the Windows Sandbox entry, and click OK. After you restart your PC, the Windows Sandbox shortcut will be available in the list of programs on Start.
Click that shortcut to immediately create a sandbox, which appears in a resizable window that closely resembles a Hyper-V virtual machine, minus the toolbar and configuration options.
A few things are worth noting about these lightweight virtual machines:

  • The sandbox runs an unactivated copy of Windows 10; the edition and version match that of the host PC.
  • Windows Defender Antivirus protection is turned off. (Because the sandbox is not persistent or connected to the host, this means malicious code can run but can’t cause damage outside the sandbox.)
  • All of the familiar Windows accessories, administrative tools, and system utilities are available, including Windows PowerShell. With the noteworthy exception of the Microsoft Edge browser, however, no Windows 10 apps are installed or available.
  • The default user account is a local administrator called WDAGUtilityAccount; that account is also used by the Windows Defender Application Guard feature for browsing web pages in an isolated environment.
  • Virtual system resources include 4 GB of virtual memory and a 40 GB system drive. The sandbox image itself is contained in a small, read-only partition labeled PortableBaseLayer, which you can see in Disk Management (on our test systems, it’s typically 8 GB in size).

Because the sandbox runs in a Hyper-V enhanced session, it shares the Clipboard with the host PC. As a result, you can copy links or executable files from the host PC and paste them directly into the sandbox window.
Because Windows Sandbox was designed to be lightweight and simple, it lacks any interface for customizing the sandbox environment. However, customization is possible by using a simple XML file. For example, including the value
<MemoryInMB>8192</MemoryInMB> increases the default memory for the sandbox from 4 GB to 8 GB.
Sandbox configuration files use the .wsb extension to associate with Windows Sandbox, and you can launch a sandbox using a custom configuration by double-clicking a saved .wsb file. For details, see “Windows Sandbox configuration,” at https://bit.ly/windows-sandboxconfig-files.

CREATING AND MANAGING VIRTUAL MACHINES

Beginning with Windows 10 version 1709, Hyper-V supports two ways of creating a persistent virtual machine from within Hyper-V Manager. The Quick Create option was introduced in version 1703, and version 1709 added support for a gallery of predefined virtual machine images. This option allows you to create a VM with just a few clicks; if you’re comfortable with the settings it makes on your behalf, this can be a useful tool.
The alternative is the traditional New Virtual Machine Wizard, which walks you step by step through configuring each virtual component. The process can feel tedious, but it also results in much greater control over the VM’s configuration.
Using Quick Create to configure a new VM
The Quick Create command appears at the top of the Actions pane for a Hyper-V server (which in this case is a desktop PC running Windows 10 Pro), as shown earlier in Figure 16-2. Clicking Quick Create opens a Create Virtual Machine dialog box like the one shown in Figure 16-6. From this dialog box, you can choose a predefined image or specify a local source of installation media, as we’ve done here.

Figure 16-6 With just a single dialog box, Quick Create allows you to answer the most essential questions posed by the New Virtual Machine Wizard.
Over time, the number of ready-made virtual machines available in the Hyper-V gallery has increased. The Windows 10 Dev Environment package, shown earlier in Figure 16-6, includes an evaluation version of Windows 10 Enterprise and requires a download of more than 16 GB; the two Ubuntu packages, by contrast, allow you to set up a VM running this popular Linux distribution but require a download of well under 2 GB.
In addition to the packages Microsoft provides in this default gallery, organizations can make custom images available for internal development and test groups.
If nothing in the Quick Create gallery meets your requirements, take advantage of the last option to create a VM using local installation media. From the Quick Create dialog box, select Local Installation Source, click the Change Installation Source button, and navigate to the ISO file you want to use for installation or the VHD/VHDX you want to use as a template. The file must be in the form of an ISO image or a virtual hard disk file.
The check box under Change Installation Source enables Secure Boot, a feature of UEFI-based computers.
We recommend that you click More Options to display controls where you can enter a descriptive file name and select a virtual network adapter. You can specify two settings from this dialog box:

  • Name The text you enter here will be used to identify the VM in the Virtual Machines list in Hyper-V Manager.
  • Network Here you select a virtual network switch for the VM. Unless you’ve created a custom network switch, choose Default Switch here.

With those details complete, click Create Virtual Machine. Hyper-V creates your new VM using default settings and displays a final dialog box with two buttons. The first allows you to connect to the VM immediately; the second opens the Settings dialog box for the new VM, where you can adjust the amount of memory, tinker with hard drives, and make any other necessary changes.

Using the New Virtual Machine Wizard

If you want step-by-step control over the process of creating a new VM, avoid Quick Create. Instead, open Hyper-V Manager and, in the Actions pane, click or tap New > Virtual Machine. That action launches the New Virtual Machine Wizard. Navigating through the wizard leads you through the process of setting up a virtual machine. Use the Next and Previous buttons or the links along the left side to step through each group of settings. At any point in the wizard, you can click Finish to create a virtual machine that uses default values for any wizard pages you skip.
The first page of the wizard is a text-only Before You Begin page, which you can banish for good by selecting Do Not Show This Page Again. The remainder of this section describes your options at each succeeding step of the wizard.

Specify name and location

After you step through the Before You Begin page, the wizard asks you to provide a name for your virtual machine. Replace the generic New Virtual Machine entry with a name that’ll help you differentiate this virtual machine from others you might create. (The wizard will use this entry again later, as the suggested name for the virtual hard disk you create.) If you don’t like the proposed storage location for the virtual machine files, select the check box and specify another, as shown in Figure 16-7.

Figure 16-7 Use a descriptive name to help identify the VM in Hyper-V Manager. We recommend storing configuration files in the default location unless you have a separate, dedicated data drive.
The default location is %ProgramData%\Microsoft\Windows\Hyper-V\. If your computer has a small system drive—a common configuration in some desktop systems that use a solidstate drive for system files and a large hard disk for data files—you might want to store the files elsewhere. Keep in mind that a virtual machine can occupy 10–40 GB or more, and each checkpoint can consume equivalent amounts of space.
It’s possible to change the location where the virtual machine configuration files are stored after you create the VM, but it’s not easy. The virtual hard disk can be moved by right-clicking the machine name and choosing the Move option, for example, and the paging file location can be changed by adjusting the VM configuration, but these options aren’t available for the core configuration files. To completely move all the pieces of a virtual machine at a later time, you can export a virtual machine, copy it, and store it in a different location. You’re much better off choosing a suitable location before you create the virtual machine.

Specify generation

On the Specify Generation page, shown here, select either Generation 1 or Generation 2 for the style of virtual machine you need.

If you’re going to install a relatively new, supported version of Windows in your virtual machine, select Generation 2 to enable additional features such as Secure Boot. For an older operating system, the default option, Generation 1, is probably a better choice.

Assign memory

On the Assign Memory page, shown in Figure 16-8, you specify the amount of RAM to assign to the VM during startup. This amount remains assigned to the VM when it’s running unless you select the Use Dynamic Memory For This Virtual Machine option.

Figure 16-8 By selecting the Use Dynamic Memory For This Virtual Machine check box, you can use memory more efficiently, which can improve performance when physical memory is scarce.

Configure networking

On the Configure Networking page, shown in Figure 16- 9, you specify the virtual network switch where you want to connect your virtual machine’s network adapter. The default option is Not Connected, which results in a virtual machine that’s isolated from all other computers (physical and virtual) and from the internet. To connect to the host PC and to the internet, select Default Switch (a new feature, introduced in Windows 10 version 1709, which uses NAT to connect to your computer’s network) or select a virtual network switch you created previously.

Figure 16-9 Select a virtual network switch to connect to the outside world. The Default Switch option is the appropriate choice for most VMs.

Connect virtual hard disk

Use the Connect Virtual Hard Disk page, shown in Figure 16-10, to set up the virtual machine’s first virtual hard disk. By default, the New Virtual Machine Wizard creates a dynamically expanding virtual hard disk, using the VHDX format and a default name based on the name you entered in the first step. If you want to create a fixed-size virtual hard disk or use the older VHD format, choose the Attach A Virtual Hard Disk Later option and customize your VM after you complete the wizard.

Figure 16-10 With the first option, you create a virtual hard disk. Choose one of the other options to use an existing virtual hard disk. Just like a physical computer, a virtual machine can have multiple hard drives; the wizard allows you to create or attach the system drive only. By default, this drive is created in the shared documents folder for the Public user profile, where it’s accessible to any user who signs in on the host PC. You can override that default and store the virtual hard disk on any physical disk that’s accessible to the Hyper-V host.

Installation options

The Installation Options page, shown in Figure 16-11, allows you to specify how and when you want to install an operating system in your new virtual machine.
Because this is a generation 2 virtual machine, the only options available are to use an ISO image file or install from a network server running enterprise deployment tools. (Generation 1 VMs offer options to install from the physical CD/DVD drive on the Hyper-V host or from a bootable virtual floppy disk.)

Figure 16-11 These options are available for a generation 1 VM. Generation 2 VMs allow installation of an operating system only from an image (ISO) file or a network source.
Like a physical computer, a virtual machine is useless without an operating system, so installing one should be your first order of business unless you’re using a virtual hard disk that already has an operating system installed. Select the appropriate option, specify the location of your operating system installation media, and click Next. This brings you to a Summary page, where you can review your settings before clicking Finish to complete the wizard.
At this point, even though you specified installation options, you still don’t have a working virtual machine. Now back in Hyper-V Manager, you have two choices: You can select the newly created VM and then fine-tune its settings (as described in the following section). Or you can double-click the new virtual machine to open it in a Virtual Machine Connection window. Then click or tap the Start button on the toolbar or choose Start on the Action menu. This “powers on” your virtual machine and launches the operating-system setup from the location you specified in the wizard.

CHANGING SETTINGS FOR A VIRTUAL MACHINE

As we noted earlier in this chapter, you can freely modify most of the virtual hardware associated with a virtual machine—for example, adding virtual memory, expanding a virtual hard disk, or connecting a virtual DVD drive. The one exception is the machine generation, which cannot be changed after its initial configuration. You can also perform management tasks, such as adjusting how the VM behaves when you shut down or restart the host PC.
To dive into these settings, open Hyper-V Manager, select the virtual machine you want to reconfigure, and then, near the bottom of the Actions pane, click or tap Settings. (If that menu is not visible, right-click the VM name to see a shortcut menu containing the same options.) The Settings dialog box, shown in Figure 16-12, contains two groups of options: one for the virtual hardware and the other for management settings. Note that some hardware options available here differ slightly, depending on the machine generation.

Figure 16-12 Use this Settings dialog box to adjust a wide array of options that are not available when using Quick Create or the New Virtual Machine Wizard.
The Processor settings shown in Figure 16-12 are primarily designed for Hyper-V on servers containing multiple processors. Virtually all PCs designed for use with Windows 10 contain a single processor with multiple cores, and the settings in that dialog box do not apply. If you try to assign more than one virtual processor to a virtual machine, Hyper-V ignores the setting.
Some settings can be changed even while a machine is running (which is important for virtual machines running critical tasks), especially on generation 2 virtual machines. Other configuration changes, however, require that the VM be shut down and turned off (not just saved).

Fine-tuning virtual memory usage

As with a physical PC, adding memory is the single most important thing you can do to improve performance. The balancing act with a virtual machine is finding the right configuration that doesn’t hobble performance on the host PC.
Options available when you select from the Hardware pane are identical for both generations of virtual machines. When dynamic memory is enabled, you can specify minimum and maximum amounts of memory to be available to that VM. If you’re obsessed with memory tuning, you can also change buffer sizes for dynamic memory and adjust the priority for memory usage when multiple virtual machines compete for a limited supply of physical RAM.
Figure 16-13, for example, shows the memory configuration for a VM running Windows Server 2016. Note that we’ve increased the Minimum RAM setting from its default value of 512 MB to 4096 MB and lowered the default Maximum RAM value of 1,048,576 MB to 8192 MB.

Figure 16-13 Using these dynamic memory settings, the VM will never have less than 4 GB of RAM available to it. When needed, it can use as much as 8 GB of memory but no more.

Adding, removing, and adjusting virtual disks

For most garden-variety VMs, the default configuration is sufficient: a single virtual disk used as the system drive and a virtual DVD available for installing software. For some tasks, however, you might want to add a second virtual hard disk, or you might need to change the size or format of an existing disk. This section covers your available options.

Adding a new virtual disk

To add a new virtual disk to an existing VM, follow these steps:
1. Open Settings and click the entry for the VM’s disk controller: SCSI Controller on a generation 2 machine, or one of the two IDE Controllers on a generation 1 machine.
2. From the list on the right, choose Hard Drive and click Add. Hyper-V automatically selects an unused location on the controller and displays the settings for that location, as shown in Figure 16-14.

Figure 16-14 Clicking the New button on this page launches a wizard that walks you through configuring a virtual hard disk.
3. Click New to open the New Virtual Hard Disk Wizard and complete its steps:
1. Choose Disk Format (VHD/VHDX) This option is available only for a generation 1 machine. For generation 2 machines, the default format is VHDX and this step is unavailable.
2. Choose Disk Type Dynamically Expanding is the default and is usually the correct choice for a VM running a modern operating system; you can also choose Fixed or Differencing.
3. Specify Name And Location Change the default name (“New Virtual Hard Disk”) to something descriptive, and adjust the location if necessary.
4. Configure Disk Accept or change the default size of 127 GB, or copy the contents of an existing physical or virtual disk to the newly created disk.

4. Complete the wizard to add your hard disk.
Note that this sequence is the equivalent of attaching a new drive to a physical PC. If the virtual machine is running Windows, you’ll need to use the Disk Management console to add the drive, format it if necessary, and assign a drive letter.

Removing or replacing a virtual disk

Removing a virtual disk from a VM configuration is a straightforward process. You might choose to do so if you created a secondary disk for test purposes and no longer need it. From the Settings dialog box for the VM, click the drive in the Hardware pane on the left, and then click the Remove button on the right. Although it’s possible to remove the system drive from a VM, it’s hard to imagine why you would want to do that.
You’re more likely to replace one virtual disk with another, a task you can complete by selecting the virtual disk, clicking the Browse button in the pane on the right, and then choosing the replacement drive. As an alternative, you can also click New to replace the existing disk with a blank disk for a clean start.
In either case, note that removing or replacing the disk does not remove the underlying VHD/VHDX file. If you want to reclaim that storage space on the host PC, you’ll need to do so manually, from File Explorer.

Inspecting, expanding, and converting virtual disks

If you’re curious about the size, format, and other details of a virtual hard disk, select its entry in the left pane of the Settings dialog box and then, on the right, click Inspect. That opens a small dialog box packed with all the essential details, including the current file size and the maximum disk size.
To expand a virtual disk or convert it to a different format or disk type, you need to first remove any checkpoints from the virtual machine (a process we explain later in this chapter). After doing so, shut down the VM, select the hard disk from the Settings dialog box, and click Edit. That opens yet another wizard, as shown in Figure 16-15, with Compact, Convert, and Expand options that are relatively easy to follow.

Figure 16-15 Use the Edit Virtual Hard Disk Wizard to convert a dynamically expanding disk to fixed size, or vice versa. You can also convert between VHD and VHDX formats here.
If you find you’ve run out of virtual disk space (or are in imminent danger of doing so), use the Expand option to increase the size of the drive. Note that the additional space you create is not automatically added to any disk volumes in your virtual machine. You’ll need to open the VM and use Disk Management to expand the volume to use the newly added space.

Advanced security options

On generation 2 VMs only, the options available when Security is selected offer the same security features you get with Windows 10 running on a UEFI-based physical PC. Figure 16-16 shows these options for a virtual machine running a preview release of Windows. Note that Secure Boot is enabled using the Microsoft Windows template. For a virtual machine running a distribution of Linux that supports Secure Boot, choose the Microsoft UEFI Certificate Authority template instead. (The third option, Open Source Shielded VM, is available only on hosts running Windows Server 2016.)

Figure 16-16 On a generation 2 virtual machine, you can turn on Secure Boot and, optionally, create a virtual Trusted Platform Module to use BitLocker Disk Encryption on virtual disks.
This set of options also allows you to enable a virtual Trusted Platform Module (TPM), which allows the disks in a virtual machine to be encrypted with BitLocker Disk Encryption. On 2015 releases of Windows 10, enabling this feature required some special preparation; these steps are not required on any currently supported Windows 10 versions. For more details, see the TechNet article “Generation 2 virtual machine security settings for Hyper-V,” at https://bit.ly/gen2-vm-security.

Automatic start and stop actions

You use the final two options under the Management heading to specify what happens to a virtual machine when you shut down or start the Windows 10 Hyper-V host. For most purposes, the correct setting for Automatic Stop Action is Save; for Automatic Start Action, you can configure a VM to start automatically (with or without a delay) or start the VM only if it was running when the system shut down previously.

RUNNING A VIRTUAL MACHINE

As the final step in creating a virtual machine, as described earlier in this chapter, you double-click the name of a virtual machine in Hyper-V Manager to open the machine in a Virtual Machine Connection window.
(Clicking Connect in the dialog box that appears after you set up a new machine using Quick Create does the same thing.) You then click the Start button on the toolbar to power on the machine. You can run the virtual machine session in a Virtual Machine Connection (VMConnect) window using one of two session types:

  • Basic sessions run in the VMConnect console window, which can be expanded to any resolution supported by the virtual display adapter. This type of session accepts keyboard and mouse input and displays the contents of the VM display; however, there’s no access to audio hardware or external USB devices.
  • Enhanced sessions, which debuted with Hyper-V in Windows 8.1, provide a significantly richer experience, with the ability to share the Clipboard with the host machine, redirect audio from the VM to the host PC’s speakers or headphones, share local drives and some USB devices in the VM, connect to a printer through the host PC, and sign in with a smart card. Enhanced sessions can also use multitouch displays and multiple-monitor configurations.

Enhanced session mode uses Remote Desktop Protocol over the virtual machine bus (VMBus); as a result, you can only use an enhanced session with a VM running a supported guest operating system: Windows 8.1 or Windows 10 (Pro, Enterprise, or Education); or Windows Server 2012 R2 or later. Remote Desktop connections do not have to be enabled in the guest operating system. For guest operating systems that don’t support enhanced sessions, such as Windows 7 Pro, the only alternative to a basic session is to configure a network connection in the VM and use the Remote Desktop client to connect to it. That option provides several of the features available in an enhanced session, including a shared Clipboard and audio support.
Working with Virtual Machine Connection windows
As shown in Figure 16-17, a virtual machine running in a Virtual Machine Connection window looks (and, for the most part, acts) just like a separate physical computer, except that it’s contained in a window on your desktop.
In this example, we’re even able to capture a screenshot of the sign-in screen, which isn’t possible on a physical PC.

Figure 16-17 To work safely with a preview release of Windows 10, you can run it in a Virtual Machine Connection window.
Use the toolbar at the top of the window (or the corresponding commands on the Action menu) to operate the virtual machine.

From left to right, the buttons have the following functions:

  • Ctrl+Alt+Del Because the Ctrl+Alt+Del key combination is reserved by Windows 10 on your physical computer, when you press it while you’re using a virtual machine, the key combination goes to your host computer. To mimic the effect of Ctrl+Alt+Del within a virtual machine, press Ctrl+Alt+End, or click or tap this toolbar button.
  • Start This button turns on a virtual machine that is off.
  • Turn Off This button turns the virtual machine off, but it does soby effectively unplugging the machine. This, of course, is a quick but not graceful way to shut down a computer (even a virtual one), and you’ll lose any unsaved data.
  • Shut Down Clicking this button is equivalent to using the Shut Down command on the Start menu, and the machine goes through the usual shutdown process. Note that some unusual configurations (usually older, unsupported operating systems) do not allow the use of the Shut Down command in Hyper-V. For a virtual machine without this support, use commands within the virtual machine to shut down properly.
  • Save This button saves the virtual machine state and then turns it off, releasing all resources to the host PC. The process is much like hibernation on a physical computer. When you next start the virtual machine, you return immediately to where you left off.
  • Pause/Resume Pausing a virtual machine stops it temporarily but does not fully release its resources, as the Turn Off, Shut Down, and Save options do.
  • Reset Resetting a virtual machine discards any changes and reboots using the last saved version.
  • Checkpoint This button creates a checkpoint, which is a snapshot of the virtual machine’s state and its data.
  • Revert This button restores the virtual machine to its condition at the previous checkpoint and restarts the virtual machine.
  • Basic/Enhanced Session On guest operating systems that support it, this button toggles the virtual machine between basic session mode and enhanced session mode. For more information, see the next section, “Using enhanced session mode.”
  • Share Use this option, introduced in version 1709, to export the entire virtual machine configuration and data files (but not checkpoints) to a compressed file in VMCZ format. You can then copy that file to another PC running Hyper-V and double-click to import the VM.

Within the Virtual Machine Connection window, you use the virtual machine just as you would a physical computer, with only a few exceptions:

  • When you run an older, unsupported guest operating system, using a mouse is not as fluid as it is when your guest operating system is Windows 7 or later. In those configurations, the mouse can become trapped when you click inside the virtual machine window. To release it, press Ctrl+Alt+Left Arrow.
  • Not all of your physical computer’s hardware is available in all virtual machines. For example, access to the physical DVD drive on the Hyper-V host is not available in generation 2 virtual machines. (You can, however, mount an ISO image as a DVD drive.) For generation 1 machines, only one virtual machine can use a physical DVD drive at any given time. (To release the DVD drive from one virtual machine so that you can use it in another, use commands on the Media menu.) USB devices, audio devices, and some other local resources work only in enhanced session mode.

When you close the Virtual Machine Connection window, note that your virtual machine continues to run. By closing the window, all you’re doing, in effect, is turning off the monitor. To shut down or turn off the virtual machine, you should use the appropriate buttons on the Virtual Machine Connection window. If that window is closed, reopen it by using Hyper-V Manager.

Using enhanced session mode

As we noted earlier, Hyper-V support in earlier versions of Windows included severe limitations on access to physical hardware from a VM. You could overcome some of these limitations (specifically, audio playback and file copying) by using Remote Desktop Connection to connect to a virtual machine, but that option requires a working local network connection to the virtual machine.
The solution in Windows 10 is enhanced session mode, which solves many of these shortcomings. With enhanced session mode, you can redirect the following resources from your physical computer to a virtual machine in a Virtual Machine Connection window:

  • Audio devices
  • Printers
  • Plug and Play devices
  • Clipboard (which you use to copy and paste files and other information between the virtual machine and your physical computer)

Alas, enhanced session mode comes with its own limitations. As noted earlier, it works only with Windows 8.1 (or Windows Server 2012 R2) and later versions as the guest operating system. And in enhanced session mode, you can’t change the resolution of the virtual machine’s monitor using commands within the virtual machine. (For a workaround, see the following tip.)
However, a new capability built in to Windows 10 version 1703 and later allows you to change resolution simply by dragging the borders of the Virtual Machine Connection window; when you do so, the guest operating system automatically adjusts to the new resolution.
If your virtual machine is running an operating system that supports enhanced session mode, you can switch between basic and enhanced session mode by clicking or tapping the next-to-last button on the Virtual Machine Connection toolbar.
You can enable and disable enhanced session mode on a per-server or per-user basis. To view or change either setting, in Hyper-V Manager, select the host name from the tree on the left and then, under the host name in the Actions pane, click or tap Hyper-V Settings. In the Hyper-V Settings dialog box that appears, you’ll find enhanced-session-mode settings under Server and User.
One of the most effective uses of an enhanced session is to work with a virtual machine as if it were a complete replacement for the host PC. To do so, move the resolution slider to Full Screen. If your host PC has multiple monitors, select the Use All My Monitors check box. Click Connect, and the virtual machine expands to fill the entire display (or displays). The only indication that you’re working with a virtual machine is the toolbar at the top of the screen. That bar includes the name of the VM and the host PC in the center and standard Minimize, Restore, and Close buttons on the right. If the status bar gets in the way of something on the screen, you can slide it left or right. To hide it completely, click the Pin icon at the far left. When the status bar is hidden, you can show it by moving the mouse pointer to the top of the screen and allowing it to remain there briefly.

WORKING WITH CHECKPOINTS

A checkpoint captures the data and configuration of a running virtual machine—a snapshot in time. Indeed, in earlier versions of Hyper-V, checkpoints were called snapshots. A checkpoint can be restored so that you can quickly and easily return your virtual machine to an earlier time—this capability is particularly valuable for providing a consistent test environment for evaluating software. After the testing is complete, revert to the previous checkpoint to start another round of testing under conditions that are exactly the same as they were before the previous test.
To capture a checkpoint from within a running VM, click or tap the Checkpoint button on the Virtual Machine Connection toolbar, or use the keyboard shortcut Ctrl+N. You can provide a descriptive name for the checkpoint, but no other interaction is necessary. The checkpoints you collect for a given virtual machine appear in the center of the Hyper-V window, as shown in Figure 16-18. To revert to an earlier checkpoint, select the checkpoint and, in the Actions pane, click or tap Apply.

Figure 16-18 When you select a checkpoint in the center pane, a list of applicable actions for that checkpoint appears in the bottom of the Actions pane.
Microsoft engineers discovered that droves of Hyper-V users use checkpoints as a form of backup. (Although it doesn’t provide the full capabilities of a more traditional backup program—such as the ability to restore individual folders and files—it’s convenient and easy.) However, the checkpoint feature as implemented in earlier Hyper-V versions is far from ideal for backup. Because those checkpoints (now called standard checkpoints) include information on the virtual machine state, running applications, and network connections, restoring one often takes you to an unstable condition (for example, the same network connections might not be available).
In response, Client Hyper-V in Windows 10 adds a new type of checkpoint called a production checkpoint. A production checkpoint uses the Volume Snapshot Service (VSS) backup technology to save the data and configuration of a running virtual machine but not its state. This provides a much better backup solution, and it’s now the default checkpoint in Hyper-V. You can still use standard checkpoints if you prefer; to make the switch, open Settings for a virtual machine and, under Management, click Checkpoints:

Effective with version 1709, Hyper-V adds a Use Automatic Checkpoints check box. This option automatically creates a checkpoint when you start a VM, giving you the option to roll back without having to remember to create checkpoints. The next time you shut down and restart the virtual machine, you’ll have the option to revert to the previous checkpoint. This option is automatically on for new Windows 10 VMs. If you’re concerned that this option is too resource-intensive, disable it.

IMPORTING, EXPORTING, AND MOVING VMS

When you have a virtual machine running on one Windows 10 PC and you want to move or copy that VM to a different Windows 10 PC, you have two options.
The first is to use the Export function. Start by shutting down the VM you want to move or copy. Then, in HyperV Manager, select the VM and click Export in the Actions menu. In the resulting dialog box, specify a location that has sufficient free disk space to hold all the files associated with the VM (a folder on a removable hard disk, for example, or a network share) and then click Export. This operation (which can take a long time depending on the size of the virtual disks associated with the VM) saves your files in three separate subfolders in the location you specified.

ALTERNATIVES TO HYPER-V

Client Hyper-V is the easiest way to work with virtual machines in Windows 10, but it’s not the only way. Two relatively new options provide alternatives that might make sense if you’re a candidate for virtualization.
Windows 10 supports the use of Hyper-V Containers, which are self-contained virtual environments that can manage workloads without requiring the overhead (and licensing cost) of a full operating system. Container support is new and still developing. For an overview, see the information at https://bit.ly/windows10-containers-docs.
Microsoft Azure is a cloud-based service capable of running virtual machines that don’t require local resources. Azure VMs are charged on a pay-as-you-go basis, making them ideal for test environments and important servers where downtime is not an acceptable option. If you have a Visual Studio subscription, your account includes a monthly allowance for Azure usage, with ready-made Windows and Linux virtual machines available. For more details, see https://azure.microsoft.com/services/virtualmachines/.