A couple of days ago we were troubleshooting a problem with one of our Windows 2003 systems performance with our Equallogic PS400E iSCSI storage system. The problem turned out to be caused by poor alignment of our disk partitions. Since we discovered that disk alignment could have a more dramatic affect than we had ever thought we decided to undertake a project to properly align all of our Windows and Linux systems. The Linux systems with LVM were pretty easy to move, but the Windows systems proved much more troublesome, espeically the boot drive. I was finally able to come up with a free solution that took time, but worked pretty well. I thought I'd document it here in case it helps anyone else.
First you should probably decide if you want to align all your volumes, or just the data volumes. Realigning the data volumes can be easily accomplished with tools like Ghost or Clonezilla, or even simply xcopy, robocopy, or backup/restore procedures. Simply add a new disk, create an aligned partition, and copy the data with your tool of choice. Doing the same on the boot partition is a little more inovled since it's pretty easy to break the boot loader by moving data all around.
There are several reasons you might want to align your existing boot partition though, in many cases your swap file is on that partition and if your system does any swapping an aligned partition can be much faster. In our case we had several systems that had been migrated from older systems where everything was all on the C: drive. These systems used postgres database, did lots of logging, had some MSSQL Express thrown in, etc. While it might have been possible to reinstall and move all of these applications to a D: drive, it seemed like a lot of work and the documentation on the various apps was pretty weak. We decided it would be better if we could figure out a way to align the partition data without a reinstall.
This turned out to be much more difficult that I first thought. We didn't own a version of Ghost that would clone Windows 2003 reliably, and so I went searching for a free solution. Clonezilla seemed promising, and we created the first clone of our system with it, but we were never able to get the newly cloned, properly aligned partition to boot.
Then I decided to give Gparted a try. Gparted is a great tool that can boot from a live CD and resize and move your existing partitions. The thought here was to use Gparted to simply resize the existing partition by 64 sectors and the move it slightly to the right to an aligned location. Unfortunately Gparted wasn't quite as easy as I had hoped, mainly because the GUI only allows you to set sizes by MiB, not by sector. Still, I was undeterred, and I found a way to manipulate Gparted to do what I wanted. It takes two passes, which can take a long time if you have largish system paritions, but most of our were less that 16GB, with typically only about 8GB used. Here what I did:
!!! MAKE A BACKUP/SNAPSHOT IN CASE THINGS GO WRONG !!!1. Make sure the disk is defragmented
2. Boot the system with the Gparted live CD.
3. Select the parition you are wanting to resize and choose (Move/Resize)
4. Shrink the volume by some amount, the smaller you shrink it the faster it will copy during the move step. I usually shrink it a GB or so larger than the amount of data on the drive.
5. Move the partition to right by a few MB's to free up space at the start of the disk.
6. Once the move completes, exit Gparted, not the entire live CD, just the Gparted application
7. Start the terminal window on the live CD
8. In the command window type 'parted /dev/sda' (substitute your actual device here) to start the command line parted editor
9. Create a new partition at the start of the disk to fill in the space up to the section where you want to align your parition. For example, if you want your system partition to start at sector 128, create a very small partition that takes up space from sectors 63-127. The command would be something like this:
mkpart primary 63s 127s
This tells parted to create a new primary partition from sector 63 to sector 127. That means the very next sector available is 128, a stripe aligned partition. You may want a different start sector based on your array (some use 64K, some 128K, some bigger) but I've found the 128K alignment to work well with both 64K (Equallogic) and 128K (EMC Clariiion) stripe sizes.
10. Exit parted and restart the Gparted GUI by clicking the Gparted icon.
11. Use the Move/Resize option to resize the NTFS partition to fill the entire remaining space. As pointed out by several users, you
MUST uncheck the "Round to Cylinders" option prior to this. I guess I thought this was obvious since we're trying to align to a specific sector but that's why I'm not a documentation writer.
12. Exit gparted, run parted again, remove the small partition you created earlier and reboot.
Now you have a nice, stripe aligned NTFS partition that should still boot right up normally. The first reboot will run a checkdisk to make sure all the moving and resizing didn't damage anything on the disk. Enjoy the improved performance and lowered IOPS on your SAN storage!
Obviously the steps above are just an outline, you really shouldn't try this unless you understand what the above means, but if your comfortable with manipulating partitions the above should be enough to give you an idea what to do. I've found that the above procedure takes about 15-30 minutes for a typical 8-10GB system partition, so keep that in mind when planning downtime. Also, make sure your future OS deployments are aligned so you don't have to repeat this again.
The above procedures work for virtual machine too (assuming the VMFS volume is aligned as well, which is done automatically with VI3 volumes and above). There are some other tools which will to this at the VMDK layer (Netapp has mbralign available to their customers and Vizioncore's vOptimizer Pro will do it without having to copy the entire VMDK) but I don't have any experience with these tools and I needed something that would work for physical machines too. The above procedure did the trick for me.
Thursday, July 2. 2009 at 07:22 (Link) (Reply)
i'm not sure but the partition in this example don't should start on the 129th sector ?
127 x 512 is 65024 bytes of starting partition offset, mybe is not aligned !
what is your partition starting offset now ?
Thursday, July 2. 2009 at 09:03 (Reply)
Take a look at http://clariionblogs.blogspot.com/2008/02/disk-alignment.html for a nice diagram.
Friday, July 24. 2009 at 17:09 (Reply)
Wednesday, August 12. 2009 at 10:06 (Reply)
Error obtained is : Nex size can't be less the space already occupied by data. you either need to delete unused files or see the -i option
Please advise
Wednesday, August 12. 2009 at 10:27 (Link) (Reply)
Wednesday, August 12. 2009 at 10:47 (Reply)
Your procedure was very helpfull.
Thursday, August 20. 2009 at 07:57 (Reply)
One further question, you mentioned it was fairly easy to align Linux machines that use LVM, could you elaborate on that? My LVM knowledge is pretty sparse.
Thanks,
Sunday, August 30. 2009 at 15:04 (Reply)
I'm a complete Linux noob and am sorry for having to ask this stupid question regarding step 12 - what's the exact command for "remove partition" in parted?
Monday, September 7. 2009 at 20:11 (Reply)
Monday, October 5. 2009 at 12:24 (Reply)
Great tutorial, unfortunatly the mkpart primary 63s 127s reported to may primary partitions...the test system I am using only has one.
Since I am no linux/unix expert any help much appreciated in driving the Lived CD part of his procedure.
Wednesday, November 11. 2009 at 18:57 (Reply)
Thursday, November 19. 2009 at 19:11 (Reply)
Dude, I have been trying to get Diskpart to do this for at least a year with NO LUCK! I have a legacy app with a database designed by a neophyte. I have been adding indices, tuning queries, and getting hateful stares from those forced to use it. This will certainly help me out.
Thank you! Thank you! Thank you!
Grampy
Saturday, November 21. 2009 at 02:46 (Link) (Reply)
Can you tell me how to identify if the disks are aligned or not ?
Sunday, November 22. 2009 at 20:02 (Link) (Reply)
With Linux you would generally use fdisk in expert mode or parted to list the starting sector. If you just took defaults you'll typically see the starting sector as 63. For 64K alignment you'd want the partition to start on sector 128 (sectors start at 0), for 128K the sector should be 256 and so on.
Wednesday, December 23. 2009 at 06:42 (Reply)
Partition Disk #0, Partition #0
Partition Size 74,53 GB (80.023.651.328 bytes)
Partition Starting Offset 97.792 bytes
Partition Disk #0, Partition #1
Partition Size 32,50 KB (33.280 bytes)
Partition Starting Offset 32.256 bytes
Friday, January 29. 2010 at 10:34 (Link) (Reply)
-Michael
Friday, January 29. 2010 at 13:00 (Reply)
Thursday, March 25. 2010 at 11:49 (Reply)
I noticed that moving a partition with 26 GB was done in around 10 or 15 minutes. in this time it can not have aligned every physical sector.
Do you agree?
I think a workarround would be moving the partition to the end of the harddisk if the harddisk is big enough (at least the double size of the used data on the partition) and then moving it back to sector 2048, so every used sector must be moved physically... but that would imply that every sector of the ssd has been written once a time which is also not good for the performance of a ssd I think...
Monday, March 29. 2010 at 10:38 (Link) (Reply)
More proof? When I did this on a VM with a snapshot, the snapshot grew to almost exactly 2x the original partition, which would make sense because it would have to write changes for both the move to the right, and the move back to the "aligned" location.
Monday, March 29. 2010 at 11:03 (Reply)
Very nice proof with vmware...
As mentioned at the beginning: Thank you!
Monday, March 29. 2010 at 10:31 (Reply)
Thanks
Monday, March 29. 2010 at 10:43 (Link) (Reply)
I wish I had a better suggestion. Are you sure that the Windows partition is still marked active when you are done? Can you boot a Windows CD in rescue mode and try "fixmbr" or "fixboot" maybe. Just a few thoughts.
Tuesday, April 20. 2010 at 11:00 (Reply)
Thank you.
Friday, May 7. 2010 at 00:54 (Link) (Reply)
Facing the daunting taks of having to reinstall and reconfigure everything I started looking into adjusting the partition and found this guide to be invaluable. But there was an unexpected shortcut I thought of sharing.
Before starting the partition shrink/move process (the drive had one 119Gb partition which used all available space of the drive; about 40Gb of the partition was in use), I imaged the drive using commercial O&O Disk Image Professional 5 (http://bit.ly/arBnmn) in offline mode (booted from Disk Image Pro's boot disk) to make sure the image was clean/complete. I checked the partition rather than the entire disk to be imaged and left the default "Complete->Used Sector" imaging method unchanged.
Then I proceeded to adjust/move the partition with GParted. It ran about 40 minutes and in the end spat out an error stating that the boot partition was now larger that the device and thus corrupted. It is possible that I incorrectly set the move/size parameters or perhaps there was a software error. Either way, I started restore from image, planning to retry partition adjustment once the image restore was complete. ~40Gb restore from a Raptor to SSD drive took only some 15 minutes. I booted into Windows just to make sure the image restore worked and the system started without any problems. I then checked how the restored partition looked like using diskpar, and was surprised to find out that StartingOffset was now the desired 1048576 instead of the original value of 32256! It seems that simply dropping the boot partition (which in this case spanned the entire SSD) into an image and then restoring it into "entire drive" (i.e. not into an existing partition but into entire drive which I chose primarily because I knew the partition on the SSD was corrupted due to the failed GParted run) automatically fixed the alignment problem! This feature may well be specific to O&O Drive Image 5, but it saved the effort of having to move/adjust the partition with GParted.