Chapter 17

Running Windows 11 in a virtual machine or in the cloud

When you need to test a new app or online service, the last thing you want to do is risk the PC you rely on for daily work. But setting up a separate physical computer requires a significant investment in hardware, not to mention the desk or workbench space that a secondary system occupies and the maintenance it requires.

A much better alternative to setting up a separate physical machine is to use a virtual machine (sometimes called a VM), which enables you to build a simulated “computer within a computer” that you can use without investing in any additional hardware or using any additional space in your physical environment.

A virtual machine 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. To connect to the VM, you open it in a window, which you can expand to occupy your full display, just as if you were connecting to a PC using a remote connection.

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.

Every business edition of Windows 11—Pro, Enterprise, and Education—includes a built-in hypervisor and associated management tools; an expanded set of virtualization tools is available in Windows Server. Collectively, these features are called Hyper-V.

Note

The Hyper-V feature set is included in Windows 10 as well. Using Hyper-V on a PC running Windows 10, you can install Windows 11 in a virtual environment without requiring an upgrade to the host PC’s operating system.

Virtualization in Windows 11

Setting up one or more virtual machines with the help of Hyper-V is especially useful for developers, IT pros, researchers, and even authors of books on computer operating systems. Consider the value of a VM in scenarios like the following:

  • You need to run an app that was written for an earlier version of Windows and does not work properly in Windows 11. Set up a virtual machine that runs the older version of Windows, install the outdated app in the VM, and use the VM exclusively for working with that app.

  • You’re a web developer and you need to test your website in different browsers and under different resource configurations. By setting up a virtual machine for each target configuration, you can reliably reproduce what your audience will see and adjust your code accordingly.

  • You’ve received a suspicious email attachment and you’re curious about what it does. Professional security researchers test software of unknown provenance or explore potentially dangerous websites using a virtual machine that’s properly isolated from the host PC and the host network. That allows them to examine possible malware without jeopardizing the host machine.

  • You want to test a new Insider version of Windows 11 or experiment with a non-Microsoft operating system such as Linux. You could set up a dual-boot configuration, but using a virtual machine allows you to switch between the alternative operating system and your host PC instantly, without rebooting.

Using a virtual machine makes it possible 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). That’s an invaluable feature for anyone producing documentation.

Virtual machines are also highly portable. You can move a VM to a new host by simply copying a few files.

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 discrete GPU to encode and decode video files, should be reserved for physical hardware. Likewise, any workload that depends on low latency and precise timing (including PC gaming) is likely to perform unacceptably in a VM.

To use Hyper-V, your system must meet certain minimum requirements, and you might need to enable the Hyper-V feature, as described later in this chapter. After those preliminaries are complete, you can use the Hyper-V Manager utility to create and manage virtual machines. With enough system resources, you can run multiple VMs simultaneously, each operating independently of the others. Because they function as separate computers, each VM 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.

Note

The hypervisor included in Windows 11 is also used to enable virtualization-based security features, such as Hypervisor-Enforced Code Integrity (HVCI). For more on this group of features, see Chapter 12, “Windows security and privacy.”

In addition to the option to create a virtual machine running Windows 11 on your own local PC, Microsoft offers a subscription-based service called Windows 365, which enables IT administrators to create virtual PCs that are hosted in the Microsoft Azure cloud. To learn more about this service, see “Running virtual machines from the cloud,” later in this chapter.

And if those options seem overly complicated or too resource-intensive, there’s a simpler alternative. A feature called Windows Sandbox, which is available in all Windows 11 business editions, allows you to create a lightweight, temporary Windows 11 virtual machine in seconds, with no additional configuration steps required. You can read more about this feature in the following section.

Creating an instant VM with Windows Sandbox

When you just want to check out a suspicious web link or test an app or online service, you don’t need to go through the time-consuming process of creating a virtual machine with Hyper-V and then deleting or resetting it after your experiment is complete. As an alternative, use the Windows Sandbox feature to build an extremely lightweight, clean, temporary virtual machine that’s ready in seconds, without requiring any additional downloads. When you close the sandbox, every trace of it is discarded, and your next session starts from a clean baseline.

Windows Sandbox uses the same underlying technology as the Hyper-V platform but runs independently. To use the feature, you must be running Windows 11 Pro, Enterprise, or Education, and hardware virtualization must be enabled in your PC’s firmware. If you satisfy both of those conditions, open the Windows Features dialog in Control Panel, select the Windows Sandbox checkbox, and click OK. (You do not need to enable any of the features under the Hyper-V heading to use Windows Sandbox.)

After you restart your PC, the Windows Sandbox shortcut will be available in the list of apps on Start. Click that shortcut to create and run a lightweight virtual machine immediately. The resizable Windows Sandbox window, shown in Figure 17-1, closely resembles a Hyper-V virtual machine, minus the toolbar and configuration options.

This screenshot shows the Windows Sandbox app in its own window, with the Settings app open showing system specifications and a nearly empty Start menu open

