Checking Virtual Machines Partitions Alignment

Today I will be providing you a useful PowerCLI script, that will help you identify if any Windows virtual machine in your environment, does not have properly aligned partition(s).

This article is not about VMFS, but Windows partitions alignment. And it only applies to Microsoft Windows pre-Vista/2008 guest operating systems, because Microsoft has corrected this issue; by moving from aligning to sector 63 by default to aligning to sector 2048.

The PowerCLI script  provided, will connect to a VMware vCenter server or vSphere ESX host, and check every Windows guest OS with “Power On” state. The results will be informed per virtual machine and by partition in a CSV file.

#Add-PSSnapin VMware.VimAutomation.Core
Connect-VIServer Your.vCenter.Server.Or.vSphere.Host

$myCol = @()
$vms = get-vm | where {$_.PowerState -eq "PoweredOn" -and `
 $_.Guest.OSFullName -match "Microsoft Windows*" } | Sort Name

foreach($vm in $vms){
trap {continue}
$wmi = get-wmiobject -class "Win32_DiskPartition" `
 -namespace "root\CIMV2" -ComputerName $vm

foreach ($objItem in $wmi){
$Details = "" | Select-Object VMName, Partition, StartingOffset, Status
if (($ObjItem.StartingOffset % 4096) -eq 0)
$Details.VMName = $objItem.SystemName
$Details.Partition = $objItem.Name
$Details.StartingOffset = $ObjItem.StartingOffset
$Details.Status = "Partition aligned"
} else {
$Details.VMName = $objItem.SystemName
$Details.Partition = $objItem.Name
$Details.StartingOffset = $ObjItem.StartingOffset
$Details.Status = "Partition NOT aligned"
$myCol += $Details
$myCol | Export-Csv -NoTypeInformation "Z:\Your.CSV.File.Name.csv"

Did you find any virtual machine with partitions not properly aligned?  There are several way to correct them, and tools that can be used too:

  • GParted: Is a free partition editor for graphically managing your disk partitions. You can find it here.
  • UBERAlign: Anothe free alternative, a free and powerful tool resolve this issue for everyone in the VMware community, created by Nick Weaver. You can find it here.
  • VMware vCenter Converter: You can now align partitions as part of a V2V conversion. You can find it here.
  • Quest vOptimizer Pro: Improves VM I/O performance through 64K partition block alignment. You can find it here.

Comments are closed.

%d bloggers like this: