Introduction

Hyper-V, Microsoft’s powerful virtualization platform, supports seamless integration with Linux guest operating systems using Hyper-V Integration Services. This guide provides detailed steps to configure Rocky Linux for optimal performance on Hyper-V, including support for both AMD and Intel processors. We’ll also provide a handy Bash script to automate the setup process.


Prerequisites

  1. A Hyper-V host with Windows Server or Windows 10/11 (Pro/Enterprise).
  2. A running Rocky Linux VM.
  3. Basic knowledge of Linux commands.
  4. Administrative access to both the Hyper-V host and the guest VM.

Step 1: Update Rocky Linux

Keeping the system updated ensures compatibility and stability. Log in to your VM and run:

sudo dnf update -y

Step 2: Install Hyper-V Integration Services

The hyperv-daemons package provides the necessary services for Linux VMs on Hyper-V.

Install the Required Packages:

sudo dnf install -y hyperv-daemons hyperv-tools

Step 3: Load Kernel Modules

Rocky Linux comes with built-in support for Hyper-V kernel modules, which enhance the VM’s functionality.

Load the Kernel Modules:

sudo modprobe hv_vmbus
sudo modprobe hv_netvsc
sudo modprobe hv_storvsc

Configure Automatic Loading:

Add the following lines to /etc/modules-load.d/hyperv.conf:

echo -e "hv_vmbus\nhv_netvsc\nhv_storvsc" | sudo tee /etc/modules-load.d/hyperv.conf


Step 4: Verify Integration

  1. On the Hyper-V Manager, check that all Integration Services (e.g., Time Synchronization, Heartbeat, Shutdown) are enabled.
  2. Verify logs to ensure services are running:
sudo journalctl -u hypervkvpd.service 
sudo journalctl -u hypervvssd.service 
sudo journalctl -u hypervfcopyd.service

Step 5: Performance Tweaks for AMD and Intel

Both AMD and Intel processors work seamlessly with Hyper-V when properly configured.

AMD-Specific Settings:

Ensure AMD-V is enabled in the BIOS/UEFI.

Intel-Specific Settings:

Ensure Intel VT-x is enabled in the BIOS/UEFI.

Additionally, confirm nested virtualization support:

sudo dmesg | grep -i nested

Bash Script: Automate the Integration

Save the following script as hyperv_setup.sh and make it executable.

Script: hyperv_setup.sh

#!/bin/bash

# Update the system
echo "Updating the system..."
sudo dnf update -y

# Install Hyper-V tools and daemons
echo "Installing Hyper-V tools and daemons..."
sudo dnf install -y hyperv-daemons hyperv-tools

# Load and configure kernel modules
echo "Loading Hyper-V kernel modules..."
sudo modprobe hv_vmbus hv_netvsc hv_storvsc
echo -e "hv_vmbus\nhv_netvsc\nhv_storvsc" | sudo tee /etc/modules-load.d/hyperv.conf

# Verify services
echo "Verifying services..."
sudo systemctl status hypervkvpd.service
sudo systemctl status hypervvssd.service
sudo systemctl status hypervfcopyd.service

echo "Hyper-V integration setup completed!"

Execute the Script:

chmod +x hyperv_setup.sh
sudo ./hyperv_setup.sh

Conclusion

By following this guide or using the automation script, your Rocky Linux guest on Hyper-V will fully integrate, enabling features like dynamic memory, enhanced device support, and efficient communication with the Hyper-V host. This setup ensures optimal performance for both AMD and Intel systems.