Figure 17-1 The Windows Sandbox runs the same Windows version and edition as the host PC but does not include any of the provisioned Windows apps except Microsoft Edge, File Explorer, and a handful of accessories like Notepad and Windows Media Player Legacy.

A few things are worth noting about these lightweight virtual machines:

  • The sandbox runs an unactivated copy of Windows 11; the edition and version match those 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.)

  • A small number of Windows accessories, administrative tools, and system utilities are available, including Notepad, Windows PowerShell, and Windows Media Player Legacy. With the noteworthy exception of File Explorer and the Microsoft Edge browser, however, no Windows 11 apps are installed or available.

  • Many administrative functions are disabled, including the ability to install updates and inspect disks and network configurations.

  • 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 resources available to the sandbox include 4 GB of virtual memory and a 40 GB system drive, although the amount of actual memory and disk space used is much smaller. The sandbox image itself is contained in a small virtual disk file stored in C:\ProgramData\Microsoft\Windows\Containers\Sandboxes\.

Note

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. For more on how enhanced sessions work, see “Running a virtual machine,” later in this chapter.

By design, Windows Sandbox is lightweight and simple, without a point-and-click interface for customizing the sandbox environment. However, you can create a custom configuration by editing a simple XML file. Including the value <MemoryInMB>8192</MemoryInMB>, for example, 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-sandbox-config-files.

To create a persistent virtual machine that you can modify and reuse, you need to use the full Hyper-V platform, as described in the next section.

Setting up Hyper-V on Windows 11

Hyper-V (or, more accurately, the Hyper-V role) has long been a power feature in server editions of Microsoft Windows, enabling 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.

Note

Although this chapter offers a thorough introduction to Windows-based virtualization, there’s plenty of technical detail that didn’t fit in these pages. For a more comprehensive reference, see the official documentation, “Hyper-V on Windows 10,” at https://learn.microsoft.com/virtualization/hyper-v-on-windows/. (Don’t be fooled by the title: The core features of Hyper-V in Windows 10 and Windows 11 are essentially identical.)

The feature sets of Client Hyper-V and its counterpart in Windows server editions overlap but are not a perfect match. Client Hyper-V in Windows 11 has the ability to create virtual machines that support Secure Boot and virtual Trusted Platform Modules; they also include support for nested virtualization, which allows virtual environments to host additional virtual machines.

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 app that enables 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.

You’ll find detailed coverage of both of these essential tools later in this chapter.

On hardware designed for earlier Windows versions, running Hyper-V required careful checking (and sometimes extra configuration steps) to ensure that the host computer’s CPU supported the necessary virtualization features. On a PC that meets the hardware requirements for Windows 11, these features are enabled by default, and extensive hardware compatibility checks aren’t necessary. The host PC must, however, be running Windows 11 Pro, Enterprise, or Education; Hyper-V features are unavailable on Windows 11 Home.

Beyond those basic compatibility requirements, the most important consideration is to ensure that the host PC has sufficient system resources (memory and disk space) to handle the intended workloads:

  • Although it’s possible to create and run a low-resource virtual machine on a host PC with 4 GB of total RAM, we recommend at least 8 GB of total RAM (and preferably 16 GB) for satisfactory performance with one or more virtual machines running Windows 10 or Windows 11.

  • 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, whether you use fixed or dynamically expanding 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, the only additional step required is to turn on the Hyper-V features, which are off by default. To do so, open the Windows Features dialog, shown in Figure 17-2. (The executable file for this system tool, OptionalFeatures.exe, is located in C:\Windows\System32. To open it quickly, click in the search box, type features, and then click Turn Windows Features On Or Off.)

This screenshot shows the Windows Features dialog, with the Hyper-V category expanded to show two additional groups of settings: Hyper-V Management Tools and Hyper-V Platform.

Figure 17-2 To install the Hyper-V hypervisor and all related tools and services, select the top-level Hyper-V checkbox in the Windows Features dialog.

Click the plus sign by the top-level Hyper-V entry to show all available subentries. 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

The Hyper-V Management Tools feature can be installed on any computer running any edition of Windows 10 or Windows 11. Therefore, even if the Hyper-V Platform entries are dimmed (which means your computer isn’t capable of hosting virtual machines), you can use Hyper-V Management Tools to manage virtual machines that are hosted on a different physical computer (in most cases, a computer running Window Server).

Creating and managing virtual machines with Hyper-V Manager

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

This screenshot shows the Hyper-V Manager window with three panes. A large block of text in the center is labeled “Introduction,” and a Connect To Server option is at the top of the pane on the right.

Figure 17-3 On a PC running Windows 11 Pro, you must select the PC from the pane on the left to work with existing VMs and create new ones.

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 enables you to connect to a different PC or server running Hyper-V.) That action reveals far more information and options, as shown in Figure 17-4.

This screenshot shows the Hyper-V Manager window with five entries in a list labeled “Virtual Machines” in the center pane, with a list of Checkpoints and an information pane at the bottom of the pane. Two menus with additional options are visible in the pane on the right, which is labeled “Actions.”

