Are all your guest OS partitions correctly aligned?

Guest OS partition alignment isn’t a new topic, but it is important that you deal with any misaliged disks to ensure that you are getting the best out of your storage. This post will cover how to identify which of your windows VM’s are affected using PowerShell and WMI.

Firstly, to put the performance differences into perspective, here are the results of a simple iometer benchmark comparing misaligned IO (on the left) to correctly aligned IO (on the right).

IOPS;

IOPS-Alignment

Throughput;

MBps-Alignment

Latency;

AvgRespTime-Alignment

As you can see from these results, there are significant advantages of using correctly aligned disks. Now you need to find out if you have any misaligned disks with this simple PowerShell script.

Remember to change the parameters on the highlighted rows;

  • Row 15 – your vCenter Server name
  • Row 24 – your VM’s in Scope
  • Row 67 – the path to export the CSV results
Check Disk Alignment;
## =============================================================================
## NAME : Check_Disk_Alignment.ps1
## AUTHOR : Jon Munday (www.jonmunday.net)
## DATE : 20/03/2013
## PURPOSE : This script Checks to see if NTFS partitions are aligned correctly
## =============================================================================

## Clear
Clear-Host

## Loads PowerCLI snap-in to the current session.
Add-PSSnapin vmware.vimautomation.core

## Connect to vCenter
$vcenter = 'myvcenter.mydomain.fqdn'
Write-Host "Connecting to $vcenter" -ForegroundColor Green
Connect-VIServer $vcenter | Out-Null

## Create empty array
$results = @()

## Get VM's you want check for alignment
Write-Host " - Getting list of Virtual Machines"
$computers = Get-Datacenter MyDatacenter | Get-VM -Name * | Where-Object {$_.PowerState -eq "PoweredOn"} | Sort Name

## Check each VM
foreach ($computer in $computers){
    $ping = Test-Connection -ComputerName $computer -Count 1 -Quiet

    IF($ping -eq 'True'){

    $partitions = Get-WmiObject -Class Win32_DiskPartition -ComputerName $computer

    foreach ($partition in $partitions){

    ## Association of Disk to Partition - For Example Disk #0, Partition #0 = C:\
    $query = "ASSOCIATORS OF {Win32_DiskPartition.DeviceID='$($partition.DeviceID)'} WHERE AssocClass=Win32_LogicalDiskToPartition"

    $disktopart = Get-WmiObject -ComputerName $computer -Query $query

        $Detail = New-Object PSObject -Property @{
            SystemName = $partition.SystemName
            Drive = $disktopart.DeviceID
            DiskName = $partition.Name
            BlockSize = $partition.BlockSize
            SizeGB = "{0:N2}" -f ($partition.Size/1024/1024/1024)
            StartingOffset = "{0:N0}" -f ($partition.StartingOffset)
            AlignmentCheck = If([Uint64]($partition.StartingOffset % 4096) -eq 0) {"Aligned"} Else {"NOT Aligned"}
        }

        $results += $Detail

        }
    }
}

## Display Results in PowerShell ISE Console
$results `
| Select SystemName,Drive,DiskName,BlockSize,SizeGB,StartingOffset,AlignmentCheck `
| Sort SystemName,Drive,DiskName `
| Format-Table -AutoSize

## Export Results to CSV
$results `
| Select SystemName,Drive,DiskName,BlockSize,SizeGB,StartingOffset,AlignmentCheck `
| Sort SystemName,Drive,DiskName `
| Export-CSV -Path C:\TEMP\DiskAlignment\Alignment_Results.csv -NoTypeInformation

## Disconnect from vCenter
Write-Host "Disconnecting from $vcenter" -ForegroundColor Yellow
Disconnect-VIServer -Server $vcenter -Force -Confirm:$false

Your results are displayed in both the Powershell console and exported to CSV where you can analyse them in Excel using pivot tables.

CSV Results;

Disk-Alignment-CSV-Results

Now the only thing left to do, is deal with the issue!

138,361 total views, 10 views today