Geoff's Knowledgebase

Sep 7

Realign Windows VM Partition after Installed


VMware and the storage vendors have been saying for quite some time that virtual machine partitions need to be aligned for best performance with iSCSI and Fiber Channel storage. Unfortunately for Windows machines that typically meant formatting the hard disk of a virtual machine with very specific settings BEFORE installing Windows. I had many machines that were physical and imported into VMware using a P2V tool, and couldn’t align the partition after installation.

Using these steps I am able to now align the partition properly. I am getting much better performance with my virtual machines after aligning the partition. Windows XP and Server 2003 VMs have benefited. My Server 2008 VMs already had the proper alignment.

Check for alignment problems

The first step was to check for an alignment problem. From what I read online, the partition should be aligned with a 1024 KB starting position. My existing machines had less than 512 kb start. I modified a script that I found online to clean up some coding errors. Save this file as “align.vbs” and run it against your Windows virtual machine:

Option Explicit
dim strOutput
dim lngStartingOffset
dim strComputer
dim objWMIService
dim colDiskPartitions
dim objPartition

'get the local computer and disk partitions
strComputer = “.”
Set objWMIService = GetObject(“winmgmts:{impersonationLevel=impersonate}!\” & strComputer & “\root\cimv2”)
Set colDiskPartitions = objWMIService.ExecQuery(“Select * from Win32_DiskPartition”)
For each objPartition in colDiskPartitions
 ’write the partition details to the output
 strOutput = “”
 strOutput = strOutput & “Device ID: ” & objPartition.DeviceID & vbcrlf      
 strOutput = strOutput & “=============================================” & vbcrlf
 strOutput = strOutput & “Number Of Blocks:” & vbTab & objPartition.NumberOfBlocks  & vbcrlf  
 strOutput = strOutput & “Block Size:” & vbTab & objPartition.BlockSize & ” KB”& vbcrlf
 strOutput = strOutput & “Total Volume Size:” & vbTab & Round( (objPartition.Size/1024/1024/1024), 0) & ” GB” & vbcrlf
 strOutput = strOutput & “Type: ” & vbTab &  vbTab & objPartition.Type & vbcrlf
 strOutput = strOutput & “Starting Offset:” & vbTab & objPartition.StartingOffset & ” (” & objPartition.StartingOffset/1024 & ” KB)” & vbcrlf

 ’performing a MOD operation on a large number can result in an overflow. Make the number lower before attempting MOD.
 lngStartingOffset = objPartition.StartingOffset
 do until lngStartingOffset < 2147483647.5 
  lngStartingOffset = lngStartingOffset / 1024
 ’if the starting offset is evenly divisible by 1024 then the partition is aligned.
 If (lngStartingOffset Mod 1024) = 0 Then
  strOutput = strOutput & “  Disk Alignment:” &  vbTab & “Aligned” & vbCRLF
  If ( (lngStartingOffset / 1024) < 1024 ) Then
   strOutput = strOutput & vbCrLf & “  * Please note, this is not necessarly a problem, however we noticed” & vbcrlf
   strOutput = strOutput & “    your starting offset is less than the Microsoft recommended size” & vbcrlf
   strOutput = strOutput & “    of 1024 KB.  Please see Microsoft’s KB article 929491 for ” & vbcrlf
   strOutput = strOutput & “    additional details.”
  End If
  strOutput = strOutput & “  Disk Alignment:” &  vbTab & “NOT ALIGNED!!” & vbCRLF
 End If
 ’alert the user
 msgbox strOutput

Perform the Alignment Operation

  1. Run the alignment check script to verify that the partition needs to be aligned.
  2. Shut down the Windows VM.
  3. Make a backup copy of the VM in case the align operation goes bad.
  4. Set the option to mount the gparted.iso file at power on, and set the BIOS to boot to the CD first.
  5. Boot.
  6. Leave the keyboard mapping “dont touch keymap”, language at default (33), and Boot x-windows gparted automatically (continue to start x)
  7. Select the disk and partition.
  8. Select “Resize/Move” from the toolbar
  9. Set the free space preceding: 2 and Align to: none. Click Resize/Move
  10. Click OK at the start sector warning.
  11. Click “Apply” in the toolbar and check Apply at the “are you sure” prompt.
  12. Wait for the long disk operation to complete.
  13. Set the free space preceding: 1 and Align to: none. Click Resize/Move
  14. Click OK at the start sector warning.
  15. Click “Apply” in the toolbar and check Apply at the “are you sure” prompt.
  16. Wait for the long disk operation to complete.
  17. Exit GParted, double click the Exit icon, and shutdown the machine.
  18. Unmount the GParted live CD.
  19. Attempt to boot Windows. You may need to repair the boot sector by booting to the installation disk and dropping to a recovery console:       fixmbr \Device\HardDisk0
  20. After booting Windows I am prompted to restart after scanning for new hardware.
  21. Run the Alignment check script again to verify that the partition is now aligned.