Figure 17-4 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 11 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 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 addresses have 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. In Figure 17-4, shown earlier, you can see the actions that apply to the Hyper-V host running on the local computer named EB-P5560 and to the virtual machine named “Windows 11 dev environment.”

In Windows 11, you have two options for creating a persistent virtual machine from within Hyper-V Manager. The Quick Create option allows you to create a VM with just a few clicks by downloading a predefined virtual machine image from an online collection; 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.

Before examining either of those options, though, let’s look at the architecture of a Hyper-V virtual machine.

What’s in a VM?

Creating and configuring a virtual machine doesn’t require any tools, nor does it involve connecting physical components like motherboards, solid-state drives, and memory modules. To build a virtual machine, you use point-and-click Hyper-V management tools to select from an assortment of standard virtual components and add them to your PC build. 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 the components that make up a Windows virtual machine by opening Device Manager within that machine. Figure 17-5, for example, shows Device Manager expanded to show a virtual disk, a virtual DVD-ROM drive, a virtual network adapter, two virtual storage controllers, and an assortment of virtual system devices on a virtual motherboard.

This screenshot shows a Device Manager window with seven categories expanded, each showing one or more devices with Hyper-V or “virtual” included in the device name.

Figure 17-5 Virtual machines are made up of virtual components, as you can see when you open Device Manager from within a VM running Windows 11, as shown here.

It’s considerably easier (and less expensive) 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.

We discuss the tools for creating and reconfiguring VMs later in this chapter. The remainder of this section covers 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 alternative 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 and Windows 11, Hyper-V supports two types of machines, each of which represents a different generation of virtual PC hardware:

  • 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, with support for modern technologies such as Secure Boot and UEFI built in. Among desktop operating systems, Windows 8, Windows 8.1, Windows 10, and Windows 11 are supported; it also supports Windows Server 2012 and later versions as a guest operating system. Generation 2 VMs also support all current Linux distributions.

Note

For a complete discussion of the differences between the two VM generations, including a list of supported operating systems, visit https://bit.ly/Gen1Gen2.

Generation 2 removes support for attaching physical DVD drives and other older hardware to a virtual machine, a feature required only for the most ancient operating systems. 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 modern Hyper-V features, such as the ability to adjust memory or add a network adapter while the virtual machine is running.

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 and Windows 11 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 memory in a range by setting two additional values: Minimum RAM and Maximum RAM. That configuration enables 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 17-6 shows memory usage in a VM that is configured with Dynamic Memory enabled and default settings in use, with Minimum RAM set to 512 MB and Maximum RAM set to 1 TB.

This screenshot shows Task Manager, with the Performance tab selected and a graph of memory usage in the pane on the right. The graph shows 1.8 GB of memory in use, with 2.6 GB of memory available. The value for Maximum Memory is 1.0 TB.

Figure 17-6 Unlike a physical PC, virtual machines can be configured with dynamic memory. This VM is currently using 2.6 GB of RAM but is authorized to use as much as it needs.

In that Task Manager window, you can see the current RAM usage, 2.6 GB, in the upper-right corner. That’s slightly more than the 2048 MB of RAM that was allocated at startup, which means this VM has already taken advantage of its ability to ask for additional memory when needed. The Maximum Memory value at the bottom right shows that this VM is ready and able to increase its RAM to as much as necessary. No, the host PC does not have a terabyte of RAM available, but specifying that extremely high default value means that the VM has permission to use as much physical RAM as 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 a VM to run with a fixed amount of RAM, clear the Dynamic Memory checkbox to disable that option.

You’ll find a discussion of the different ways to manage memory usage in VM configurations later in this chapter.

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 and Windows 11 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 are an esoteric format primarily intended for use with failover clusters of multiple virtual machines running Windows Server editions and are not intended for use on desktop PCs running Windows 10 or Windows 11.)

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 uses 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 use a shared drive by specifying a virtual disk file that already exists. If you have a spare physical disk partition available, you can attach that physical drive to it directly rather than using a virtual disk. This option offers excellent performance but is impractical on most desktop configurations.

Generation 1 VMs can directly connect to a physical CD/DVD drive. VMs of either generation can use 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 on a Generation 1 machine.

You’ll find more about the mechanics of creating and managing virtual disks later in this chapter.

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 with a network adapter but is not connected to the network; this configuration is equivalent to a standalone computer with a wired network card (and no Wi-Fi adapter) that isn’t plugged into a router or switch and thus can’t connect to the internet or to other computers. That disconnected configuration might be useful for some testing scenarios, but for most situations, you 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.

In Hyper-V on Windows 11, 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 Virtual Switch dropdown. (See “Configure networking,” later in this chapter.)

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 when you want your VM to behave as if it were another PC on your local network. This configuration binds the virtual switch to the host PC’s physical network adapter so that you can access your physical network. Assuming the host PC’s 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 other virtual machines using the same virtual switch on the host PC but isolates them from other devices on the host PC’s network; those VMs can also connect 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. Without additional configuration steps, it has no internet connectivity.

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

