What Is Hyper-V and How Does It Work?

Virtualization has transformed the way we manage and deploy resources. Whether on the cloud or on-premise, virtualization technologies enable us to maximize resource utilization, enhance scalability, reduce costs, and strengthen security.

Hyper-V is a widely used virtualization product from Microsoft that can seamlessly run multiple, independent virtual machines on any computer. In this article, we will provide a comprehensive guide to Hyper-V, covering its features, how it compares to VMware, and how to enable and manage it on Windows Server 2019.

What is virtualization and what are its uses?

Virtualization is the process of creating multiple isolated virtual resources from a single physical resource. In simple terms, virtualization allows a physical computer to run many virtual computers, with each virtual computer getting its own dedicated network, memory, storage, and operating system (OS).

Virtualization does this by using a special software called a hypervisor. The hypervisor acts as an abstraction layer between the virtual computers (or machines) and the physical resources. It manages the allocation and distribution of virtual resources to the virtual computers and ensures that they do not interfere with each other.

Docker containers and virtual machines (VMs) are two popular types of virtualization. Docker containers are lightweight virtualization solutions that package an application and its dependencies into a single image. VMs are more heavyweight virtualization solutions that allow you to run entire operating systems in isolated environments.

Virtualization has several benefits, including:

  • Consolidation A pool of physical servers can be consolidated to create a single, large virtual environment. This can save space, power, and maintenance costs.
  • Easier management Virtualization software typically includes a centralized management dashboard that can be used to create and manage virtual machines, monitor their performance, and apply security policies.
  • Multi-OS support Without virtualization, there’s no way to run two operating systems on the same computer. Virtualization enables us to run applications with different OS requirements on the same computer without having to worry about conflicts.
  • Isolation and security Each virtual machine is sandboxed and isolated from the rest. Even if one malfunctions or crashes, it doesn't affect the other VMs.
  • Agility: Virtualization fosters agility. Virtual machines are easy to create, configure, and move between physical servers.

What is Hyper-V?

Hyper-V is a hypervisor developed by Microsoft that lets you create, deploy, and manage virtual machines on a Windows server. It offers several security, performance, and networking features that were not offered by Microsoft's older virtualization products, such as Microsoft Virtual Server and Windows Virtual PC.

How does Hyper-V work?

Hyper-V virtualizes all the hardware resources of a physical computer and shares them across different virtual machines. The physical computer on which Hyper-V runs is known as the host. The virtual machines running on the host are known as guest VMs.

Each Hyper-V virtual machine operates as if it were a separate physical computer, with its own operating system, memory, storage, network, and processor. This isolation makes it possible to run applications with different kernel needs on the same computer. For example, you can run a C++ application inside a CentOS 7 VM, and a Java application inside a Windows Server VM, on the same physical computer.

The latest versions of Hyper-V can also be enabled on certain Windows 10 versions, including Windows 10 Enterprise, Windows 10 Pro, and Windows 10 Education. To run Hyper-V, your system must meet the following minimum requirements:

  • A minimum of 4 gigabytes of memory
  • A 64-bit processor that supports Second Level Address Translation (SLAT)
  • CPUs with VM Monitor Mode Extension (VT-x for Intel CPUs or AMD-V for AMD CPUs)

Network virtualization

Hyper-V uses a virtual switch and a virtual networking adapter for networking. The virtual switch is a Layer-2 Ethernet switch with many pre-built features for traffic segmentation, monitoring, and security. The network adapter binds with a port on the virtual switch, which allows a VM to start networking.

To set up networking, administrators can create a virtual switch during the Hyper-V installation. This switch can then be attached to VMs as they are provisioned. When a switch is associated with a VM, Hyper-V automatically adds a network adapter to that VM.

It’s worth noting that a single virtual switch can be associated with multiple VMs. The switch enables the VMs to share the same network resources, and communicate with each other and the external network, as needed.

Hyper-V offers different kinds of virtual switches:

  • Internal Internal switches are like private networks for VMs. They allow VMs to communicate with each other and with the host system but not with external networks.
  • Private Private switches are entirely isolated. VMs connected to a private switch can only communicate with each other and not with the host.
  • External External switches bridge VMs to the physical network adapter on the host server, enabling communication with other devices on the physical network. They give a VM direct connection to the outside world.

Hyper-V also supports native Network Address Translation (NAT) for virtual machines. NAT allows multiple VMs to use the host’s IP address when connecting to external networks. To implement NAT, you must create a NAT virtual network and connect it with your VM’s internal switch.

Hyper-V vs. VMWare

