Creating an Aligned VMDK with FDISK in ESX for NetApp Storage

While this is less of an issue, as Windows Server 2008 and Windows 7 VMs already have the proper offset, I occasionally find that I have to create a one-off Linux or Windows Server 2003 VM. That being the case, I want to refer to NetApp documentation for creating a properly aligned disk, but always have trouble finding the document. Here is an excerpt from the NetApp document TR-3747 Best Practices for File System Alignment inVirtual Environments (page 18, section 4.4.3 for Linux guests).

INSTRUCTIONS FOR LINUX:

  1. Create only one virtual disk (vmdk file) to host the different filesystems (/boot, /var, /, and swap).
  2. Log in to the ESX service console.
  3. CD to the VM directory and view this directory by typing the following commands (shown below):
    cd /vmfs/volumes/RHEL/RHEL
    ls
  4. Get the number of cylinders from the vdisk descriptor by typing the following command (this
    number will differ depending on several factors involved with the creation of your .vmdk file):
    cat RHEL.vmdk
    (see ddb.geometry.cylinders = “xxxx”)
  5. Run fdisk on the RHEL.vmdk file by typing the following command:
    fdisk ./RHEL-flat.vmdk
  6. You will have to set the number of cylinders.
    Type in x and then press Enter.
  7. Enter c and press Enter.
  8. Type in the number of cylinders that you found from step 5 and press enter.
  9. Type p at the expert command screen to look at the partition table (which should be blank)
  10. Return to regular (non-extended) command mode by typing r at the prompt.
  11. Create a new 100MB partition to host the /boot filesystem by typing n and then p when asked for
    the partition type.
  12. Enter 1 for the partition number, 1 for the first cylinder (NOTE: There is a typo in the pdf that tells you to hit enter again at the last cylinder question)
  13. Enter +100MB for the last cylinder question.
    Note: During RHEL installation, the default block size of 1024 bytes will be used for the 100MB
    filesystem that will be mounted as /boot. This does not effect alignment, but will result in less
    efficient writes when compared to using a filesystem block size of 4096 bytes or a multiple
    thereof. However, because /boot is only written to during install (15MB), upgrade, and
    configuration changes there is no need to change this.
  14. Go into extended mode to set the starting offset by typing x
  15. Set the starting offset by typing b and pressing Enter, selecting 1 for the partition and pressing
    Enter, and entering 64 and pressing Enter. Please note that ‘64’ is used as an example. You can
    choose any value as long as it is divisible by 8
    Note: The reason the logical block address needs to be divisible by 8 is because each sector is
    512 bytes in size. Eight multiplied by 512 results in 4096 (or 4KB).
  16. Check the partition table by typing p
  17. Type r to return to the regular menu.
  18. To set the system type to Linux, type t
  19. For the hexcode type 83
  20. Create a second partition on the same vmdk to host the other filesystems (/, /var, boot) on LVM by
    typing n and then p when asked for the partition type.
  21. Enter 2 for the partition number, choose default value for the first cylinder, and press Enter for the
    last cylinder question and use the default value.
  22. Go into extended mode to set the starting offset by typing x
  23. Set the starting offset by typing b and pressing Enter, selecting 2 for the partition and pressing
    Enter, and entering 208848 as the new beginning of data and pressing Enter.
    Note: Please note that ‘208848’ is used as an example. You can choose any value (higher than
    the default value displayed on the screen) as long as it is divisible by 8.
    Note 2: The reason the logical block address needs to be divisible by 8 is because each sector is
    512 bytes in size. Eight multiplied by 512 results in 4096 (or 4KB).
  24. Type r to return to the regular menu
  25. To set the system type to Linux LVM, type t
  26. Type 2 to enter the partition you just created (step ommitted from PDF version)
  27. For the Linux LVM hexcode type 8e
  28. Save and write the partitions by typing w. Ignore the warning, as this is normal.
  29. Start the VM and run Linux setup. Make sure to press Esc to bring up the boot menu and select
    “CD ROM drive” to boot from the CD
  30. On the partitioning layout screen, select “Create Custom Layout” and click “Next”
  31. On the screen to specify the partitions for different filesystems, select the first partition /dev/sda1
    and click “edit”. Select “format partition as” to ext3, and specify the mount point as “/boot”
  32. Next, select /dev/sda2 and click “LVM” to open the “Make LVM Volume Group” screen
  33. On the “Make LVM Volume Group” screen, click “Add”  to open the “Make Logical Volume” screen
  34. Enter the mount point, type, name and size and click “ok”. Add the different mount points (/, /var,
    swap).
  35. Click “Ok” to go back to the screen that shows the different partitions and click “Next”
  36. You will see the Format warnings popup screen for partition /dev/sda1. Click “Format”.
  37. Complete the Linux installation by clicking “Next” and following the standard best practices as you
    would do normally in your environment.

Continue reading