This screenshot shows the Virtual Switch Manager dialog, with two virtual switches in a tree pane on the left and settings on the right for Name, Notes, and Connection Type.

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

Using Quick Create to download and run a preconfigured VM

The Quick Create command appears at the top of the Actions pane on the right side of Hyper-V Manager when you’ve selected the host PC in the left pane. Clicking Quick Create opens a Create Virtual Machine dialog like the one shown in Figure 17-8. From this dialog, you can choose one of the predefined virtual disk images available from Microsoft, as shown here.

This screenshot shows the Create Virtual Machine dialog with icons and labels for five operating systems in a list on the left and Windows 11 Dev Environment selected. A large blue Create Virtual Machine button is in the lower right.

Figure 17-8 Clicking Quick Create opens this dialog, containing links to preconfigured VMs available for download from Microsoft’s servers.

Over time, the number of ready-made virtual machines available in the Hyper-V gallery has increased. The MSIX Packaging Tool Environment and the Windows 11 Dev Environment packages, for example, are built using evaluation versions of Windows 10 and Windows 11 Enterprise, respectively. Each requires a download of several gigabytes, and the evaluation license expires after 90 days. The three Ubuntu packages, by contrast, enable you to set up a VM running this popular Linux distribution with no such restrictions; each requires a download of roughly 2 GB.

In addition to the packages Microsoft provides in this default gallery, IT professionals can make custom images available for internal development and test groups. For details on how to add your own virtual machine images to the Quick Create gallery, see this post from Microsoft’s Thomas Maurer: https://bit.ly/hyper-v-custom-gallery.

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, select Local Installation Source, click the Change Installation Source button, and navigate to the ISO file you want to use for installation or the virtual hard disk you want to use as a template. The file must be in the form of an ISO image or a VHD/VHDX disk image. Figure 17-9 shows this option in use with a previously created virtual machine running an Insider release of Windows 11.

This screenshot shows the Create Virtual machine dialog, with Local Installation Source chosen from the bottom of the list on the left. To its right is a label with the name of a Windows 11 VHDX file and a Change Installation Source button.

Figure 17-9 Choosing the Local Installation Source option enables you to quickly create a VM with ISO-based installation media or using a virtual hard disk as a template.

The checkbox under Change Installation Source enables Secure Boot, a feature of UEFI-based computers. 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:

  • Name The text you enter here is 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 with two buttons. The first allows you to connect to the VM immediately; the second opens the Settings dialog for the new VM, where you can adjust the amount of memory, tinker with hard drives, and make any other necessary changes.

Building a custom VM with the New Virtual Machine Wizard

If you want step-by-step control over the process of creating a new VM, the Quick Create option is not for you. 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 successive step of the wizard.

Note

For fast results, you can open the New Virtual Machine Wizard and immediately click Finish. As it turns out, however, that upfront efficiency is just an illusion, as is the corresponding Quick Create option. When using the wizard in this fashion, you’ll need to spend time and effort later manually changing the generic default name for the VM and the virtual hard disk, adjusting the size of available memory, and attaching installation media. In addition, the default settings create a Generation 1 VM, which can’t be changed to a Generation 2 configuration.

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 helps 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 checkbox and specify another, as shown in Figure 17-10.

This screenshot shows the Specify Name And Location page of the New Virtual Machine Wizard, with a name field and a series of boxes for specifying the location of the VM files.

Figure 17-10 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 and a larger data drive—a common configuration in some desktop systems that use a solid-state 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 in Figure 17-11, select either Generation 1 or Generation 2 for the style of virtual machine you need. (For a discussion of the differences, see “Machine generation,” earlier in this chapter.)

This screenshot shows the Specify Generation page of the New Virtual Machine Wizard, with two options available for choosing a Generation 1 or Generation 2 virtual machine.

Figure 17-11 For modern operating systems, choose a Generation 2 VM. Use the older alternative for Windows 7 and other older operating systems.

If you’re going to install a current, 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 17-12, 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. (For an explanation of how dynamic memory works, see “Memory,” earlier in this chapter.)

This screenshot shows the Assign Memory page from the New Virtual Machine Wizard with the value 8192 MB entered in the Startup Memory box and the Use Dynamic Memory box below it selected.

Figure 17-12 Selecting the Use Dynamic Memory For This Virtual Machine checkbox enables your VM to use memory more efficiently, which can improve performance when physical memory is scarce.

Note that the wizard does not allow you to specify values for Minimum RAM and Maximum RAM. Instead, if you use the New Virtual Machine Wizard and enable dynamic memory, Hyper-V assigns 512 MB and 1.0 TB, respectively. You can exercise far more granular control over memory by adjusting the settings for a VM after you create it, as explained a bit later in this chapter.

Configure networking

On the Configure Networking page, shown in Figure 17-13, 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 (which uses NAT to connect to your computer’s network) or select a virtual network switch you created previously.

