Categories

Testing the 4K boundary

Advanced Format disks have started shipping –see http://managedux.com/2011/04/26/using-vbscript-to-check-partitions-for-advanced-format-4k-512e-sector-alignment/

These disks use a 4096 byte sector instead of 512. To get the best performance from these disks the partitions have to be aligned to a 4K boundary. This happens automatically in Windows 2008 and above. 

We need to be able to start testing partition alignment. This function uses a couple of WMI classes to do just that.

function test-4KAligned {
[CmdletBinding()]
param (
   [string]$computer=".",
  
   [ValidatePattern("[A-Z]:")]
   [string]$drive
)

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

foreach ($partition in $partitions){
 
  $query = "ASSOCIATORS OF {Win32_DiskPartition.DeviceID='$($partition.DeviceID)'} WHERE AssocClass=Win32_LogicalDiskToPartition"
  $disktopart = Get-WmiObject -ComputerName $computer -Query $query
 
 
if (($partion.StartingOffset % 4096) -eq 0){
   $align = $true
}
else {
   $align = $false
}
 
$diskpartition = New-Object -TypeName PSObject -Property @{
   Partition = $partition.Name
   Description = $partition.Description
   AlignedTo4Kboundary = $align
   Drive = $disktopart.DeviceID
}
if ($drive) {
   if ($drive -eq $diskpartition.Drive){$diskpartition}
}
else {$diskpartition}
}

}#process

<#
.SYNOPSIS
Tests disk partition alignment to 4k boundary

.DESCRIPTION
Tests disk partition alignment to 4k boundary.
See
http://managedux.com/2011/04/26/using-vbscript-to-check-partitions-for-advanced-format-4k-512e-sector-alignment/
and
http://msdn.microsoft.com/en-us/library/hh182553.aspx

Default is that all drives are tested

.PARAMETER  computer
Computer to test

.PARAMETER  drive
Drive to test

.EXAMPLE
test-4kaligned

Tests local machine

.EXAMPLE
test-4kaligned -computer server01

Tests remote machine

.EXAMPLE
test-4kaligned -computer server01 -drive C:

Tests C: drive on remote machine

#>

}

The test is performed using modulus arithmetic on the starting offset. A result of zero means its divisible exactly by 4096 so is aligned.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>