Skip to content

            Lost ?  |  Need an account:
 
Home >> Knowledge Base >> Virtualization >> VMware ESX Server >> VMware Disk Alignment - Preparing VMDK for Windows Installation
VMware Disk Alignment - Preparing VMDK for Windows Installation PDF Print E-mail
(18 votes, average 4.22 out of 5)
Written by Tom Hirt   
Thursday, 09 April 2009 14:13
Article Index
VMware Disk Alignment
Checking VMFS Disk Alignment
Aligning VMFS and Linux using fdisk
Preparing VMDK for Windows Installation
All Pages

 

Preparing VMDK for Windows Installation


If you are installing Windows Server 2000, 2003 or Windows XP on a physical server or desktop, you cannot fix disk alignment at the time of installation.  You can fix data partitions and other volumes that are added later (see our KB on Windows disk Alignment), but not the boot volume.  Worse yet, once Windows has been installed on the drive, there is no way to fix the alignment, it must be done when the partition is created –now there’s a catch-22.  This is rather frustrating knowing you’re taking a performance hit on the boot volume because it cannot be aligned.

Fortunately, in VMware, we can fix the drive alignment before the OS is ever installed!  We can use fdisk from the service console and set the partition alignment before Windows is installed.  Lets hear it for VMware!

  1. Create a new virtual machine using the virtual infrastructure client (do not power on the machine).

  2. From your service console, change directory to the location of the newly created virtual machine

    # cd /vmfs/volumes/487bba15-14da54c8-f2a0-001e4ffbda71/WIN
    /vmfs/volumes/487bba15-14da54c8-f2a0-001e4ffbda71/WIN # ls -l
    -rw-------    1 root     root    8589934592 Apr  9 17:49 WIN-flat.vmdk
    -rw-------    1 root     root          370 Apr  9 17:49 WIN.vmdk
    -rw-------    1 root     root            0 Apr  9 17:49 WIN.vmsd
    -rwxr-xr-x    1 root     root         1189 Apr  9 17:49 WIN.vmx
    -rw-------    1 root     root          258 Apr  9 17:49 WIN.vmxf

  3. Get the number of cylinders from the VMDK.  The line begins with 'ddb.geometry.cylinders'

    /vmfs/volumes/487bba15-14da54c8-f2a0-001e4ffbda71/WIN # cat WIN.vmdk

    # Disk DescriptorFile
    version=1
    CID=41e9d328
    parentCID=ffffffff
    createType="vmfs"

    # Extent description
    RW 16777216 VMFS "WIN-flat.vmdk"

    # The Disk Data Base
    #DDB

    ddb.virtualHWVersion = "4"
    ddb.uuid = "60 00 C2 90 24 ba cd bd-f2 35 ca ab 3e 73 37 a2"
    ddb.geometry.cylinders = "1044"
    ddb.geometry.heads = "255"
    ddb.geometry.sectors = "63"
    ddb.adapterType = "lsilogic"

  4. Run fdisk on the WIN-flat.vmdk file

    /vmfs/volumes/487bba15-14da54c8-f2a0-001e4ffbda71/WIN # fdisk ./WIN-flat.vmdk

    Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
    Building a new DOS disklabel. Changes will remain in memory only,
    until you decide to write them. After that, of course, the previous
    content won't be recoverable.

    You must set cylinders.
    You can do this from the extra functions menu.
    Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

    Command (m for help):

  5. Set the number of cylinders from step #3 above.  Ignore fdisk’s warning about the cylinder size being larger than 1024, this only applies to older systems and is not applicable to us.

    Command (m for help): x

    Expert command (m for help): c
    Number of cylinders (1-1048576): 1044

    The number of cylinders for this disk is set to 1044.
    There is nothing wrong with that, but this is larger than 1024,
    and could in certain setups cause problems with:
    1) software that runs at boot time (e.g., old versions of LILO)
    2) booting and partitioning software from other OSs
    (e.g., DOS FDISK, OS/2 FDISK)

    Expert command (m for help):

  6. Confirm your cylinder is set correctly and no partitions exist on the new disk

    Expert command (m for help): p

    Disk ./WIN-flat.vmdk: 255 heads, 63 sectors, 1044 cylinders

    Nr AF  Hd Sec  Cyl  Hd Sec  Cyl    Start     Size ID
    1 00   0   0    0   0   0    0          0          0 00
    2 00   0   0    0   0   0    0          0          0 00
    3 00   0   0    0   0   0    0          0          0 00
    4 00   0   0    0   0   0    0          0          0 00

    Expert command (m for help):

  7. Exit from expert mode and create a new primary partition using the defaults

    Expert command (m for help): r

    Command (m for help): n
    Command action
    e   extended
    p   primary partition (1-4)
    p
    Partition number (1-4): 1
    First cylinder (1-1044, default 1):
    Using default value 1
    Last cylinder or +size or +sizeM or +sizeK (1-1044, default 1044):
    Using default value 1044

    Command (m for help):

  8. Return to expert mode and change the start offset to align the disk.  The start block should be a value that not only aligns the NTFS partition within the VMFS, but also aligns the VMFS with the LUN.  As such, use should use the same start block you used when originally creating the VMFS partition on the LUN.  If your not absolutely positive, using a start block of 2048 (2048 = 1024KB) will cover most configurations.  However, you should ask your storage administrator for the LUN's alignment size to be absolutely certain.

    Command (m for help): x

    Expert command (m for help): b
    Partition number (1-4): 1
    New beginning of data (63-16771859, default 63): 2048

    Expert command (m for help):

  9. Print the partition table to verify the starting offset is set correctly

    Expert command (m for help): p

    Disk ./WIN-flat.vmdk: 255 heads, 63 sectors, 1044 cylinders

    Nr AF  Hd Sec  Cyl  Hd Sec  Cyl    Start     Size ID
    1 00   1   1    0 254  63 1023        128   16771732 83
    2 00   0   0    0   0   0    0          0          0 00
    3 00   0   0    0   0   0    0          0          0 00
    4 00   0   0    0   0   0    0          0          0 00

    Expert command (m for help):

  10. Return from exit mode and set the filesystem type to ‘HPFS/NTF’

    Expert command (m for help): r

    Command (m for help): t
    Selected partition 1
    Hex code (type L to list codes): 7
    Changed system type of partition 1 to 7 (HPFS/NTFS)

    Command (m for help):

  11. Exit fdisk and write the changes to the VMDK.  You can safely ignore the warning about error 25

    Command (m for help): w
    The partition table has been altered!

    Calling ioctl() to re-read partition table.

    WARNING: Re-reading the partition table failed with error 25: Inappropriate ioctl for device.
    The kernel still uses the old table.
    The new table will be used at the next reboot.
    Syncing disks.
    /vmfs/volumes/487bba15-14da54c8-f2a0-001e4ffbda71/WIN #

  12. Power on the virtual machine and begin the normal Windows installation process.

  13. When the installer gets to the partition screen, install on the existing partition (hit enter).  Do not destroy or recreate the partition or you will lose the sector alignment.

    Windows Partition Setup