This screenshot shows the Configure Networking page of the New Virtual Machine Wizard, with a single option labeled Connection, and Default Switch selected from that list.

Figure 17-13 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 17-14, 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. (You also have the option to specify the location of an existing file in VHDX format.) 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.

Just as with 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.

This screenshot shows the Connect Virtual Hard Disk page of the New Virtual Machine Wizard, with three options. Create A Virtual Hard Disk is selected, with values for Name, Location, and Size below it.

Figure 17-14 With the first option, you create a virtual hard disk. Choose the second option to use a virtual hard disk that already exists.

In addition to specifying the name and location of your virtual hard disk file, you must specify the disk’s capacity, in gigabytes. Be sure you create a virtual hard disk that’s big enough to store the operating system, apps, and data you plan to use on the virtual machine. Although you don’t want to go overboard, don’t worry too much about specifying a size that’s too big. As noted earlier, a dynamically expanding VHDX file starts small and can grow as needed; just make sure the location you choose on the physical disk has enough space to accommodate the virtual drive file as it grows.

Note

Changing the name or location of a virtual hard disk is a tedious process that requires multiple steps. Likewise, resizing a virtual hard disk after it has been created involves tinkering with partitions in the virtual machine. To avoid those hassles, it’s worth putting some thought into getting this setting right from the start.

If you have an existing virtual hard disk you want to use instead of creating a new one, select the second option on this wizard page.

Installation options

The Installation Options page, shown in Figure 17-15, enables 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.)

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 screenshot shows the Installation Options page of the New Virtual Machine Wizard, with three options for installing an operating system below it. The second option, Install An Operating System From A Bootable Image File, is selected, and the box below it includes a path to an ISO file.

Figure 17-15 These options are available for a Generation 2 VM. Generation 1 VMs allow installation of an operating system from a physical DVD or a virtual floppy disk.

This brings you to a Summary page, where you can review your settings before clicking Finish to complete the wizard.

Even after clicking Finish, you still have a few choices to make before working with your new virtual machine. In Hyper-V Manager, you can select the newly created VM and then fine-tune its settings (as described in the following section). When you’re satisfied with those settings, 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. If you created a new, blank virtual disk and attached an ISO file containing Windows installation media, Hyper-V launches the operating-system setup from the location you specified in the wizard.

Running a virtual machine

Double-clicking the name of a virtual machine in Hyper-V Manager opens that VM in a Virtual Machine Connection (VMConnect) window. If the VM is already running, you’ll be taken to the machine in its current state. For a newly created VM that you’re running for the first time, or for a previously created VM that’s shut down or sleeping, you’ll need to click Start to power on the machine. (You can use the button in the connection window or on the toolbar, or click Action > Start from the Virtual Machine Connection menu bar.)

When you run a session in a Virtual Machine Connection window, you can use 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. This is the only option available for VMs running Windows Home edition (regardless of version).

  • Enhanced sessions 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 also support higher display resolutions and can use multitouch displays and multiple-monitor configurations.

Enhanced session mode uses Remote Desktop Protocol over the virtual machine bus (VMBus), which requires a supported guest operating system: Windows 8.1 or later (Pro, Enterprise, or Education edition) 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, which is not supported on Home edition, 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 17-16, 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.

This screenshot shows the Windows 11 sign in screen, with the author’s username and a box for entering a PIN. It’s contained within the Virtual Machine Connection window, which includes a menu bar and a row of buttons on a toolbar.

Figure 17-16 A Windows VM in a Virtual Machine Connection window enables you to create multiple user accounts and sign in using a password or a PIN.

Use the toolbar at the top of the window, as shown in Figure 17-17, to operate the virtual machine. Additional options are available on the menu bar above it.

This screenshot shows the upper-left corner of the Virtual Machine Connection window, with the name of the virtual machine in the title bar, six menu options in a row below the title bar, and 11 buttons in a row below the menu bar.

