Navigation
Recherche
|
How to set up Windows 11 Hyper-V virtual machines
vendredi 6 septembre 2024, 16:34 , par ComputerWorld
Though it may seem that virtual machines, a.k.a. VMs, have been around forever, Microsoft introduced its first version of the Hyper-V virtualization environment as part of Windows Server 2008. Hyper-V and its VMs didn’t appear in a Windows desktop operating system until May 2012 with the Windows 8 technical preview.
Since then, however, Hyper-V VMs have come to represent approximately 1 in every 10 VMs in global use. This is no small number, given that the cloud more or less runs on VMs of one kind or another. We’re talking billions and billions (and not hamburgers, either). That said, Windows 11 users and admins have plenty of good reasons to run VMs on PCs on a vastly smaller scale than in the cloud. Among them are: The ability to run multiple OSes, including various versions of Windows 10 and 11 (or older, unsupported versions), Linux, and more, side-by-side. Among other benefits, this lets users run legacy applications not compatible with Windows 11. Supports virtual networks, complete with virtualized gateways, routers, servers, and network nodes on one or more private or public networks. Supports easy isolation and testing, useful to testing software, experimenting with specific configurations, and avoiding device or software conflicts with the host PC. Enables superior backup and disaster recovery capabilities, thanks to checkpoint and snapshot mechanisms, with recovery to other PCs or into the cloud easily done. Works through remote access and management, so that VMs can be maintained across multiple devices and locations, with secure boot, live migration, and lots of options for network storage. Microsoft provides two tools for creating Hyper-V VMs in Windows 11. In this guide I’ll provide some background, discuss how to use each tool, and detail the drawbacks each entails. In this article: Understanding VMs and hypervisors Requirements for a Windows 11 VM Creating VMs with Hyper-V Manager Creating VMs with Dev Home (Preview) Net-Net: It really could be easier Understanding VMs and hypervisors Hyper-V is a kind of hypervisor: a program that can create, run, and manage one or more virtual machines on some kind of physical computer. Essentially, a hypervisor creates a runtime environment in which an administrator can define the properties of one or more VMs that run in its embrace. Such properties include virtual processors and cores, virtual memory, virtual storage, virtual networking connections, and a virtualized operating system. VMs use such resources to run commands, programs, and more, each inside its own independent and isolated runtime environment. From inside a VM, Windows looks and runs as it would on any computer. From outside the VM, the hypervisor handles interactions with the host OS and translates between virtual resources allocated to the VM and physical resources made available to the hypervisor. PCs that run Hyper-V Manager (the hypervisor built into Windows) or other hypervisors, such as VMware Workstation, are called host PCs, where individual VMs function as hypervisor clients. Requirements for a Windows 11 VM Because a Windows VM represents an instance of a virtualized Windows operating system, Windows 11 VMs inherit the system requirements for Windows 11 itself. Hyper-V adds additional items to this list (they’re preceded by an asterisk): * Windows Edition: Windows 11 Enterprise, Education, or Pro. (Windows 11 Home does not support Hyper-V.) CPU: A 1.0GHz (or faster), 64-bit ARM or x86 CPU that supports second-level address translation (SLAT is its Intel name, RVI its AMD name, and “Stage-2 page tables” is what ARM calls it) is needed to run Windows 11 inside Hyper-V. Windows 11 also imposes CPU requirements for SSE4.2 instruction support for 24H2 or newer OS versions (specifically, the POPCNT instruction must be available). RAM: Windows 11 VMs need at least 4GB of RAM to operate, ideally on a physical PC equipped with 8GB RAM (or more). For Windows PCs that will run Hyper-V, you’ll want at least 4GB of RAM for the base OS and at least 4GB more for each VM you want to run in parallel. Thus, a Windows 11 PC with 32GB of RAM could handle up to seven Windows 11 VMs, but no more than that. Fewer is better, in fact. Graphics: The physical PC should support DirectX 12 or higher as well as a WDDM 2.0 (or higher) driver. Display resolution to accommodate a VM window should be 720p (1280 x 720 pixels) or better. This is the same as for the Windows 11 OS itself. * VM generation: VMs come in two forms: Generation 1 and Generation 2. A Gen 1 VM uses BIOS firmware and supports only limited hardware devices and features. A Gen 2 VM uses UEFI firmware and supports a much wider range of hardware devices and features. Microsoft recommends that admins always create generation 2 VMs if they can. Indeed, Windows 11 works only on a Gen 2 VM. Other noteworthy requirements: The physical PC should support the Trusted Platform Module (TPM) version 2.0 and UEFI with Secure Boot. Nearly all PCs built in mid-2018 or later should meet these requirements with ease, although TPM 2.0 must be enabled on some PCs. Today, there are two ways to set up a Hyper-V VM in Windows 11: the standard way, and a developer-oriented way. The standard way uses Hyper-V Manager to create and configure VMs. The developer-oriented way, which made its debut in April 2024, uses a Microsoft utility named Dev Home (Preview). It’s available from the Microsoft Store. As you will see, the developer-oriented way is simpler and less fraught with obstacles than the traditional one. But there’s a catch, as I’ll explain in the Dev Home section below. Creating VMs with Hyper-V Manager Although Hyper-V is included with modern Windows versions, it is not enabled by default. Thus, you must first turn Hyper-V on using the Windows Features element from Control Panel (Control Panel > Programs and Features > Turn Windows features on or off). Turn on Hyper-V Manager Click the top-level Hyper-V item. When you do so, you’re turning on both the Hyper-V platform itself (Hyper-V Platform) and Hyper-V Management Tools to run VMs through the Hyper-V Manager or through some remote access toolset (e.g., the Remote Desktop Connection, a.k.a. mstsc.exe, or the Remote Desktop app, ID=9WZDNCRFJ3PS). I usually turn on the item labeled Windows Hypervisor Platform as well, as shown in Figure 1. Once you’ve selected these items, click OK and Windows will install and enable them for you. Figure 1: Turn on top-level Hyper-V and the Windows Hypervisor Platform elements. Ed Tittel / IDG Windows Features will find, install and enable the elements necessary to run Hyper-V Manager — and along with it, the support necessary to run Hyper-V VMs inside its embrace. When Windows Features is done, it reports: “Windows completed the requested changes.” It also informs you that a reboot is needed to finish the installation process. Thus, you must restart the PC before you can run or use the Hyper-V platform in any way. The easiest way to do that is simply to click the “Restart now” button at the lower right in Figure 2. Figure 2: Click “Restart now” to get your PC ready for Hyper-V VM action! Ed Tittel / IDG After the reboot, typing “hyper” into the Start menu search box brings Hyper-V Manager up as its first choice, as shown in Figure 3. Figure 3: Once rebooted, Hyper-V Manager is ready to run. Ed Tittel / IDG Run VM Quick Create using a provided OS Accessing Hyper-V Manager from its host desktop — also known as running local, or local invocation — turns out to be the easiest way to set up a Hyper-V VM. The first time Hyper-V Manager is run, there’s literally nothing to see because no VMs are known to it yet. As you can see in Figure 4, each of the center panes for Hyper-V Manager reports “No VMs” or “No item.” Figure 4: When run for the first time, Hyper-V Manager shows precisely nothing. Ed Tittel / IDG If you click Quick Create, the top item in the right-hand menu you can soon remedy this situation. By default, Microsoft provides pointers to various predefined runtime environments, including evaluation versions of Windows 10 and 11 aimed at developers and (until early July) three different Long Term Servicing (LTS) branches for Ubuntu Linux (which may be freely offered to anyone who’s interested). The right-hand side of Figure 5 shows the details for the “Windows 11 dev environment” item, an evaluation copy worth installing as a short-lived example. Select the OS you want to install and click Create Virtual Machine. Figure 5: Select Windows 11 dev environment (left), then click Create Virtual Machine (lower right). Ed Tittel / IDG This downloads a ~21GB Windows image file. (On my Lenovo P16 Mobile Workstation, a 12th-Gen x86 platform, that took about 5 minutes to complete, including image verification.) Then, Hyper-V Manager creates a VM, extracts the virtual boot/system disk, verifies the image again, and completes (this takes another 5 minutes or so), as announced in Figure 6. Click Connect to hook up the new test VM inside Hyper-V Manager. Figure 6: VM successfully created. Next step: click Connect. Ed Tittel / IDG What happens next is that Hyper-V Manager opens a virtual machine window. You must start the VM to turn it on, as shown in Figure 7. If you were using an ISO (covered in a moment), this is when the process of installing Windows inside the VM would occur. Figure 7: Before you can interact with a VM, you must start it up: click Start! Ed Tittel / IDG But because Microsoft has so kindly provided us with a predefined, ready-to-run VM for this development environment, clicking Start launches a boot-up screen (“Getting ready”) that grinds away for a minute or so. After that you’ll be able to log in to a Windows 11 desktop (account name User, no password). There’s your first Hyper-V VM! Though this takes at least 15 minutes to work through, it’s about as fast and easy as creating a VM ever gets. Figure 8 shows the VM running inside a Hyper-V Virtual Machine Connection window (see the legend on the title bar for confirmation). Figure 8: The Windows 11 Dev Environment VM start menu shows a developer focus. Ed Tittel / IDG Setting up a VM from a predefined virtual hard disk (.vhdx file and configuration information) is incredibly simple. Basically, it means turning on and running an already set up VM that’s more or less ready to run. VM Quick Create using an ISO You can see another option for creating VMs if you look back to Figure 5, where you can navigate into a “Local installation source” by clicking that button at the lower left corner of the “Create Virtual Machine” window. This lets you navigate into local drives and pick an ISO — a disk image format used for Windows installations — from which to run VM setup. (See “The best places to find Windows ISOs” for some reliable sources.) That approach offers the ability to pick any Windows version you might like, but because it requires OS installation into a new VM, it takes longer to work through. There’s more effort involved in getting configuration right, too. By clicking the Local Installation source button shown in Figure 5 and navigating to the root of my E: drive where a May 30 Windows 11 Insider Preview ISO resides, I made it a target for a Hyper-V VM. You can see the results of this election in Figure 9, from whence you must click Create Virtual Machine (lower right) to proceed further with a local ISO. Figure 9: By targeting an ISO through File Explorer, you open VM creation options to whatever the file system can see. Ed Tittel / IDG This time when you click Create Virtual Machine, the Hyper-V wizard works from the ISO. Because I accepted all defaults, this VM shows up as “New Virtual Machine” in Hyper-V Manager. I right-clicked that string in the top center pane (“Virtual Machines” and selected Rename from the pop-up menu to call it “Win11.26100.” It appears as such in Figure 10. Figure 10: Renamed to Win11.26100 (for its primary Windows 11 build number), the new VM must now be installed. Ed Tittel / IDG Because we’re working from an ISO file, we must now install this OS image before it can run as a VM. This is where timing becomes sensitive: once you click Connect, then click the Start button, you must be ready to hit the proverbial “any key” (because any key will do) to start the installer running. If you wait too long, you’ll see a PXE boot message instead, and the install will go no further. Be prepared and act fast! If all goes well, you’ll see the Windows 11 setup screen “Select language settings.” After that, it’s just matter of marching through the Windows install process, so I won’t track that further except to note that you will need a valid product key for whatever version of Windows you’re installing. By default, you will encounter a problem: At some point, you’ll get the error message “This PC doesn’t currently meet Windows 11 system requirements.” That’s because Hyper-V Manager Quick Create does not enable the Trusted Platform Module (TPM: special, secure chip-level storage used for hardware keys and other highly sensitive system data) by default. Turn off the VM (click Action in the top menu, then click Turn off). In the main Hyper-V Manager screen, select the VM you’re installing (in this case, Win11.26100), then click the Settings option at the lower right. This opens the Settings page for the Win11.26100 VM. Click on Security. In the Security pane, you will see that while Secure Boot is enabled, TPM is not. Check the Enable Trusted Platform Module checkbox, as shown in Figure 11. Then click Apply and then OK. Figure 11: TPM must be enabled before Windows 11 may be installed. Hyper-V Manager neglects to do this by default, so you must do so manually. Ed Tittel / IDG Now when you click Connect and get into the installer, it should run to the end. Once the process is complete (it took another 40 minutes or so on my beefy P16 Mobile Workstation), you’ll see a typical Windows in a VM window. There you are: another VM for your Hyper-V collection. Full-blown VM creation In addition to the Quick Create option, Hyper-V Manager also offers a New > Virtual Machine option, as show in Figure 12. This provides more direct access to the various settings and selections possible when creating a Hyper-V VM. Figure 12: The New > Virtual Machine action provides more control over details when creating a new VM. Ed Tittel / IDG Using this option opens a New Virtual Machine Wizard that walks you through the entire VM specification process, as shown in Figure 13. As you can see, it lets you specify a name, choose a file system location, select a VM generation, assign memory, and handle networking, virtual hard disk, and installation details. (Alas, you must still manage the TPM setting yourself manually, as described in the preceding section.) Figure 13: The New Virtual Machine Wizard takes users through VM creation and settings, step-by-step. Ed Tittel / IDG In the screenshots that follow, I’ll create a new Windows 11 VM for version 24H2 (Build 26100.863) downloaded from the Insider Preview downloads page. Figure 14 shows the Specify Name and Location screen, where I’ve named the VM Win11.24H2. It uses the default storage location for a virtual hard disk file. Figure 14: The VM name is set to Win11.24H2, after which you click Next to continue. Ed Tittel / IDG By default, all Hyper-V VMs are designated Generation 1. Since Generation 1 doesn’t support Windows 11 VM requirements, you must select the Generation 2 radio button to install a Windows 11 VM, as shown in Figure 15. Figure 15: Click the Generation 2 radio button to meet Windows 11 VM requirements. Ed Tittel / IDG The next step is to allocate 8GB (8,192MB) of RAM (double the default) for the Win11.24H2 VM, as shown in Figure 16. Figure 16: Double the defaults (8GB instead of 4GB) this time around, please. Ed Tittel / IDG The next step is to select the Default Switch option for the Connection field under the Configure Networking heading, as shown in Figure 17. Here again, it’s important to note the default is “Not connected,” which means the VM cannot access any networks. Default Switch enables the VM to connect to the networks to which the host PC has access. If you have other switches defined in your host configuration, they should appear in the pull-down menu for this VM setup item (and you’ll be able to use them, if you like). Figure 17: Use Default Switch if you want the VM to have network (and internet) access. Ed Tittel / IDG The next step is to connect a virtual hard disk for the VM to use. Here again we’ll use the default location mentioned earlier. Other options include “Use an existing virtual hard disk” (this is how the dev environment described earlier gets its contents) and “Attach a virtual hard disk later” (allows users to otherwise finish configuring a VM without allocating or linking to a virtual hard disk). See Figure 18 for the details for Win11.24H2.vhdx. Figure 18: This represents the default allocation (127GB) for Hyper-V VM virtual hard disks. Ed Tittel / IDG Next comes the fun part: providing a file system link to an ISO and electing how (or if) to install that image. This reads “Installation Options” on the left-hand side. In this case, we’ll link to the ISO I downloaded from the Insider Preview downloads page, and tell it to install the OS from that file, as shown in Figure 19. Figure 19: The selected radio button instructs the installer to find a specific Windows 11 ISO file. Ed Tittel / IDG At this point, the wizard is finished, so click Summary on the left to show your work so far. It will show all the settings you’ve made. Click Finish to complete the VM creation process. Then, you’ll return to Hyper-V Manager, where you now see a VM named Win11.24H2 in the upper center “Virtual Machines” pane, as shown in Figure 20. Figure 20: The new VM, Win11.24H2, is turned off. That’s good! Ed Tittel / IDG You could try to connect to and start the install process for Win11.24H2 now, but we know one more change is needed — namely, to enable TPM under the new VM’s Security settings, as detailed before Figure 11 above. Once you’ve done so, you can get going on the install for this Windows 11 OS image, as described earlier in this story as well. We’re done with the introduction to Hyper-V Manager and creating VMs. Now it’s time to dig into some down and dirty details. A big Hyper-V Manager gotcha: remote VM access By definition, all VM access is remote — that is, there’s no physical mouse, keyboard, or monitor attached to any VM. To interact with a VM, you must map virtual stuff onto real stuff — including the aforementioned peripherals but also CPUs, RAM, storage, networking, and yadda yadda yadda. Remember further that remote access is one of the benefits of VMs: indeed, they should readily support access across any network connection to a parent hypervisor. Alas, when a remote connection uses the Windows remote desktop protocol (RDP) through Remote Desktop Connection or the Remote Desktop app, and that hypervisor is Hyper-V, things can get interesting. Let me explain how this can present obstacles above and beyond the gotchas I’ve already mentioned (issues getting the Windows Installer to start up for an ISO-based install, and the need to enable TPM for that install to actually work). For starters, you can’t start a new Windows 11 VM from inside an RDP session, as it seeks to read and mount the targeted Windows 11 ISO to run its Setup.exe. For whatever odd reason, this works only from a local login on the host PC (not in an RDP session). If you click the Start button shown in Figure 7 in an RDP session, the VM won’t boot to run Setup.exe. Indeed, if you click Start, you’ll get a black screen in the VM window, instead of running the Windows 11 installer. You must turn off the VM (click Action in the top menu, then click Turn off). Then click the Start button shown in Figure 7 from the physical host PC, using the local mouse or keyboard. Once Setup.exe is running, however, an RDP session shows the VM as you’d expect to see it, with the initial Windows 11 installer screen (see Figure 21). Figure 21: Once Setup.exe is running, you can RDP into the VM, if you wish. Ed Tittel / IDG The next gotcha that makes itself felt occurs after you elect the Install now option that appears next. You will find you cannot copy and paste a Windows activation key into the Activate Windows prompt shown in Figure 22. Why? Because this only works in an enhanced session inside RDP, and you can’t elect that option until after Windows 11 is installed. Indeed, fixing this requires some fiddling to the Windows Hello login options. (Turned on by default, they don’t work with an enhanced session that permits copying and pasting from outside the RDP session into that session.) Figure 22: When you get to the key prompt in Activate Windows, you’ll discover you cannot copy and paste a text key. Manual entry only! Ed Tittel / IDG You’ll have to enter the 25-character (letters and numbers) string for your chosen Windows key manually. Or you can use the 30-day eval for the Windows 11 developer environment instead (no key required but access doesn’t last very long). But there’s one more RDP gotcha to surmount: you can’t log in to your new desktop until you uncheck the “Enhanced session” option in the View menu for the RDP session. Once you do that and log in, click Settings > Accounts > Sign-in options, then turn off the toggle under “Additional settings” that reads For improved security…, as shown in Figure 23. Then you can switch back to an enhanced session and log in using a password or a PIN. Figure 23: Note that “Enhanced session” in the View menu up top is unchecked. Turn off the toggle under “Additional settings.” Then you can re-enable that option so that cut and paste will work in RDP. Ed Tittel / IDG Getting past plain-vanilla VMs Thanks to our earlier efforts in this story, you’ve got yourself some working Windows 11 VMs set up mostly using Hyper-V Manager’s defaults. By setting up the plain-vanilla, all-default Win11.26100 VM via Quick Create and the slightly modified Win11.24H2 VM that follows it through the New Virtual Machine Wizard, you can learn a lot about what makes a VM tick, as well as provisioning defaults. Those defaults will change according to the configuration of the host physical PC on which Hyper-V Manager runs. That is, machines with fewer cores, less RAM, and less storage will produce default VMs with fewer cores, less RAM, and less storage than those machines with more cores, more RAM and more storage, like the formidable Lenovo P16 Mobile Workstation I used as my test machine, with 24 cores, 64GB RAM, and ~4 TB total storage, 2 TB on the boot/system drive. In most cases, the defaults that Hyper-V Manager chooses for the VMs it creates on your behalf work reasonably well. For those already familiar with Hyper-V, feel free to change values up or down. IMO, reducing values from their defaults doesn’t make too much sense except perhaps for special cases (or underwhelming physical PCs). For more info on Hyper-V and VMs: Microsoft Learning offers a free 45-minute module entitled “Configure and Manage Hyper-V virtual machines” for those who want more details. Also, there’s a series of tutorials at Windows 11 Forum under its Virtualization heading (54 in all, across a range of VM topics) for those who really want all the minutiae. Creating VMs with Dev Home (Preview) When Microsoft released v0.13 of its Dev Home (Preview) developer toolbox on April 23, 2024, I noticed they added support for “Environments” as something new. Microsoft explains that environments provide “… the ability to create, manage, and configure Hyper-V VMs and Microsoft Dev Boxes” (see the GitHub Dev Home Preview v0.13 release notes). Many readers may be indifferent to Dev Boxes (an Azure service to enhance developer productivity through self-service access to preconfigured, project-oriented development environments in the cloud via Azure, for which a subscription is required). If those readers want to use Hyper-V VMs, however, they should NOT be indifferent to its VM capabilities, which require Windows 11 22H2 or later. Because I’m only too familiar with the gotchas outlined in the previous section that can impede creation (and use) of VMs through Hyper-V Manager, I wanted to see if Dev Home (Preview) could do any better. I deliberately used an RDP session to run Dev Home on a remote PC. Inside Dev Home, I opened the Environments option, shown with a small blue highlight bar to its left in Figure 24. Figure 24: Home Dev Environments shows existing VMs along with “New Virtual Machine.” Ed Tittel / IDG Notably, Dev Home brought up all VMs already defined on the P16, and their status (Stopped, Running, Saved); I guess that means they count as “Environments” from the tool’s perspective. More notably, clicking the Create Environment button at the upper right sped me through the steps to create a new Hyper-V VM: Select Microsoft Hyper-V as the “environment provider.” Enter NewVM2 in the field tagged “New virtual machine name.” Select the 30-day evaluation for the “Windows 11 dev environment” as the Windows OS image source (it’s labeled an “Environment” below), purely as a test, as shown in Figure 25. Click Create Environment (see lower right, Figure 25). Figure 25: This screen shows you’ve chosen the Microsoft-supplied “Windows 11 dev environment” as your image source for a new VM. Ed Tittel / IDG Once you’ve clicked the Create Environment button, be prepared to wait a while. Dev
https://www.computerworld.com/article/3477240/how-to-set-up-windows-11-hyper-v-virtual-machines.html
Voir aussi |
56 sources (32 en français)
Date Actuelle
dim. 22 déc. - 16:53 CET
|