VMware always recommends formatting and creating a new VMFS volume using the vSphere Client as it automatically aligns your VMFS volume. However, if you do not have access to the vSphere Client or you wanted to format additional VMFS volumes via a kickstart, you can do so using the CLI and the partedUtil under /sbin.

~ # /sbin/partedUtil
Not enough arguments
Get Partitions : get
Set Partitions : set ["partNum startSector endSector type attr"]*
Delete Partition : delete Resize Partition : resize
Get Partitions : getptbl
Set Partitions : setptbl

With ESXi 5, an MBR (Master Boot Record) partition table is no longer used and has been replaced with a GPT (GUID Partition Table) partition table. There is also only one block size of 1MB versus the 2,4 and 8 that was available in ESX(i) 4.x

We can view the partitions of a device by using the "getptbl" option and ensure we don't have an existing VMFS volume:

~ # /sbin/partedUtil "getptbl" "/vmfs/devices/disks/mpx.vmhba1:C0:T2:L0"
652 255 63 10485760

Next we will need to create a partition by using the "setptbl" option:

/sbin/partedUtil "setptbl" "/vmfs/devices/disks/mpx.vmhba1:C0:T2:L0" "gpt" "1 2048 10474379 AA31E02A400F11DB9590000C2911D1B8 0"

The "setptbl" accepts 3 arguments:

  • diskName
  • label
  • partitionNumber startSector endSector type/GUID attribute

The diskName in this example is the full path to the device which is /vmfs/devices/disks/mpx.vmhba1:C0:T2:L0

The label will be gpt

The last argument is actually a string comprised of 5 individual parameters:

  • partitionNumber - Pretty straight forward
  • startSector - This will always be 2048 for 1MB alignment for VMFS5
  • endSector - This will need to be calculated based on size of your device
  • type/GUID - This is the GUID key for a particular partition type, for VMFS it will always be AA31E02A400F11DB9590000C2911D1B8

To view all GUID types, you can use the "showGuids" option:

~ # /sbin/partedUtil showGuids
Partition Type       GUID
vmfs                 AA31E02A400F11DB9590000C2911D1B8
vmkDiagnostic        9D27538040AD11DBBF97000C2911D1B8
VMware Reserved      9198EFFC31C011DB8F78000C2911D1B8
Basic Data           EBD0A0A2B9E5443387C068B6B72699C7
Linux Swap           0657FD6DA4AB43C484E50933C84B4F4F
Linux Lvm            E6D6D379F50744C2A23C238F2A3DF928
Linux Raid           A19D880F05FC4D3BA006743F0F84911E
Efi System           C12A7328F81F11D2BA4B00A0C93EC93B
Microsoft Reserved   E3C9E3160B5C4DB8817DF92DF00215AE
Unused Entry         00000000000000000000000000000000

Once you have the 3 arguments specified, we can now create the partition:

~ # /sbin/partedUtil "setptbl" "/vmfs/devices/disks/mpx.vmhba1:C0:T2:L0" "gpt" "1 2048 10474379 AA31E02A400F11DB9590000C2911D1B8 0"
0 0 0 0
1 2048 10474379 AA31E02A400F11DB9590000C2911D1B8 0

UPDATE (01/15) - Here is a quick shell snippet that you can use to automatically calculate End Sector as well as creating the VMFS5 volume:

partedUtil mklabel ${DEVICE} msdos
END_SECTOR=$(eval expr $(partedUtil getptbl ${DEVICE} | tail -1 | awk '{print $1 " \\* " $2 " \\* " $3}') - 1)
/sbin/partedUtil "setptbl" "${DEVICE}" "gpt" "1 2048 ${END_SECTOR} AA31E02A400F11DB9590000C2911D1B8 0"
/sbin/vmkfstools -C vmfs5 -b 1m -S $(hostname -s)-local-datastore ${DEVICE}:1

We can verify by running the "getptbl" option on the device that we formatted:

~ # /sbin/partedUtil "getptbl" "/vmfs/devices/disks/mpx.vmhba1:C0:T2:L0"
652 255 63 10485760
1 2048 10474379 AA31E02A400F11DB9590000C2911D1B8 vmfs 0

Finally we will now create the VMFS volume using our favorite vmkfstools, the syntax is the same as previous release of ESX(i):

~ # /sbin/vmkfstools -C vmfs5 -b 1m -S himalaya-SSD-storage-3 /vmfs/devices/disks/mpx.vmhba1:C0:T2:L0:1
Checking if remote hosts are using this device as a valid file system. This may take a few seconds...
Creating vmfs5 file system on "mpx.vmhba1:C0:T2:L0:1" with blockSize 1048576 and volume label "himalaya-SSD-storage-3".
Successfully created new volume: 4dfdb7b0-8c0dcdb5-e574-0050568f0111

Now you can refresh the vSphere Client or run vim-cmd hostsvc/datastore/refresh to view the new datastore that was created.