VMware is a company that offers a wide range of virtualization products, including vSphere, VMware Workstation, and VMware ESXi. Hyper-V and VMware are the two leading virtualization platforms. Both platforms offer a wide range of benefits, but there are also some key differences between them.

  • Hyper-V offers limited support for non-Windows based VMs, whereas VMware provides robust cross-platform compatibility.
  • VMware is a commercial product, whereas Hyper-V is free for Windows Server and Windows 10 users.
  • Hyper-V has a smaller overhead compared to VMware, as it is embedded within the Windows Kernel. VMware typically uses more resources, as it runs on top of an operating system.
  • VMware has a steeper learning curve compared to Hyper-V.
  • VMware has a larger ecosystem of third-party applications and integrations that can be used to extend its feature set. Hyper-V integrates seamlessly with Microsoft suite products but not as many third-party applications.
  • Both products offer advanced virtualization features, including nested virtualization, live migration, cloning, and remote connectivity.

Choosing between physical servers (bare metal) and Hyper-V/VMWare VMs

When deciding between physical servers (bare metal) and Hyper-V/VMWare virtual machines, it's important to weigh the pros and cons of each option. In this section, we'll explore the key considerations to help you make the right call.

Deployment and isolation

Bare metal

When you use bare metal, your workloads are run directly on the physical servers. Each server generally runs a single operating system, and you have maximum control over the hardware. This approach offers the highest levels of isolation, as each server can operate independently.

Virtual machines

With virtual machines, you run multiple instances of operating systems on a single physical server. All the VMS share the hardware resources of the server, including the CPU, memory, network, and storage. Even though VMs do provide isolation between workloads, it’s not as strict as with bare metals.

Resource utilization

Bare metal

When you use bare metal, each server is dedicated to a particular task or application. While this does provide maximum performance for that particular workload, it can result in underutilized hardware, as one server often doesn’t use all of its available resources.

Virtual machines

VMs are much more resource-efficient as they allow you to run multiple workloads on a single physical server. This efficient resource usage is one of the key benefits of virtualization. Moreover, users can dynamically allocate and share resources for VMs, based on demand, which makes them a flexible solution as well.

Scalability

Bare metal

Scaling with bare metal generally involves adding more physical servers. This process is much less flexible and slower compared to scaling VMs, as it often requires the purchase, installation, and configuration of new hardware.

Virtual machines

VMs offer greater scalability. You can easily spawn, clone, or migrate VMs to cater to changing demands, often without the need for additional physical hardware. This scalability is a primary reason why virtualization is a popular choice for cloud computing and data centers.

Management and maintenance

Bare metal

Managing, monitoring, and maintaining physical servers can be more labor-intensive. Updates, backups, troubleshooting, and auditing may require more effort, especially for large-scale deployments.

Virtual machines

VMs are inherently easier to manage. Virtualization platforms, like HyperV and VMWare, provide tools for central management, snapshot backups, seamless migration, and troubleshooting. Updates and maintenance can be more streamlined, as changes can be made centrally (at the virtualization layer).

Cost considerations

Bare metal

The deployment of bare metal servers may involve higher upfront costs as you will need dedicated servers for different workloads. However, in some cases, it can be more cost-effective for specific high-performance applications that require dedicated resources, e.g. a data warehouse.

Virtual machines

In terms of hardware needs and utilization, VMs can be far more cost-effective compared to bare metal. They allow you to make the most of your existing hardware and provide flexibility to scale resources as needed.

Hyper-V features

Hyper-V offers an array of features related to the deployment, networking, management, security, operations, and migrations of VMs.

  • Nested virtualization Hyper-V supports nested virtualization, which allows you to run virtual machines within virtual machines (i.e., run Hyper-V inside a Hyper-V virtual machine). This is a useful feature for testing and development scenarios.
  • Easy-to-use management tools Microsoft offers various tools for managing Hyper-V virtual machines, including the Hyper-V manager and the System Center Virtual Machine Manager (SCVMM).
  • Failover clustering Hyper-V supports failover clustering, enabling high availability for virtual machines.
  • Replicas and backups Hyper-V comes with built-in features for replication and backups. A Hyper-V replica allows you to create and store copies of your virtual machines on a separate host. The System Center Data Protection Manager (DPM) can be configured to perform backups at the host or guest level.
  • Portability Hyper-V provides several features, such as import/export, live migration, and storage migration, which make Hyper-V virtual machines highly portable.
  • Security Hyper-V is secure by design. It offers numerous security controls, including encrypted networks, host key attestation, Trusted Platform Module (TPM) attestation, sensitive data storage, shielded VMs, and host resource protection.
  • Remote connections Hyper-V ships with Virtual Machine Connection, a utility that offers console access to virtual machines. This is great for troubleshooting, configuring virtual machines, or performing maintenance tasks.