Figure 17-17 It’s worth memorizing what each of the buttons on this toolbar does.

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

  • Ctrl+Alt+Del Because the Ctrl+Alt+Del key combination is reserved by Windows 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 tap this toolbar button.

  • Start This button turns on a virtual machine that is currently not running. If the VM is running, it’s grayed out and unavailable.

  • Turn Off This button turns the virtual machine off, but it does so in the most drastic manner possible, with the same effect as unplugging a physical PC. This is, of course, not the most graceful way to shut down a computer (even a virtual one), and you’ll probably lose any unsaved data.

  • Shut Down Clicking this button is equivalent to using the Shut Down command in Windows 10 or Windows 11; it instructs the machine to go through the usual shutdown process. Note that some 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. For more information, see “Working with checkpoints” later in this chapter.

  • 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 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. (For more details on this option, see “Importing, exporting, and moving Hyper-V VMs,” later in this chapter.

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 a 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 storage devices, audio devices, and some other local resources work only in enhanced session mode. (For more information, see the following section.)

When you close the Virtual Machine Connection window, the virtual machine continues to run. By closing the window, all you’re doing, in effect, is turning off the virtual monitor. To shut down or turn off the entire virtual machine, you should use the appropriate buttons on the Virtual Machine Connection window. If that window is closed, you can access these functions by opening Hyper-V Manager, selecting the VM’s entry, and using the Turn Off, Shut Down, and Save options in the Actions pane.

Using enhanced session mode

Running a Hyper-V basic session in a window is convenient and adequate for simple tasks. But that option comes with significant limitations, including a lack of support for audio playback and an inability to share files between the host PC and the VM using the Windows Clipboard.

The solution to these and other problems is enhanced session mode, which allows you to connect to the following resources on your host computer from a Hyper-V virtual machine:

  • Audio devices

  • Printers

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

In enhanced session mode, you can’t change the resolution of the virtual display using commands within the virtual machine. Within the VM, the Display Resolution option in Settings > System > Display is grayed out and unavailable, and this message appears: “Display settings can’t be changed from a remote session.” (Recall that enhanced session mode uses Remote Desktop Protocol to connect to the virtual machine, which explains the message about a “remote session.”) There are two workarounds to this limitation:

  • If the VM is running in a window, you can change the display resolution by dragging the borders of the Virtual Machine Connection window; when you do so, the guest operating system automatically adjusts to the dimensions. This solution, while convenient, makes it nearly impossible to choose a standard resolution—which might, for example, be a requirement for compatibility testing.

  • To choose a specific display resolution, switch to basic session mode and then close the Virtual Machine Connection window. In Hyper-V Manager, click Connect to open a new Virtual Machine Connection window to be greeted by a dialog in which you can specify the screen resolution, as shown in Figure 17-18.

In this same dialog, clicking Show Options expands the dialog to show a Local Resources tab. There, you can specify which local resources—that is, printers, drives, and other devices from the host computer—you want to use within the virtual machine. For more information about these settings, see “Connecting to another computer with Remote Desktop” in Chapter 11, “Configuring Windows networks.”

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. (Use that icon as a shortcut to determine whether you’re running in basic or enhanced session mode.)

You can enable and disable enhanced session mode on a per-server or per-user basis. To view or change either setting, open Hyper-V Manager and select the host name from the tree on the left; then, under the host name in the Actions pane, click or tap Hyper-V Settings. In the Hyper-V Settings dialog that appears, you’ll find enhanced-session-mode settings under Server and User.

This screenshot shows the Virtual Machine Connection window, with a Connect dialog in the center, containing a slider labeled Display Configuration that is currently set to 1366 by 768 pixels. A Connect button is in the lower right.

Figure 17-18 Use the slider to choose a specific resolution if you want your VM to run in a window. Move the slider all the way to the right if you want to use the host machine’s display at its full resolution.

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 all the way to the right, until it reads Full Screen. If your host PC has multiple monitors, select the Use All My Monitors checkbox. 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 connection bar at the top of the screen. That bar includes the name of the VM and the host PC in the center, as well as 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. When evaluating competing software products, for example, you can install an app in a VM and conduct your tests and then revert to the previous checkpoint to start another round of testing with a different app under starting conditions that are exactly the same as they were in 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 Manager window, as shown in Figure 17-19. To revert to an earlier checkpoint, select the checkpoint and, in the Actions pane, click or tap Apply.

This screenshot shows the Hyper-V Manager with a window labeled Checkpoints in the center. From the tree-style list, a checkpoint named Before Installing Contoso AV Software is selected, and a group of actions are available on the right.

Figure 17-19 When you select the name of a checkpoint, a list of applicable actions for that checkpoint appears in the Actions pane for that VM.

Other options in the Actions pane enable you to rename a checkpoint, delete a checkpoint or checkpoint subtree, and export the saved checkpoint to a new VM, leaving the original undisturbed.

In Windows 10 and Windows 11, Hyper-V supports two kinds of checkpoints:

  • Standard checkpoints include information on the virtual machine state, running applications, and network connections. That’s useful if you’re trying to return to a specific point in time. As a result, restoring a VM to its previous state from a standard checkpoint might take you to an unstable condition (for example, the same network connections might not be available).

  • Production checkpoints use 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 solution that is much more useful as a backup alternative but is inappropriate when you’re trying to start with a specific state.

Standard checkpoints are the default for new VMs you create; to check the current Checkpoint settings and make any changes, open Settings for a virtual machine and, under Management, click Checkpoints. That opens a dialog like the one shown in Figure 17-20.

This screenshot shows the Settings dialog for a Hyper-V virtual machine with Checkpoints selected in the left pane and multiple options on the right. The Enable Checkpoints option is selected, with the Standard Checkpoints option chosen instead of Production Checkpoints.

Figure 17-20 Use this page in the settings for a VM to enable or disable checkpoints and to choose a checkpoint type.

On that same dialog is a Use Automatic Checkpoints checkbox. This option automatically creates a checkpoint each time you start a VM, giving you the option to roll back any changes you make in the current session 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 and Windows 11 VMs.

Checkpoints can use large amounts of disk space. On host PCs where storage is scarce, consider disabling automatic checkpoints and using them only when necessary.

Changing settings for a virtual machine

As 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.)