23 thoughts on “How to Format and Create VMFS5 Volume using the CLI in ESXi 5

  1. AFAIK the partition for a VMFS volume must end on a cylinder boundary, so selecting the last sector for the partition table needs to be done using the formula endSector = ( C * H * S – 1).

    In your example, C=652, H=255, S = 63, taking the product and subtracting one gives 10474379 as shown.

  2. @Dredd,

    Thanks for the information, the numbers are actually from a VMware installation and I was looking through the esxi_install.log to get these numbers, I was interested in how this was calculated as well.

  3. Either of you know any way to avoid the check “Checking if remote hosts are using this device as a valid file system. This may take a few seconds…” prior to creating the filesystem? I’d like to measure the time it takes to create filesystems backed by various types of storage. Thanks.

  4. I am getting the following error while executing the command partedUtil “setptbl” /vmfs/devices/disks/mpx.vmhba1:C0:T0:L0 “gpt” “1 2048 10474379 AA31E02A400F11DB9590000C2911D1B8 0″

    Error: Read-only file system during write on /dev/disks/mpx.vmhba1:C0:T0:L0
    SetPtableGpt: Unable to commit to disk

  5. Did anyone find a solution to this? We are getting the same message Error: Read-only file system during write on /dev/disks/naa.600508b1001c282ee975ec5ff98a098c
    WriteNewPtable: Unable to commit to disk

  6. Thanks to Willian I’ve been using this method to kickstart numerous systems and it all worked fine. Today I came across a slightly different system (older) and it was refusing create VMFS partition table with “can not satisfy all constraints” error. Spent some time troubleshooting and one of VMware KBs pointed at partedUtil getUsableSectors. The end sector from getUsableSectors was less than what cyls*heads*sects – 1. And partedUtil was happy to make me a new partition. Just FYI

  7. It would appear that this method will not work when attempting to create a datastore on the disk that ESXi is installed on and running from. partedUtil will consistently error out with “Read-only file system during write on /dev/disks/foo.bar”. This is frustrating because you CAN edit the datastores on a disk that ESXi is running on from within vSphere itself.

    Clearly ESXi is capable of configuring the disk it is running on. I was wondering if there is an alternate set of commands to run that set the disk up for write before running partedUtil.

    • The partition doesn’t exist yet because we use the –novmfsondisk option in kickstart. We recently tried removing that flag and then deleting the partition first, which it will do with no complaints, but then it refuses to remake that partition with the same error as above.

    • Did you adjust the start sector value?
      Should be obvious, but if you already have ESXi installed on that disk, there is around 1GB of data already on that disk and a 2MB offset alignment isn’t going to work. I would probably let the GUI tools do the work and then go back and reverse engineer the start sector to determine the proper value.

  8. William , I would love it if you could expand on this topic with the concept of a rolling VMFS 5 upgrade in mine.

    Example, youhave 8 1TB DataStores on VMFS3 and using a 4MB Block Size.
    You want to upgrade to VMFS 5 now that all your hosts and vCenter and such are upgraded.
    The best Practice states you create a new DS thats VMFS5, then SvMotion the VMs off an existing DS over to that one and then delete and re-create the entire LUN and start over.

    I would like to see an example of instead of deleting the LUN (and pestering the storage admin), using the above tools you mentioned to document the proper values from the existing DS, and then wipe it and create a fresh DS using VMFS 5 optimized values.

    This way we pester the Storage admin once to add another LUN to the cluster, and then after that the VMware admin can do the rest of the rolling upgrade on their own.

  9. I am having similar issues but my error out of the hostd.log shows the following:

    Error: Connection timed out during read on /dev/disks/mpx.vmhba1:C0:T1:L0
    WriteNewPtable: Unable to commit to disk

    • This is not a vmware issue; its a RAID/volume/SAN disks problem/incorrect setup. Disks might be presented to multiple hosts causing a write error lock/ The paths may be incorrectly setup /volume may be read only, etc..

  10. “With ESXi 5, an MBR (Master Boot Record) partition table is no longer used and has been replaced with a GPT (GUID Partition Table) partition table.”
    No entirely true. GPTs are hardware dependable. They are only there, if the disk and the bios support them, regardless of the OS used (ESXi or otherwise).
    ESXi 5 in a old supported server with old HDs, will have a nice MBR in it. I know mine do.

  11. Thank you for the clear and concise writeup. I just used this to create a datastore on my home ESXi 5 box because I can’t use the vSphere client since I’m on Linux and I can’t seem to get it to work under Wine. This was very helpful!

    I’d echo the comment about the MBR. When I created the partition, I actually forgot to include the “gpt” parameter. Running getptbl on the new partition returned “msdos”

    Also, thanks to the commenter who posted the formula to find the ending sector!

  12. William – There are tons of articles and discussions on the web regarding partition alignment for guests. Here is my $1,000,000.00 question – For a default ESXi 5.1 update 2 and ESXi 5.5 update 2 installation, there is no options to configure the partition during installation. After the installation is complete, reboot. At the ESXi service console, login, run partedUtil, the starting sector is 64 !! Every VM doc on the web says ESXi 5.0 and above creating VMFS5+ creates aligned partitions. Starting sector of 64 is misaligned. What am I doing wrong? Or all this is just in my head? Thanks

  13. There’s a way to set a partition type of disk ?

    I’ve splitted my mini 2012 1tb disk in two, and got the following ptbl

    121601 255 63 1953525168
    1 40 409639 C12A7328F81F11D2BA4B00A0C93EC93B systemPartition 128
    2 409640 952255591 48465300000011AAAA1100306543ECAC unknown 0
    3 952255592 953525127 426F6F74000011AAAA1100306543ECAC unknown 0
    4 953526272 1953523711 EBD0A0A2B9E5443387C068B6B72699C7 linuxNative 0

    how can I change the partition 4 to 0xfb to (UUID AA31E02A400F11DB9590000C2911D1B8) and format disk with vmkfstools ?

Thanks for the comment!