How to enable and use Hyper-V on Windows Server 2019

Hyper-V is shipped as a part of most Windows versions. You only need to install and enable the Hyper-V role to start creating and running virtual machines. We will show you two ways to enable the role on Windows Server 2019: through the Server Manager and PowerShell.

Before you begin, check if your system meets the virtualization requirements. You can do this by running this command on PowerShell:

Systeminfo.exe 

Navigate to the "Hyper-V Requirements" section at the end of the output. On a supported system, you should see the following lines:


Hyper-V Requirements: VM Monitor Mode Extensions: Yes
Virtualization Enabled In Firmware: Yes
Second Level Address Translation: Yes
Data Execution Prevention Available: Yes

Enabling Hyper-V using PowerShell

We’ll be using the Install-WindowsFeature cmdlet to install and enable Hyper-V. Follow these steps:

  • Run PowerShell as an administrator.
  • Copy, paste, and run the following command:

    Install-WindowsFeature -Name Hyper-V -IncludeManagementTools -Restart
  • Alternatively, if you want to install Hyper-V on a remote server, use this command:

    Install-WindowsFeature -Name Hyper-V -ComputerName -IncludeManagementTools -Restart
    (Note: Replace with the actual name of the remote server.)

The server should now restart with Hyper-V enabled.

Enabling Hyper-V using the Server Manager

  • Open the Server Manager. Click Add Roles and Features.
  • Click Next after reading the “Before you begin” page.
  • You should now see the “Select installation” page. Choose “Role-based or feature-based installation” and click Next.
  • On the “Select destination server” page, choose the desired server and hit Next.
  • On the “Select server roles” page, scroll down and select “Hyper-V” from the list of available roles.
  • You should see a pop-up window asking you to install the features required for Hyper-V. Make sure you check the “Include management tools (if applicable)”. Click Add Features.
  • On the “Features” page, hit Next.
  • Click Next on the introductory “Hyper-V” page.
  • Depending on your requirements, select the appropriate settings on the “Virtual Switches”, “Migration”, and “Default Stores” pages. For example, on the “Virtual Switches” page, you can select the network adapter. On the “Migration” page, you can select whether the server should receive live migrations. On the “Default Stores” page, you can set the default location for virtual hard disk and VM configuration files.
  • On the “Confirm Installation selections” page, check the “Restart the destination server automatically if required” box and then hit Install.

Once the installation finishes, you should be able to see the new server in the “All Servers” page in Server Manager.

Creating your first virtual machine on Hyper-V

Now that we have installed and enabled the Hyper-V role on our server, we can use the Hyper-V manager to create a virtual machine. Follow these steps:

  • Open the Hyper-V manager on the server.
  • Select “Action” -> “New” -> “Virtual Machine”.
  • The “New Virtual Machine Wizard” should open. Click Next.
  • On the “Specify Name and Location” page, specify a name and location for the virtual machine. Then, hit Next.
  • On the “Specify Generation” page, choose whether you want to create a Generation 1 VM or a Generation 2 VM. Then, click Next.
  • On the “Assign Memory” page, choose a value between 32 MB to 5902 MB for the startup memory. Depending on your use case, you may select or deselect the “Use dynamic memory for this virtual machine” box. Click Next when done.
  • On the “Configure Networking” page, choose a virtual switch from the list of available connections and click Next.
  • On the “Connect Virtual Hard Disk” page, choose between creating a new virtual disk, using an existing one, or attaching a virtual disk later. Once you have selected, click Next.
  • On the “Installation Options” page, choose how to install the VM and hit the Next button.
  • Click Finish.
  • From the Hyper-V manager, right-click the newly created virtual machine, and select Connect.
  • A new “Virtual Machine Connection” window should appear. Choose “Action” -> “Start”
  • Follow the on-screen instructions to install the operating system and boot into the VM.

Managing and monitoring VMs

Now that we have created our first virtual machine on a Hyper-V-powered virtualized resource, let's explore how to perform some common administrative operations using the Hyper-V manager and PowerShell.

Stopping virtual machines

We can use PowerShell to stop a virtual machine that’s malfunctioning or unresponsive. The Stop-VM command lets you shut down or turn off a virtual machine using its name. For example, running the following command from the guest system will shut down a virtual machine with the name SampleVM:

Stop-VM -Name SampleVM 

You can also use the -Force option to force a shutdown after giving the VM 5 minutes to save its data.

Stop-VM -Name SampleVM -Force 

To simply turn off the machine, use the -TurnOff option. This is similar to unplugging a physical computer and can lead to the loss of unsaved data.

Stop-VM -Name SampleVM -TurnOff 

Exporting and importing VM images