This Settings dialog (which we visited briefly in Figure 17-20 in the previous section) contains two groups of options: one for the virtual hardware and the other for management settings. Some of these 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).

Note that some hardware options available here differ slightly, depending on the machine generation. The remainder of this section summarizes options available in the virtual hardware for Generation 2 VMs, which covers most mainstream uses for a Hyper-V virtual machine.

Firmware

This section enables you to define the boot order for a virtual machine. If you’re working with a Generation 2 VM running Windows 10 or Windows 11, the boot order starts with an EFI Boot Manager file. If you want to boot from a virtual DVD by default, adjust these settings so that the DVD Drive option is first in the list.

Security

On Generation 2 VMs, the options available when Security is selected offer features that are equivalent to those you get with Windows 11 running on a UEFI-based physical PC. If you plan to run Windows 11 in a Hyper-V VM, you should start by enabling Secure Boot and the virtual Trusted Platform Module (TPM), as shown in Figure 17-21, before you run Windows Setup. (The latter option also allows the disks in a virtual machine to be encrypted with BitLocker Disk Encryption.)

This screenshot shows the settings for a Windows 11 virtual machine, with the Security tab selected. On the right side of the dialog, the options to enable Secure Boot and the Trusted Platform Module are selected.

Figure 17-21 If you plan to install Windows 11 in a virtual machine, be sure to enable Secure Boot and the virtual Trusted Platform Module before you run Setup.

In this example, it’s worth noting 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.)

Memory

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 17-22, for example, shows the memory configuration for a VM running an Insider Preview release of Windows 11. In this example, the Minimum RAM setting is increased from its default value of 512 MB to 4096 MB, and the default Maximum RAM value is lowered from its insanely high value to 8192 MB.

This screenshot shows the virtual memory settings for a Hyper-V VM, with dynamic memory enabled and a range of 4096 MB to 8192 MB set.

Figure 17-22 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.

There’s no right or wrong way to adjust these settings, which depend on how you plan to use the VM. For example, if you’re testing a Windows Insider Preview build of Windows 11 and you plan to switch to that VM as soon as you start up your host PC, without running any additional apps on the host PC, you can safely allocate an amount of RAM equal to the total physical RAM on your system. By contrast, if your goal is to have two VMs running in the background at all times while you do your daily productivity tasks on the host PC, you’ll want to restrict the amount of RAM for those VMs, even if that means they occasionally encounter some memory pressure.

Using dynamic memory ensures that each machine gets as much memory as it needs, but it doesn’t reserve a fixed amount of memory (which would preclude other virtual machines or the host operating system from using that memory).

If you plan to run only one virtual machine, or if you know how much memory your virtual machine needs to perform its given tasks, you can turn off dynamic memory and specify a fixed amount of memory. This setup works more like a physical computer, in that whatever memory you specify is equal to the total amount of installed RAM in the virtual machine.

Processor

The Processor settings you see here were originally designed for Hyper-V on servers containing multiple processors and were irrelevant on desktop PCs running Windows 10. But with the release of Windows 11 and its insistence on minimum hardware requirements, these settings suddenly became more important. Virtually all modern PCs contain a single processor with multiple cores, but the default settings for Hyper-V assign only a single core to a virtual machine. That detail causes Windows 11 installations in a Hyper-V VM to fail almost immediately.

The solution is to increase the value in the Number of Virtual Processors field to at least 2, as shown in Figure 17-23. This change has no impact on performance, and the remainder of the settings on this page are irrelevant for any VM using Hyper-V on Windows 11.

This screenshot shows the Processor settings for a Hyper-V VM, with the number of virtual processors set to 4. Several additional options are available beneath that setting.

Figure 17-23 If you plan to install Windows 11 in a VM, you need to increase the number of virtual processors shown here.

SCSI Controller

Generation 2 VMs include a single virtual disk controller that uses the Small Computer System Interface (SCSI) and is capable of handling multiple 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.

Note

Generation 1 machines by default use legacy IDE controllers, and the system disk must be attached to an IDE controller. (You also have the option to choose the legacy VHD disk format; for Generation 2 machines, the default format is VHDX and the older format is unavailable.) Each of the two IDE controllers on a Generation 1 machine can connect up to two devices. If you attempt to connect a new secondary drive to a controller that already has two devices attached, your attempt fails with an error message. If both of the default IDE controllers are full, use the SCSI Controller instead.

Adding a new virtual disk

