PowerCLI: Check Partition Alignment (Windows VMs Only)


image

Some time ago I  already created a script to report the disk alignment status of your Windows VM’s. I updated the script so you are able to export it to a CSV or XML file.

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

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

    foreach ($objItem in $wmi){
        $Details = "" | Select-Object VMName, Partition, Status        
            if ($objItem.StartingOffset -eq "65536"){
                $Details.VMName = $objItem.SystemName
                   $Details.Partition = $objItem.Name
                $Details.Status = "Partition aligned"
            }
            else{
                $Details.VMName = $objItem.SystemName
                   $Details.Partition = $objItem.Name
                $Details.Status = "Partition NOT aligned"                    
            }
    $myCol += $Details
    }
}
$myCol | Export-Csv -NoTypeInformation "C:\Temp\PartitionAlignment.csv"
#$myCol | Export-Clixml "C:\Temp\PartitionAlignment.xml"


The script uses WMI to gather the information about the partition of the Windows VM. So if you’re using a Firewall, be sure to open the right ports. More info about WMI and Firewalls, can be found over here: http://msdn.microsoft.com/en-us/library/aa822854%28VS.85%29.aspx

The output will look like this:

image

Powershell: Check if partition is aligned or not


This script has the following Requirements:

  • VI Toolkit
  • Powershell
  • WMI query
  • Windows VM’s

The following script get al lists of all Windows VM’s which are powered on. The next step is a WMI query which queries the Win32_DiskPartition class. The final step is a match with the $StartingOffset variable.

Add-PSSnapIn VMware.VimAutomation.Core

# Connect to vCenter
$VC = Connect-VIServer (Read-Host "Enter vCenter server")

$StartingOffset = "65536"

# Get all VM’s with powerstate = PoweredOn
$VMS = Get-VM | Where {$_.PowerState -eq "PoweredOn"} |Sort Name
ForEach ($VM in $VMS)
    {
  
# Process only Windows Server VM’s
   if ($VM.Guest.OSFullName -match "Microsoft Windows*")
        {  
      
# Do a WMI Query
       $results = get-wmiobject -class "Win32_DiskPartition" -namespace "root\CIMV2" -ComputerName $VM

           foreach ($objItem in $results)
                {
              
# Do the match
               if ($objItem.StartingOffset -match $StartingOffset){
                  
write-host $objItem.SystemName
                  
write-host $objItem.Name
                  
write-host "Partition aligned" -foregroundcolor green
                  
write-host}
              
else{
                  
write-host $objItem.SystemName
                  
write-host $objItem.Name
                  
write-host "Partition NOT aligned" -foregroundcolor red
                  
write-host                  
                    }
                }
        }
    }
# Disconnect from vCenter
Disconnect-VIServer -Confirm:$False

after running the script, the following output will be generated:

image

VMware: Partition/disk aligned or not?


 

De Laatste weken zag ik het topic Partition/Disk Alignment verschillende malen langs komen. Ik maakte tot op heden nog geen gebruik van deze optie en wilde er nu wel eens het fijne van weten. VMware heeft een whitepaper gepubliseerd over dit onderwerp. Deze vind je hier:

Partition alignment is a known issue in physical file systems, and its remedy is well-documented. The goal of the testing reported in this paper was to validate the assumption that unaligned partitions also impose a penalty when the partition is a VMware Virtual Machine File System (VMware VMFS) partition.

This paper lists a summary of the results of our testing, recommendations for VMware VMFS partition alignment, and the steps needed to create aligned VMware VMFS partitions.

http://www.vmware.com/pdf/esx3_partition_align.pdf

Nadat je de whitepaper hebt gelezen, wil je natuurlijk zelf ook wel eens kijken hoe dit in zijn werk gaat. Ik kwam een how to tegen, die geschreven is door Harley Stagner en gepost is op: http://searchvmware.techtarget.com/.

Voordat je door kunt gaan, heb je een pc of een VM nodig met daarop de Windows Automated Installation Kit (AIK) geïnstalleerd.

To install Windows AIK, you need to download the image from Microsoft, burn it to a DVD and install it. Once WindowsAIK is installed, go to Start, then Programs, then Windows AIK, then Windows PE Tools command prompt. Note: If you use Windows Vista, you have to right-click on the Windows PE Tools command prompt entry and select RunAs Administrator.

With the command prompt open, you need to run a command that will set up the directory structure needed to create your WinPE 2.0 disk. Run the following at the command prompt:

copype <arch> <destination>

Where <arch> is your processor architecture (x86, amd64, or ia64) and <destination> is a path to a local directory. Below is an example of running this command:

copype x86 c:\winpe-2_0 <enter>

copy c:\winpe\winpe.wim c:\winpe-2_0\iso\sources\boot.wim /y

image 

The final step is the creation of the iso file. This can be done with the following command:

oscdimg -n -h -bc:\winpe-2_0\etfsboot.com c:\winpe-2_0\iso c:\winpe-2_0\winpe_diskpart.iso

image

 

Nu de iso klaar is, kunnen we een nieuwe VM opstarten met winpe_diskpart.iso

image

Run Diskpart:

Diskpart
select disk 0 (of een ander nummer, als je een andere disk wilt alignen)
create partition primary align=64

image

Via msinfo32 kun je de alignment nakijken.

How to tell if your disks are aligned
How can you tell if a disk is unaligned at the Windows partition level? Remember the MBR statement — that x86 systems use the first 63 sectors. Usually there are 512 bytes per sector. If you do the math, 63 x 512 = 32,256. To verify this, log into a machine (physical or virtual) as an administrator that has not had its system volume aligned. Go to Start, then Run, then type in "msinfo32.exe" and press enter. Navigate down to Components, then Storage, then Disks. Notice that the partition starting offset for Disk #0, Partition #0 (the system volume) is 32,256 bytes. This means that the disk is not aligned.

If the partition Starting Offset is 65.536 bytes, the disk is aligned.
image

Meer informatie over disk alignment vind je hier: http://blogs.netapp.com/storage_nuts_n_bolts/2009/01/mbrscanmbralign.html

Als je kunt inloggen op now.netapp.com/. Dan kun je hier de tool mbrscan downloaden. Via deze tool kun je vanaf het Service Console de Alignment nakijken. Netapp is ook bezig met een ander script genaamd mbralign. Via dit script kun je de alignment aanpassen zonder dataverlies.

 

Update: Rudolf  Kleijwegt poste de volgende reacite: In Windows 2008 is het niet meer nodig om de Windows Automated Installation Kit te gebruiken. Je kunt namelijk tijdens het installeren de toetsencombinatie SHIFT+F10 gebruiken om een command prompt te openen. Op dat moment heb je de beschikking over diskpart en kun je een uitgelijnde partitie aanmaken. Deze procedure gaat helaas niet op voor Windows 2003. Als je daar SHIFT+F10 gebruikt krijg je een recovery console met een uitgeklede diskpart.