It’s possible to import/export Hyper-V VMs using the PowerShell or the Hyper-V manager.

For exporting:

When using the Hyper-V manager, right-click the VM and choose Export. Then choose the directory to store the exported file, and hit Export.

From the PowerShell, you can use the Export-VM cmdlet to export a VM. For example, the following command will export a VM named SampleVM to the directory D:\export.

Export-VM -Name SampleVM -Path D:\export 

For importing:

When using the Hyper-V manager:

  • Choose “Actions” -> “Import Virtual Machine”.
  • Click Next on the “Before You Begin” page.
  • On the “Locate Folder” page, navigate to the directory that contains the exported file, and choose Next.
  • On the “Select Virtual Machine” page, select the VM to import. Then, click Next.
  • On the “Choose Import Type” page, choose the type of import and hit Next.
  • On the “Summary” page, review your choices and hit Finish.

From the PowerShell, you can use the Import-VM cmdlet to import a VM. For example, the following command will import a VM from the given path and copy its files to the default directories. (Make sure to replace the path and the name of the export file)


Import-VM -Path 'D:\export\2B912EC3-F1F0-4FDF-B98E-29CAD592C95B.vmcx' -Copy -GenerateNewId

Create a virtual switch using PowerShell

Follow these steps to create a new external virtual switch for your VMs using PowerShell:

  • Run Get-NetAdapter to get a list of available network adapters.
  • Initialize a new variable with the network adapter that you want to use for the new switch.

    $adapter = Get-NetAdapter -Name 'Ethernet Adapter 2'
  • Run the following command to create the switch:

    New-VMSwitch -Name "External Virtual Switch 2" -AllowManagementOS $True -NetAdapterName $adapter.Name

Creating checkpoints using the Hyper-V manager

Hyper-V makes it easy to create checkpoints. A checkpoint captures the state of a virtual machine, allowing you to roll back to a previous state if needed. Here’s how to create a checkpoint using the Hyper-V manager:

  • On the Hyper-V manager, right-click the virtual machine and choose Checkpoint.
  • Once the process completes, you should be able to see the new checkpoint in the Checkpoints section.

Migrating a virtual machine using the Hyper-V manager

You can migrate a running virtual machine using the Hyper-V Manager in just five simple steps:

  • Open the Hyper-V manager. (To do so, select Server Manager -> Tools -> Hyper-V Manager)
  • Choose the relevant server from the navigation pane. If you don’t see the desired server, perform these steps.
    • Right click Hyper-V Manager and select Connect to Server.
    • Type the name of the server and select OK.
    • Repeat 1) and 2) if you wish to add more servers.
  • Navigate to the Virtual Machines pane. Right click on the relevant VM and then select Move. You should now be able to see the Move Wizard.
  • Follow the instructions on the different pages of the wizard, filling out destination server details, the type of move, and other parameters.
  • After making the desired selections, review them on the Summary page, and then click Finish.

Monitoring Hyper-V performance

The Hyper-V manager offers some basic metrics about the health and status of a virtual machine, including uptime, CPU usage, assigned memory, and status. Microsoft also offers other native tools to track and monitor Hyper-V VMs in real time.

For example, the Measure-VM cmdlet can be used to fetch data related to network traffic, disk usage, processor usage, and more. The Measure-VMReplication cmdlet shows stats related to replication. The Measure-VMResourcePool cmdlet reports resource utilization data for pools of virtual machines.

If you want a dedicated, all-in-one tool to monitor Hyper-V, you should check out Site24x7’s Hyper-V monitoring solution.

Remote management using PowerShell

PowerShell Direct is a handy way for remote management of Hyper-V VMs. Follow these steps to remotely access and manage a VM using PowerShell:

  • Open PowerShell as an administrator.
  • The Enter-PSSession cmdlet will allow you to connect to the virtual machine. For example, the following command will try to open a connection with a VM named TestVM:

    Enter-PSSession -VMName TestVM
  • When prompted, enter your credentials to log in to the VM.

That’s it! You can now run commands directly on the connected VM. Once you are done, use the Exit-PSSession to log out of the session.

Conclusion

Hyper-V is a leading virtualization software that enables you to build fault-tolerant and agile virtualized infrastructures. It is easy to use and offers a wide range of built-in features and tools for provisioning, deploying, managing, and scaling virtual machines.

Was this article helpful?

Related Articles

Write For Us

Write for Site24x7 is a special writing program that supports writers who create content for Site24x7 "Learn" portal. Get paid for your writing.

Write For Us

Write for Site24x7 is a special writing program that supports writers who create content for Site24x7 “Learn” portal. Get paid for your writing.

Apply Now
Write For Us