Hyper-V Virtualization Administration
# Hyper-V Virtualization Administration ## Introduction Hyper-V is Microsoft's native hypervisor for Windows Server, enabling creation and management of virtual machines. Hyper-V supports Windows a
# Hyper-V Virtualization Administration
Introduction
Hyper-V is Microsoft's native hypervisor for Windows Server, enabling creation and management of virtual machines. Hyper-V supports Windows and Linux guest operating systems, live migration, checkpoints, virtual networking, and storage. This tutorial covers Hyper-V installation, virtual machine creation, virtual switches, checkpoints, live migration, and administration.
By the end of this guide, you will be able to deploy and manage Hyper-V virtualization on Windows Server.
Technical Background
Hyper-V Components
| Component | Description | |-----------|-------------| | Hypervisor | Virtualization layer managing CPU, memory, and devices | | Parent Partition | Windows Server running Hyper-V role | | Child Partition | Virtual machine running guest OS | | Virtual Switch | Virtual network connecting VMs | | VHD/VHDX | Virtual hard disk format | | Checkpoint | Point-in-time VM state snapshot | | Integration Services | Drivers for enhanced VM performance |
Generation Types
| Generation | Description | Support | |------------|-------------|---------| | Generation 1 | BIOS-based, 32/64-bit | Legacy compatibility | | Generation 2 | UEFI-based, 64-bit only | Secure Boot, larger VMs, PXE |
Prerequisites
- Windows Server 2025 with Hyper-V role
- Hardware virtualization enabled (Intel VT-x or AMD-V)
- Sufficient RAM and CPU for VMs
- Network adapter for virtual switching
- Storage for virtual hard disks
Architecture
Hyper-V Architecture
Physical Server
├── Hypervisor
│ ├── Parent Partition (Windows Server)
│ │ ├── Hyper-V Management Tools
│ │ └── Virtual Switch
│ └── Child Partitions (VMs)
│ ├── VM 1 (Windows)
│ ├── VM 2 (Linux)
│ └── VM 3 (Windows)
├── Physical NIC → Virtual Switch
└── Physical Disk → VHDX filesStep-by-Step Implementation
Step 1: Install Hyper-V Role
**Purpose**: Install Hyper-V virtualization role.
**Commands** (PowerShell):
# Install Hyper-V role
Install-WindowsFeature -Name Hyper-V -IncludeManagementTools -Restart
# Verify installation
Get-WindowsFeature Hyper-V**Expected output**: Hyper-V role installed; server restarts.
**Verification**:
Get-VMHost
# Shows Hyper-V host informationStep 2: Create Virtual Switch
**Purpose**: Configure virtual networking for VMs.
**Commands** (PowerShell):
# Create external virtual switch (VMs access physical network)
New-VMSwitch -Name "ExternalSwitch" -NetAdapterName "Ethernet0" -AllowManagementOS $true
# Create internal virtual switch (VMs communicate with host only)
New-VMSwitch -Name "InternalSwitch" -SwitchType Internal
# Create private virtual switch (VMs communicate with each other only)
New-VMSwitch -Name "PrivateSwitch" -SwitchType Private
# Verify virtual switches
Get-VMSwitch**Expected output**: Virtual switches created and available for VMs.
**Verification**:
Get-VMSwitch
# Shows switch names, types, and network adaptersStep 3: Create Virtual Machine
**Purpose**: Deploy a new virtual machine.
**Commands** (PowerShell):
# Create Generation 2 VM
New-VM -Name "WebServer01" -MemoryStartupBytes 4GB -Generation 2 -SwitchName "ExternalSwitch"
# Create virtual hard disk
New-VHD -Path "C:\ClusterStorage\VMs\WebServer01\WebServer01.vhdx" -Size 127GB
# Attach virtual hard disk to VM
Add-VMHardDiskDrive -VMName "WebServer01" -Path "C:\ClusterStorage\VMs\WebServer01\WebServer01.vhdx"
# Configure VM to boot from DVD (ISO)
Set-VMDvdDrive -VMName "WebServer01" -Path "C:\ISOs\WindowsServer2025.iso"
# Configure boot order
Set-VMFirmware -VMName "WebServer01" -FirstBootDevice $dvd
# Verify VM configuration
Get-VM -Name "WebServer01" | Format-List**Expected output**: VM created with virtual hard disk and DVD drive.
**Verification**:
Get-VM -Name "WebServer01"
# Shows VM state, memory, and generationStep 4: Configure VM Settings
**Purpose**: Adjust VM resources and settings.
**Commands** (PowerShell):
# Set VM memory (static)
Set-VMMemory -VMName "WebServer01" -DynamicMemoryEnabled $false -StartupBytes 4GB
# Enable dynamic memory
Set-VMMemory -VMName "WebServer01" -DynamicMemoryEnabled $true -MinimumBytes 1GB -StartupBytes 4GB -MaximumBytes 8GB
# Set CPU count
Set-VMProcessor -VMName "WebServer01" -Count 2 -ExposeVirtualizationExtensions $true
# Add network adapter
Add-VMNetworkAdapter -VMName "WebServer01" -SwitchName "ExternalSwitch" -Name "Network Adapter"
# Set VM to start automatically
Set-VM -VMName "WebServer01" -AutomaticStartAction StartIfRunningBeforeShutdown
# Verify settings
Get-VM -Name "WebServer01" | Select-Object Name, State, CPUCount, MemoryAssigned**Expected output**: VM settings configured.
**Verification**:
Get-VMProcessor -VMName "WebServer01"
Get-VMMemory -VMName "WebServer01"Step 5: Start VM and Install Guest OS
**Purpose**: Start VM and install operating system.
**Commands** (PowerShell):
# Start VM
Start-VM -Name "WebServer01"
# Connect to VM (via Hyper-V Manager or PowerShell Direct)
# PowerShell Direct (from host to Windows guest)
Invoke-Command -VMName "WebServer01" -Credential (Get-Credential) -ScriptBlock { Get-ComputerInfo }
# Check VM state
Get-VM -Name "WebServer01" | Select-Object Name, State**Expected output**: VM started; guest OS installation begins from ISO.
**Verification**:
Get-VM -Name "WebServer01"
# Shows State: RunningStep 6: Create Checkpoints
**Purpose**: Create point-in-time VM snapshots.
**Commands** (PowerShell):
# Create checkpoint
Checkpoint-VM -Name "WebServer01" -SnapshotName "BeforeUpdate"
# List checkpoints
Get-VMSnapshot -VMName "WebServer01"
# Apply checkpoint (revert VM to snapshot state)
Restore-VMSnapshot -VMName "WebServer01" -Name "BeforeUpdate"
# Remove checkpoint
Remove-VMSnapshot -VMName "WebServer01" -Name "BeforeUpdate"
# Verify checkpoints
Get-VMSnapshot -VMName "WebServer01"**Expected output**: Checkpoint created; VM can be reverted to snapshot state.
**Verification**:
Get-VMSnapshot -VMName "WebServer01"
# Shows snapshot name and creation timeStep 7: Live Migration
**Purpose**: Move running VM between Hyper-V hosts.
**Prerequisites**:
- Shared storage (SMB 3.0, iSCSI, FC)
- Cluster or same domain
- Live Migration enabled on both hosts
**Commands** (PowerShell):
# Enable Live Migration on host
Set-VMHost -UseAnyNetworkForMigration $true
# Perform live migration
Move-VM -Name "WebServer01" -DestinationHost "HyperV02" -IncludeStorage -DestinationStoragePath "C:\ClusterStorage\VMs\WebServer01"
# Verify migration
Get-VM -Name "WebServer01" -ComputerName "HyperV02"**Expected output**: VM moved to another host without downtime.
**Verification**:
Get-VM -Name "WebServer01" -ComputerName "HyperV02"
# Shows VM running on new hostStep 8: Export and Import VM
**Purpose**: Backup or move VM to another host.
**Commands** (PowerShell):
# Export VM (including configuration and disks)
Export-VM -Name "WebServer01" -Path "C:\VMExports\WebServer01"
# Import VM on another host
Import-VM -Path "C:\VMExports\WebServer01" -GenerateNewID -VHDPath "C:\VMs\WebServer01\WebServer01.vhdx" -ConfigurationPath "C:\VMs\WebServer01\"
# Verify imported VM
Get-VM -Name "WebServer01"**Expected output**: VM exported and imported successfully.
**Verification**:
Get-VM -Name "WebServer01"
# Shows imported VM availableConfiguration Examples
VM Creation Script (`New-VM.ps1`)
param(
[string]$VMName,
[int]$MemoryGB = 4,
[int]$CPUCount = 2,
[int]$DiskSizeGB = 127,
[string]$SwitchName = "ExternalSwitch",
[string]$VHDPath = "C:\VMs",
[string]$ISOPath = $null
)
# Create VM directory
$vmPath = Join-Path $VHDPath $VMName
New-Item -ItemType Directory -Path $vmPath -Force
# Create VM
New-VM -Name $VMName -MemoryStartupBytes ($MemoryGB * 1GB) -Generation 2 -SwitchName $SwitchName -Path $vmPath
# Create and attach VHDX
$vhdPath = Join-Path $vmPath "$VMName.vhdx"
New-VHD -Path $vhdPath -Size ($DiskSizeGB * 1GB)
Add-VMHardDiskDrive -VMName $VMName -Path $vhdPath
# Add ISO if provided
if ($ISOPath) {
Set-VMDvdDrive -VMName $VMName -Path $ISOPath
Set-VMFirmware -VMName $VMName -FirstBootDevice (Get-VMDvdDrive -VMName $VMName)
}
# Configure dynamic memory
Set-VMMemory -VMName $VMName -DynamicMemoryEnabled $true -MinimumBytes 1GB -StartupBytes ($MemoryGB * 1GB) -MaximumBytes ($MemoryGB * 2GB)
# Configure CPU
Set-VMProcessor -VMName $VMName -Count $CPUCount
Write-Host "VM $VMName created successfully"Hyper-V Host Configuration
# Enable nested virtualization (for VMs running Hyper-V)
Set-VMProcessor -VMName "VM1" -ExposeVirtualizationExtensions $true
# Enable Enhanced Session Mode (better VM console experience)
Set-VMHost -EnableEnhancedSessionMode $true
# Set default VM storage location
Set-VMHost -VirtualHardDiskPath "C:\ClusterStorage\VMs\"
# Set default VM configuration location
Set-VMHost -VirtualMachinePath "C:\ClusterStorage\VMs\"Checkpoint Configuration
# Set checkpoint type (Standard or Production)
Set-VM -VMName "WebServer01" -CheckpointType Production
# Limit checkpoint count
Set-VM -VMName "WebServer01" -CheckpointCountLimit 5Verification
Hyper-V Verification Commands
Get-VMHost -- Hyper-V host information
Get-VM -- List all VMs
Get-VM -Name "VM1" | Format-List -- Detailed VM config
Get-VMSwitch -- Virtual switches
Get-VMSnapshot -VMName "VM1" -- VM checkpoints
Get-VHD -Path "C:\VMs\VM1.vhdx" -- VHDX info
Get-VMNetworkAdapter -VMName "VM1" -- VM network adaptersExpected Results
- VMs listed with correct state (Running, Off, Saved)
- Virtual switches created and connected
- Checkpoints created and restorable
- Live migration completes without downtime
- VM exports/imports successful
Troubleshooting
| Symptom | Possible Cause | Diagnostic Command | Corrective Action | Verification | |---------|---------------|-------------------|-------------------|--------------| | VM won't start | Insufficient resources | `Get-VMHost` | Free memory/CPU; add resources | VM starts | | VM no network | Wrong virtual switch | `Get-VMNetworkAdapter -VMName "VM1"` | Assign correct switch | VM has network | | Live migration fails | No shared storage | `Get-ClusterSharedVolume` | Configure shared storage | Migration succeeds | | Checkpoint fails | Checkpoint limit reached | `Get-VMSnapshot` | Remove old checkpoints | Checkpoint created | | VHDX won't mount | Corrupt or in use | `Get-VHD` | Repair or detach VHDX | VHDX mounts | | Hyper-V role missing | Hardware virtualization disabled | `systeminfo` | Enable VT-x/AMD-V in BIOS | Hyper-V available | | Enhanced session not working | Not enabled on host | `Get-VMHost` | `Set-VMHost -EnableEnhancedSessionMode $true` | Enhanced session works |
Best Practices
1. **Use Generation 2 VMs**: UEFI-based, better performance, Secure Boot support. 2. **Use dynamic memory**: Allows memory reclamation when VMs don't need it. 3. **Store VHDX on separate volume**: Separate VM storage from OS volume. 4. **Use checkpoints sparingly**: Checkpoints are not backups; remove after use. 5. **Enable Enhanced Session Mode**: Better console experience for VMs. 6. **Use fixed-size VHDX for production**: Better performance than dynamically expanding. 7. **Monitor host resources**: Ensure host has capacity for all VMs. 8. **Use live migration for maintenance**: Move VMs before host maintenance. 9. **Back up VMs regularly**: Use Windows Server Backup or third-party solutions. 10. **Document VM configurations**: Record memory, CPU, disk, and network settings.
Conclusion
Hyper-V provides native virtualization on Windows Server with features including virtual machines, virtual switches, checkpoints, live migration, and export/import. Proper Hyper-V administration includes role installation, virtual switch configuration, VM creation and management, resource allocation, and backup strategies. With Hyper-V, Windows Server hosts can run multiple isolated workloads efficiently, reducing hardware costs and improving flexibility.
References
- Hyper-V Documentation (https://learn.microsoft.com/windows-server/virtualization/hyper-v/)
- PowerShell Hyper-V Module (https://learn.microsoft.com/powershell/module/hyper-v/)
- Hyper-V Deployment Planning (https://learn.microsoft.com/windows-server/virtualization/hyper-v/plan/)
- Live Migration Overview (https://learn.microsoft.com/windows-server/virtualization/hyper-v/manage/live-migration-overview)