If all went well, after the install has completed, you can download the Disk Alignment Check Tool from our downloads area and verify your drives alignment.  For additional details on Microsoft Windows platforms and disk alignment, see our Windows Disk Alignment KB.

Note: Any new partitions created within the VM should use the procedures outline in the Windows Disk Alignment KB but with the same start offset used in step #8.

Enjoy you new optimized VM!

 

 


Add this page to your favorite website
AddThis Social Bookmark Button


Comments
Add New Search
Andre  - Nice step-by-step guide... |15/01/2010 14:12:22
I already read various articles about disk alignment. Your's is the one I bookmarked. Nice job.
BTW, it seems someone changed a setting in step 8 and did not replace the picture in step 9. (2048 blocks should really not result in a 128 blocks offset;-)))
Travis  - Nice write up |27/01/2010 11:02:46
Very nice write on disk alignment. I followed all the steps and when I went to install Windows I pressed enter in step 13 of your guide and the next screen asked me if I wanted to format the partition. Should this happen?
Anonymous |03/02/2010 15:36:41
In step 11, command
Code:
# vmkfstools –C –createfs vmfs3 –b 4m /dev/disks/vmhba32\:0\:0\:0\:1

should looks like
Code:
# vmkfstools –C vmfs3 –b 4m /dev/disks/vmhba32\:0\:0\:0\:1

One should use "-C" or "--createfs".
admin |03/02/2010 20:20:40
Nice catch! I've updated step #11 to reflect the change.

Thanks!
-Tom
ericgc |18/02/2010 10:28:51
how come that command is not in step 11 anymore?
Anonymous |26/02/2010 03:19:52
Hello,

Does this apply to windows 2008 as well?

/Nick
thirt |03/03/2010 12:08:48
Hi Nick,

