How to Configure Hyper-V Storage for VMs on Windows Server 2012 R2
Storage configuration is one of the most critical aspects of Hyper-V performance and reliability. Windows Server 2012 R2 Hyper-V supports multiple storage types, including locally attached SATA/SAS drives, iSCSI SANs, Fibre Channel, SMB 3.0 file shares, and pass-through disks. Understanding how to optimally configure virtual hard disks, storage controllers, and host storage paths directly impacts VM performance, backup capabilities, and your ability to scale the environment over time.
Prerequisites
- Windows Server 2012 R2 with the Hyper-V role installed
- Host storage provisioned and formatted (NTFS or ReFS for VM storage paths)
- Hyper-V PowerShell module available
- VMs stopped for operations that require offline storage changes
Virtual Hard Disk Formats: VHD vs VHDX
Windows Server 2012 R2 supports both VHD (legacy) and VHDX (modern) formats. VHDX is strongly recommended for all new VMs:
- VHD: Maximum size 2TB, sector alignment can cause performance issues on Advanced Format (4K sector) disks, supported on older Hyper-V versions
- VHDX: Maximum size 64TB, 1MB internal block size reduces fragmentation, supports data corruption logging for metadata, aligned to 4K sectors for modern storage hardware
Virtual Hard Disk Types
Both VHD and VHDX support three disk types:
- Fixed: Allocates the full specified size immediately on the host. Best I/O performance, no storage expansion surprises
- Dynamically expanding: Starts small and grows as data is written. Convenient for development; can fragment over time; best used on SSDs
- Differencing: Stores only changes relative to a parent disk. Used for checkpoints and rapid VM deployment from a template
Step 1 — Create Virtual Hard Disks
Create a fixed VHDX (best performance):
New-VHD -Path "D:VMsServer01-OS.vhdx" -SizeBytes 80GB -Fixed
Create a dynamically expanding VHDX:
New-VHD -Path "D:VMsServer01-Data.vhdx" -SizeBytes 500GB -Dynamic
Create a differencing disk based on a parent (for template-based deployments):
New-VHD -Path "D:VMsServer02-OS.vhdx" -ParentPath "D:TemplatesWS2012R2-Sysprep.vhdx" -Differencing
Step 2 — Attach Disks to Storage Controllers
Generation 1 VMs use IDE for the OS disk and SCSI for additional disks. Generation 2 VMs use SCSI only. Add a hard disk drive to a VM:
# For Generation 1 - OS disk on IDE (required):
Add-VMHardDiskDrive -VMName "Server01" -ControllerType IDE -ControllerNumber 0 -ControllerLocation 0 -Path "D:VMsServer01-OS.vhdx"
# Add a data disk on SCSI:
Add-VMHardDiskDrive -VMName "Server01" -ControllerType SCSI -ControllerNumber 0 -ControllerLocation 0 -Path "D:VMsServer01-Data.vhdx"
For Generation 2 VMs, all disks attach to SCSI:
Add-VMHardDiskDrive -VMName "Server02-Gen2" -ControllerType SCSI -ControllerNumber 0 -ControllerLocation 0 -Path "D:VMsServer02-OS.vhdx"
Add-VMHardDiskDrive -VMName "Server02-Gen2" -ControllerType SCSI -ControllerNumber 0 -ControllerLocation 1 -Path "D:VMsServer02-Data.vhdx"
Step 3 — Resize a Virtual Hard Disk
VHDX disks can be expanded online (while the VM is running) if the disk is attached to a SCSI controller. The guest OS partition must also be extended after the disk is resized:
# Expand a VHDX to 200GB:
Resize-VHD -Path "D:VMsServer01-Data.vhdx" -SizeBytes 200GB
Inside the guest VM, extend the partition using PowerShell or Disk Management:
Resize-Partition -DriveLetter D -Size (Get-PartitionSupportedSize -DriveLetter D).SizeMax
Step 4 — Configure Pass-Through Disks
Pass-through disks give a VM direct access to a physical disk, bypassing the VHDX layer. This can improve performance for I/O-intensive workloads but sacrifices checkpoint and replication support. The physical disk must be offline on the host:
# Set the physical disk offline on the host:
Set-Disk -Number 2 -IsOffline $true
# Attach as pass-through to VM:
Add-VMHardDiskDrive -VMName "Server01" -ControllerType SCSI -ControllerNumber 0 -ControllerLocation 2 -DiskNumber 2
Step 5 — Configure iSCSI Storage for Hyper-V
Connecting Hyper-V hosts to iSCSI SANs is common in enterprise environments. Configure the iSCSI initiator on each Hyper-V host:
# Start and auto-start the iSCSI initiator service:
Start-Service MSiSCSI
Set-Service MSiSCSI -StartupType Automatic
# Connect to an iSCSI target:
New-IscsiTargetPortal -TargetPortalAddress "192.168.20.10"
Connect-IscsiTarget -NodeAddress "iqn.2014-01.com.example:storage01" -IsPersistent $true
Step 6 — Use SMB 3.0 File Shares for VM Storage
Windows Server 2012 R2 Hyper-V supports storing VM files on SMB 3.0 shares, enabling Scale-Out File Server (SOFS) as shared storage for Hyper-V clusters. Configure a VM to store its files on an SMB share:
# Set the default VM storage path on the host:
Set-VMHost -ComputerName "HV-Host01" -VirtualHardDiskPath "\SOFSVMStorageVHDs" -VirtualMachinePath "\SOFSVMStorageVMs"
# Create a new VM on the SMB share:
New-VM -Name "SMBStorageVM" -Generation 2 -MemoryStartupBytes 2GB -SwitchName "VMSwitch" -NewVHDPath "\SOFSVMStorageVHDsSMBStorageVM.vhdx" -NewVHDSizeBytes 60GB -Path "\SOFSVMStorageVMsSMBStorageVM"
Step 7 — Optimise VHD/VHDX Files
Dynamically expanding VHDXs can accumulate unused space. Compact them to reclaim host storage (VM must be off):
Optimize-VHD -Path "D:VMsServer01-Data.vhdx" -Mode Full
Convert a VHD to VHDX format (VM must be off):
Convert-VHD -Path "D:VMsServer01-OS.vhd" -DestinationPath "D:VMsServer01-OS.vhdx"
Convert from dynamic to fixed (for production performance):
Convert-VHD -Path "D:VMsServer01-Data.vhdx" -DestinationPath "D:VMsServer01-Data-Fixed.vhdx" -VHDType Fixed
Step 8 — Inspect VHD/VHDX Files
Get-VHD -Path "D:VMsServer01-OS.vhdx" | Select-Object Path, VhdType, VhdFormat, Size, FileSize, Fragmentation
The Fragmentation property shows the degree of internal fragmentation. Values above 10% suggest the disk should be compacted and defragmented.
Viewing All VM Disk Attachments
Get-VM | ForEach-Object {
$vm = $_
Get-VMHardDiskDrive -VMName $vm.Name | Select-Object @{N='VM';E={$vm.Name}}, ControllerType, ControllerNumber, ControllerLocation, Path
} | Format-Table -AutoSize
Summary
Storage configuration in Hyper-V on Windows Server 2012 R2 encompasses virtual disk format and type selection, controller architecture, pass-through options, iSCSI and SMB connectivity, and ongoing optimisation through compaction and conversion. Using VHDX format with fixed sizing on fast storage provides the best performance for production workloads. Dynamically expanding disks are appropriate for development and test environments. Leveraging SMB 3.0 and Scale-Out File Server opens up highly scalable, flexible shared storage solutions that integrate tightly with Hyper-V clustering capabilities.