To add a new virtual disk to an existing VM, make sure the VM is shut down and then 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 17-24.

    This screenshot shows the Hard Drive settings for a virtual machine, with the Virtual Hard Disk option selected and two buttons available below it, New and Browse.

    Figure 17-24 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:

    • 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. (For an explanation of how each type is used, see “Storage controllers and virtual disks,” earlier in this chapter.)

    • Specify Name And Location Change the default filename (“New Virtual Hard Disk.vhdx”) to something descriptive, and adjust the location if necessary.

    • Configure Disk Accept or change the default size of 127 GB and create a new, blank virtual hard disk, as shown in Figure 17-25, or select one of the other options to copy the contents of an existing physical or virtual disk to the newly created disk.

      This screenshot shows the Configure Disk page from the New Virtual Hard Disk Wizard. Create A New Blank Virtual Hard Disk is selected, with a size of 127 GB. Two additional options below that enable you to copy a physical or virtual hard disk.

      Figure 17-25 These settings create a dynamically expanding virtual hard disk that has a capacity of 127 GB within the VM but uses minimal disk space on the host PC.

  4. Complete the wizard to add your hard disk.

Note that this sequence is the equivalent of attaching a new, unformatted drive to a physical PC. If the virtual machine is running Windows, you 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 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 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 and then, on the right, click Inspect. That opens a small dialog 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 (see “Working with checkpoints,” earlier in this chapter). After doing so, shut down the VM, select the hard disk from the Settings dialog, and click Edit. That opens yet another wizard, with Compact, Convert, and Expand options that are relatively easy to follow.

Caution

Changing the format, disk type, or size of a virtual hard disk runs a small but meaningful chance of data loss. As a precaution, we recommend backing up the VHD/VHDX file before performing the conversion or resizing.

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 need to open the VM and use Disk Management to expand the volume to use the newly added space.

Network Adapter

For just about any mainstream computing task, the default network adapter is sufficient, and there’s no need to make any changes. The main reason to use this dialog is to choose a different virtual switch—if you’re moving between wired and wireless networks on the host PC, for example. Networking experts might want to explore some of the options here, such as the ability to spoof a MAC address so that your VM’s packets appear to come from another device on the network. You can find that option by expanding the properties under the Network Adapter heading and then clicking Advanced.

Automatic start and stop actions

Use the final two options under the Management heading to specify what happens to a virtual machine when you shut down or start the Hyper-V host PC. 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.

Importing, exporting, and moving Hyper-V VMs

How do you move or copy a virtual machine from one Windows PC to another? Using Windows 11, 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 Hyper-V Manager, select the VM and click Export in the Actions menu. In the resulting dialog, 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.

To import the VM on the new PC, open Hyper-V Manager and click Import Virtual Machine from the Actions menu. In the Import Virtual Machine Wizard, browse to the location that contains the exported files and then choose one of the three options on the Choose Import Type page:

  • Register The Virtual Machine In-Place (Use The Existing Unique ID) Use this option if you are permanently moving the VM to the new Hyper-V host and you want to use the exported files in their current location. This option makes sense if you copied the files to a dedicated Hyper-V data folder on the new PC, for example.

  • Restore The Virtual Machine (Use The Existing Unique ID) Use this option if you want to permanently move the VM to the new Hyper-V host and, as part of the import, copy the exported files to the default location on the new PC. The exported files remain in place on the storage device you used for the transfer.

  • Copy The Virtual Machine (Create A New Unique ID) This option is appropriate if you plan to continue using the old VM and you want to create an independent copy of the VM on the new Hyper-V host. For a Windows VM, note that choosing this method will probably require reactivation.

A slightly simpler alternative is the Share option. From a VM that’s running in a Virtual Machine Connection window, click the Share button (the rightmost button on the VMConnect toolbar) or press Ctrl+H. That action copies the virtual machine configuration and data files (but not checkpoints) to a compressed file in VMCZ format. Copy that file to the new Hyper-V host and double-click to restore the VM to default locations.

Finally, if you’ve run out of disk space on the host PC and need to move all or part of a VM to a new, more capacious drive, shut down the VM and click Move. The resulting wizard enables you to move virtual disk storage or an entire virtual machine to a new location or locations of your choosing. The VM remains registered in Hyper-V Manager; only the location of associated data files changes.

Running virtual machines from the cloud

Client Hyper-V is the easiest way to work with virtual machines in Windows 11, but it’s not the only way. Two relatively new options provide cloud-based alternatives that might make sense if you’re a candidate for virtualization.

Windows 365 is a subscription-based product that uses virtual machines hosted in a cloud service run by Microsoft. Each Windows virtual machine, called a Cloud PC, is created with Windows 11 installed by default, although administrators can choose to use Windows 10 instead. A Cloud PC is assigned to an individual user and functions as their secure, dedicated work PC, with access available through a web browser, through Remote Desktop apps on a desktop PC or Mac, or through mobile clients available on iOS and Android devices.

The service is available in two subscription types: Windows 365 Business is for organizations with up to 300 users or Windows 365 Enterprise is for larger organizations. For more information, see https://learn.microsoft.com/windows-365/.

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 and are ideal for test environments and important servers where downtime is not an acceptable option. Every Visual Studio subscription includes a monthly allowance for Azure usage, with ready-made Windows and Linux VMs available. For more details, see https://azure.microsoft.com/services/virtual-machines/.