No, Microsoft finally got around to fixing this in Windows 2008. I guess they received enough fan mail on the topic to address it. :D

Best
-Tom
amikolajczyk  - IT Manager |08/10/2010 07:53:16
Hi, could you explain this a little more? What was the "this" that got fixed in 2008? Is it no longer necessary to do this in Windows 2008? I just followed your steps for a 2008 R2 VM and it failed to get past POST.

I checked a recently deployed 2008 R2 server with your alignment check script and it reported everything was aligned A-OK even though I didn't manually do any manual steps at all.

Thanks for this guide, I read a lot of them and this was hands-down the best explanation along with the best step-by-step guide.

Regards,
AJM
Berni |28/08/2010 08:39:56
Great article about disk aligment. Thanks!

But how can I extend an existing volume with the right aligment? When I extend the volume in VIC, the second disk is not aligned :(
victor |02/01/2011 18:18:56
If I were to clone the aligned VM does the alignment follow or not?
Denis |15/02/2011 14:00:06
Hi, Tom! Thanks.

But i don't understand, why we align a windows partition of virtual machine, if vmdk-flat-files already aligned, because they are consist of 1MB clusters of VMFS file system.
Anthony Vandewerdt |06/04/2011 23:11:02
Hi.

Great pictures.
You make the statement:
NTFS is formatted in blocks ranging from 1MB to 8MB

Do you mean VMFS?
If I check here, NTFS uses clusters that are nowhere near that big:
http://support.microsoft.com/kb/140365
erski  - Partition 1 has different physical/logical beginni |19/11/2011 01:46:22
I've made changes to disk step by step and I got this error:

Disk /dev/sda: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders, total 8388608 sectors
Units = sectors of 1 * 512 = 512 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 224909 111431 83 Linux
Partition 1 has different physical/logical beginnings (non-Linux?):
phys=(0, 1, 1) logical=(0, 32, 33)

/dev/sda2 224910 2329424 1052257+ 82 Linux swap / Solaris
/dev/sda3 2329425 8385929 3028252+ 83 Linux

Any idea how to resolve the problem?
Mark W |12/02/2012 19:26:15
Hi, you mention in the article that once a windows partition is created and windows installed, you cannot change the offset. This is incorrect. You can boot off a gparted live cd, add a 2MB offset, then once its done that, change it to 1MB offset and then it aligns correctly. The two step process is necessary due to the way Gparted calculates the space.
Magik  - Sr Systems Engineer |22/02/2012 11:57:45
If you can get your hands on a tool called MBRALIGN from NetApp Host Utilities for ESX then you can use this to run against VMDK files to fix the offset of existing virtual disks. It takes advantage of the fact that your partition is a VMDK and simply fixes the VMDK.

Rick
C. Beerse  - re: |25/04/2012 08:30:05
victor wrote:
If I were to clone the aligned VM does the alignment follow or not?

Depends on the clone tool: Most (older) tools just do a block copy of the guest disks. Hence, the allignment does not change.
From vmware-converter 5.x (and workstation 8?) there is an option that optimizes the disk allignment. That updates the allignment to the conversion target. Current versions of other (vmware based) converters do the same.
C. Beerse  - re: IT Manager |25/04/2012 08:33:36
amikolajczyk wrote:
Hi, could you explain this a little more? What was the "this" that got fixed in 2008? Is it no longer necessary to do this in Windows 2008? I just followed your steps for a 2008 R2 VM and it failed to get past POST.

As far as I know, msW2k8 and newer installations start with an 1 MByte offset for this allignment by default. That is with disks over a (relative small) size. If you create a realy small filesystem (less than 1 GB) it is reported the 63KByte first block missallignment is still there.

I can imagine microsoft has done this because as a result of its own virtualisation business. I donnot have the impression this allignment is some active optimum.
Write comment
Name:
Email:
 
Website:
Title:
UBBCode:
[b] [i] [u] [url] [quote] [code] [img] 
 
 
:D:):(:0:shock::confused:8):lol::x:P:oops::cry::evil::twisted::roll::wink::!::?::idea::arrow:
 
Please input the anti-spam code that you can read in the image.

!joomlacomment 4.0 Copyright (C) 2009 Compojoom.com . All rights reserved."

Last Updated on Wednesday, 03 February 2010 20:19
 

Forum Activity

Author: Cogterrit
May.18.12
Author: Cogterrit
May.18.12
Author: Cogterrit
May.18.12
Author: Cogterrit
May.17.12

Online Stats

Guests Online: 83
Members Online: 1