| Advertise on warmetal.nl! Click for more information about advertising here. |
Did you find this website useful? Did I save you a lot of time? |
|
For information about why you should keep LUNs aligned with your vmdks I'd like to refer to this article from yellow-bricks.com. It explains why alignment is important, but I'll tell you it comes down to performance. When the LUNs, vmdk and Guest OS blocks are not aligned the array will request more blocks than the VMs are actually asking for.
Please note the following remarks:
[root@esx01 ~]# gunzip mbrtools.tar.gz [root@esx01 ~]# tar -xf mbrtools.tar [root@esx01 ~]# ll total 3860 -rwxrwxrwx 1 root root 86949 Apr 28 2009 howto.pdf -rw------- 1 root root 1629 Apr 13 21:53 ks.cfg -rwxrwxrwx 1 root root 962284 Apr 16 2009 mbralign -rwxrwxrwx 1 root root 134186 Apr 28 2009 mbralign1.2.pdf -rwxrwxrwx 1 root root 771276 Oct 5 2008 mbrscan -rw-r--r-- 1 root root 1960960 May 12 12:57 mbrtools.tar -rwxrwxrwx 1 root root 1133 Apr 28 2009 readme.html
After obtaining the NetApp tools you can use the mbrscan tool:
This option can be used when scanning one VM or when scanning an entire host (while using the -all switch).
If VM is running:
[root@esx01 WINXP01]# /root/mbrscan WINXP01-flat.vmdk -------------------- Failed to open WINXP01-flat.vmdk - [Device or resource busy] --------------------
So create a snapshot and rerun:
[root@esx01 WINXP01]# /root/mbrscan WINXP01-flat.vmdk -------------------- WINXP01-flat.vmdk p1 (NTFS) lba:63 offset:32256 aligned:No --------------------
Note: You can run the tool using the ”–all” switch which will scan all -flat.vmdk files that are on the host.
You can check disks from within Windows:
For misaligned VMs, you typically will find that the VM is running with a default starting offset value of 32,256, which is not completely divisible by 4,096; hence, the partition is not aligned.
This option can be used when you just want to know if one particular VM is aligned.
# Original script: http://ict-freak.nl/2009/12/15/powercli-check-partition-alignment-windows-vms-only/ # Changed: Sjoerd Hooft - 10 Nov 2011 $myCol = @() $timestamp = Get-Date -format "yyyyMMdd-HH.mm" $cluster = "Acceptance" $csvfile = "D:\sjoerd\$timestamp-alignmentinfo-$cluster.csv" #$vms = Get-Datacenter "The Netherlands" | get-vm | where {$_.PowerState -eq "PoweredOn" -and $_.Guest.OSFullName -match "Microsoft Windows*" } | Sort Name $vms = Get-Cluster $cluster | get-vm | where {$_.PowerState -eq "PoweredOn" -and $_.Guest.OSFullName -match "Microsoft Windows*" } | Sort Name foreach($vm in $vms){ $wmi = $null $wmi = get-wmiobject -class "Win32_DiskPartition" -namespace "root\CIMV2" -ComputerName $vm # Use default authentication, but if unsuccesfull try other credentials until succesfull $teller = 1 while (($wmi -eq $null) -and ($teller -lt 4)){ Write-Host "Enter Credentials for $vm. This is try $teller, with a maximum of 3 tries." -Foregroundcolor Red $wmi = get-wmiobject -class "Win32_DiskPartition" -namespace "root\CIMV2" -ComputerName $vm -Credential domain\sjoerd $teller++ } foreach ($objItem in $wmi){ $Details = "" | Select-Object VMName, Partition, Status, StartingOffSet,Size if ($objItem.StartingOffset -eq $null){ Write-Host "Checking $vm" $vmview = Get-VM $vm | Get-View $Details.VMName = $vmview.Name $Details.Status = "VM could not be analyzed" } else{ # Divide StartingOffset by 4096 and round the number to zero decimals # If both numbers are the same then the partition is aligned $divoffset = ($objItem.StartingOffset / 4096) if ([System.Math]::Round($divoffset,0) -eq $divoffset){ $Details.VMName = $objItem.SystemName $Details.Partition = $objItem.Name $Details.Status = "Partition aligned" $Details.StartingOffSet = $objItem.StartingOffset $Details.Size = $objItem.Size } else{ $Details.VMName = $objItem.SystemName $Details.Partition = $objItem.Name $Details.Status = "Partition NOT aligned" $Details.StartingOffSet = $objItem.StartingOffset $Details.Size = $objItem.Size } } $myCol += $Details } } $myCol | Export-Csv -NoTypeInformation $csvfile
For alignment we'll use the mbralign tool. To do so, follow these steps:
directory in the datastore. These files end in “-mbralign-backup” and can be removed from the Virtual Center Client datastore
browser or from the ESX service console.
[root@esx01 WINXP01]# ll total 6676992 -rw-r--r-- 1 root root 82109 Apr 12 16:20 vmware-45.log -rw-r--r-- 1 root root 69145 Apr 12 16:20 vmware-46.log -rw-r--r-- 1 root root 66815 Apr 12 16:20 vmware-47.log -rw-r--r-- 1 root root 81427 Apr 12 16:20 vmware-48.log -rw-r--r-- 1 root root 54797 Apr 12 16:20 vmware-49.log -rw-r--r-- 1 root root 62878 Apr 12 16:20 vmware-50.log -rw-r--r-- 1 root root 64727 Apr 12 20:33 vmware-51.log -rw-r--r-- 1 root root 97232 May 12 14:29 vmware.log -rw------- 1 root root 8589934592 May 12 14:29 WINXP01-flat.vmdk -rw------- 1 root root 8684 Apr 13 22:33 WINXP01.nvram -rw------- 1 root root 566 Apr 12 16:20 WINXP01.vmdk -rw-r--r-- 1 root root 43 May 12 13:42 WINXP01.vmsd -rwxr-xr-x 1 root root 2814 May 12 14:29 WINXP01.vmx -rw-r--r-- 1 root root 1587 Apr 13 22:33 WINXP01.vmxf
Start the mbralign tool and confirm there are no snapshots:
[root@esx01 WINXP01]# /root/mbralign WINXP01.vmdk Part Type old LBA New Start LBA New End LBA Length in KB P1 07 63 64 16755796 8377866 NOTICE: This tool does not check for the existence of Virtual Machine snapshots or linked clones. The use of this tool on a vmdk file that has a snapshot or linked clone associated with it can result in unrecoverable data loss and/or data corruption. Are you sure that no snapshots/linked clones exist for this vmdk? (y/n)y Creating a backup of WINXP01.vmdk Creating a backup of ./WINXP01-flat.vmdk Creating a copy the Master Boot Record Working on partition P1 (3): Starting to migrate blocks from 32256 to 32768. 12801 read ops in 6 sec. 59.82% read (15.74 mB/s). 59.82% written (15.74 mB/s) --- 12801 read ops in 2 sec. 98.88% read (46.99 mB/s). 98.88% written (46.99 mB/s) Working on space not in any partition: Starting to migrate blocks. 100.00 percent complete. 100.00 percent written. . Making adjustments to ./WINXP01-flat.vmdk. Adjusting the descriptor file. [root@esx01 WINXP01]# ll total 15066688 -rw-r--r-- 1 root root 82109 Apr 12 16:20 vmware-45.log -rw-r--r-- 1 root root 69145 Apr 12 16:20 vmware-46.log -rw-r--r-- 1 root root 66815 Apr 12 16:20 vmware-47.log -rw-r--r-- 1 root root 81427 Apr 12 16:20 vmware-48.log -rw-r--r-- 1 root root 54797 Apr 12 16:20 vmware-49.log -rw-r--r-- 1 root root 62878 Apr 12 16:20 vmware-50.log -rw-r--r-- 1 root root 64727 Apr 12 20:33 vmware-51.log -rw-r--r-- 1 root root 97232 May 12 14:29 vmware.log -rw-r--r-- 1 root root 8589935104 May 12 14:38 WINXP01-flat.vmdk -rw------- 1 root root 8589934592 May 12 14:29 WINXP01-flat.vmdk-mbralign-backup -rw------- 1 root root 8684 Apr 13 22:33 WINXP01.nvram -rw------- 1 root root 566 May 12 14:38 WINXP01.vmdk -rw-r--r-- 1 root root 566 May 12 14:31 WINXP01.vmdk-mbralign-backup -rw-r--r-- 1 root root 43 May 12 13:42 WINXP01.vmsd -rwxr-xr-x 1 root root 2814 May 12 14:29 WINXP01.vmx -rw-r--r-- 1 root root 1587 Apr 13 22:33 WINXP01.vmxf [root@esx01 WINXP01]# /root/mbrscan WINXP01-flat.vmdk -------------------- WINXP01-flat.vmdk p1 (NTFS) lba:64 offset:32768 aligned:Yes --------------------
As you can see, the vmdk file is aligned now and there are two backup files. The VM started successfully so the two backup files van be deleted.
Note: You can run the mbralign utility with several options:Options: --sparse The resulting file will be sparse. This option is designed for NetApp NFS based datastores. --force The default behavior is to skip properly aligned disks. The --force option can be used to override this. (Useful for migrating and making sparse). --bs=n Use n as the block size (specified in kB). n must be one of (8, 16, 32, 64, 128, 1024). The default is 8. --codeview Show what would be done, then exit. No changes are made to the file. --quiet Only print warnings and errors (no other status isi printed to screen). --debug Print debug comments. --help Print usage. --thereAreNoVmSnapshots Supcodess the warning message about snapshots and answer YES to the question of whether to continue.
grub>find /boot/grub/stage1 (hd0,0) [old, misaligned vmdk file] (hd1,0) [new, aligned vmdk file] grub>root (hd1,0) grub>setup (hd1) Checking if "/boot/grub/stage1" exists... yes Checking if "/boot/grub/stage2" exists... yes Checking if "/boot/grub/e2fs_stage1_5" exists... yes Running "embed /boot/grub/e2fs_stage1_5 (hd1)"... 17 sectors are embedded. succeeded Running "install /boot/grub/stage1 (hd1) (hd1)1+17 p (hd1,0)/boot/grub/stage2 /boot/grub/menu.lst"... succeeded Done.
#!/bin/bash ######################################################################################################################## # Author : Sjoerd Hooft # Date Initial Version: 27 December 2011 # Comments: sjoerd_warmetal_nl # # Description: # Script to align the disks of a Virtual Machine # # Recommendations: # The script is designed for a 120 column terminal. # The running user must be root. # # Changes: # Please comment on your changes to the script (your name and email address, line number, description): # DATE - USERNAME - EMAILADDRESS - CHANGE DESCRIPTION ######################################################################################################################## # Possible improvements # Ways out if the VM does not shut down or start up properly # Email notification of the report/logfile # Debug option; uncomment for debugging # set -x # Script Variables HOSTNAME_SHORT=`hostname -s` BASEDIR=`dirname $0` WHATAMI=`basename $0` LOGFILE="$BASEDIR/$WHATAMI.log" DATE=`date +%Y%m%d` # Highlight output on screen BOLD=`tput bold` BOLDOFF=`tput sgr0` # Send all output to logfile; disable if screen output is needed exec > $LOGFILE 2>&1 # Align Variables align=/tmp/netapp/mbralign # Write down the name of the Virtual Machine to align inputvm=$1 if [ -z "$inputvm" ]; then echo echo "Usage $0 Script:" echo "--------------------------------------" echo "$BOLD $0 <NAME of VM> $BOLDOFF" echo "--------------------------------------" echo echo NAME of VM: Name of VM as found in vCenter, case sensitive echo exit fi functioncheckvm() { vmxfile=`vmware-cmd -l | grep $inputvm` checkvmexists=`vmware-cmd -l | grep $inputvm | wc -l` if [ "$checkvmexists" != "1" ]; then echo VMexists is $checkvmexists echo VM $inputvm does not exist. echo Is $inputvm located on this host? If not please vMotion the VM to this host. echo Exiting... exit fi snapshotexist=`vmware-cmd $vmxfile hassnapshot | cut -f3 -d" "` if [ "$snapshotexist" != "0" ]; then echo Snapshotexists is $snapshotexist echo VM $inputvm has snapshot, exiting... exit fi echo VM $inputvm does esixt and has no snapshots. Continuing... } functionstopvm() { vmware-cmd $vmxfile stop trysoft stopstate=on while [ "$stopstate" != "off" ] do stopstate=`vmware-cmd $vmxfile getstate | cut -f3 -d" "` echo Stopstate = $stopstate sleep 10 done } functionaligndisks() { # Record time echo start time is `date +%H%M` for disks in $(cat $vmxfile | grep vmdk | grep -v vmfs | cut -f2 -d"\"" ); do dir=`dirname $vmxfile` echo $dir/$disks $align --thereAreNoVmSnapshots $dir/$disks done for disks in $(cat $vmxfile | grep vmdk | grep vmfs | cut -f2 -d"\"" ); do echo $disks $align --thereAreNoVmSnapshots $disks done # Record time echo end time is `date +%H%M` } functionstartvm() { vmware-cmd $vmxfile start trysoft startstate=5 while [ "$startstate" != "1" ] do startstate=`vmware-cmd $vmxfile gettoolslastactive | cut -f3 -d" "` echo Startstate = $startstate sleep 10 done } functioncheckvm functionstopvm functionaligndisks functionstartvm exit
I used this week to evaluate Paragon for ESX and am sorry that I have to inform you that the outcome is not positive:
There were also a few positive points:
Overall I would say that the technique used is very good, but would be better if it would do multiple disks at the same time so the overall speed would improve. I also really miss the option to schedule jobs while the VMs are still running. Using this tool would mean I'd have to get up at night, configure the tool and start the alignment. I would have to wait for it to finish so I can start the VMs before business hours. That makes it unacceptable.
Je begrijpt denk ik wel dat dit alles bij elkaar niet zo positief is. Vaak werkt de tool niet, als hij werkt is het niet echt gebruikersvriendelijk en hij is traag. Helaas kan ik dus geen positief advies geven. Ik krijg er geen warm gevoel van en heb eigenlijk het idee dat de alignment optie niet “af” is, dat het er meer bij is gezet voor de echte functionaliteit, namelijk storage space reclaiming.
Overigens ben ik wel te spreken over de support en de hulp, nogmaals mijn dank daarvoor.
Discussion