Home VCAP-DCA 5 Using vmkfstools to Manage VMFS Datastores

Using vmkfstools to Manage VMFS Datastores

by admin

There are a number of VMFS filesystem related tasks you can run using vmkfstools.

Query a VMFS Volume

You can get information on a VMFS volume by running the following vmkfstools command:

~ # vmkfstools --queryfs -h /vmfs/volumes/NewVOL/
VMFS-3.54 file system spanning 1 partitions.
File system label (if any): NewVOL
Mode: public
Capacity 2.2 GB, 1.7 GB available, file block size 1 MB
UUID: 4ff9bb71-c0260379-3091-000c29e8410a
Partitions spanned (on "lvm"):
        mpx.vmhba1:C0:T2:L0:1
Is Native Snapshot Capable: NO

Creating a VMFS Volume using vmkfstools

VMware recommend using the vSphere client for creating any new VMFS datastores, but if you do have reason to create one from the command line, this is how it is done. First of all we need to create a partition on our new disk. This is done by running partedUtil. Running it without any arguments will show the following:

~ # partedUtil
Not enough arguments

Usage:
 Get Partitions : get 
 Set Partitions : set  ["partNum startSector endSector type attr"]*
 Delete Partition : delete  
 Resize Partition : resize    
 Get Partitions : getptbl 
 Set Partitions : setptbl  

We can view the partitions on a device by running:

~ # partedUtil  getptbl /vmfs/devices/disks/mpx.vmhba1:C0:T1:L0
msdos
652 255 63 10485760

Next, we will create a new partition on the device:

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

This command is made up of the following:

  • /vmfs/devices/disks/mpx.vmhba1:C0:T1:L0 – The device
  • gpt – the label
  • 1 – The partition number
  • 2048 – The start sector
  • 10474379 – The end sector – this is calculated by using this formula – end sector = ( C * H * S – 1). So in the case of my example it is 652 * 255 * 63 = 10474380. Minus the 1 and we end up with the end sector value I have used – 10474379
  • AA31E02A400F11DB9590000C2911D1B8 – The GUID for the partition type.
  • 0 – Attribute, set as 0.

You can check what GUID you need to use by running the following:

~ # 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

Now that the partition has been created we can check it by running:

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

We can now run vmkfstools to create the new VMFS datastore:

~ # vmkfstools --createfs vmfs5 --blocksize 1m -S NewVol /vmfs/devices/disks/mpx.vmhba1:C0:T1: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:T1:L0:1" with blockSize 1048576 and volume label "NewVol".
Successfully created new volume: 4ff21b6c-d32d89ed-be7b-000c29e8410a

Checking in the vSphere client, we can see that the datastore has been created:

part1

Extending a VMFS volume using VMKFSTOOLS

You can use vmkfstools to span a VMFS volume across disks (i.e adding an extent) in order to increase the size of the volume:

~ # vmkfstools --spanfs /vmfs/devices/disks/mpx.vmhba1:C0:T2:L0:1 /vmfs/devices/disks/mpx.vmhba1:C0:T1:L0:1


VMware ESX Question:
All data on /vmfs/devices/disks/mpx.vmhba1:C0:T2:L0:1 will be lost. Continue and format?
0) _Yes
1) _No

Select a number from 0-1: 0

Checking the datastore’s properties in the vSphere client, we can see that it has doubled in size and is spanning two extents/disks:
vmkfstools_span

Grow a VMFS Volume using VMKFSTOOLS

Along with spanning a VMFS volume across multiple disks, you can also grow a VMFS volume using VMKFSTOOLS. As with creating a VMFS volume it is recommended that this task is carried out using the vSphere client.

First of all we have to extent the partition. Start by listing the partition table on the disk where the VMFS volume you wish to extend exists:

~ # partedUtil getptbl /vmfs/devices/disks/mpx.vmhba1:C0:T2:L0
msdos
652 255 63 10485760
1 2048 5237189 251 0

Next we can determine what value to use for the last sector by running:

~ # partedUtil getUsableSectors /vmfs/devices/disks/mpx.vmhba1:C0:T2:L0
1 10485759

Next, we can resize the volume. Be careful to enter the correct sector values. Anything entered incorrectly here can destroy your partition/VMFS volume:

~ # partedUtil resize /vmfs/devices/disks/mpx.vmhba1:C0:T2:L0 1 2028 10485759

We can check that it resized correctly by running:

~ # partedUtil getptbl /vmfs/devices/disks/mpx.vmhba1:C0:T2:L0
msdos
652 255 63 10485760
1 2028 10485759 251 0

The last sector value should have changed. Finally, we can use VMKFSTOOLS to grow the VMFS volume:

~ # vmkfstools --growfs /vmfs/devices/disks/mpx.vmhba1:C0:T2:L0:1 /vmfs/devices/disks/mpx.vmhba1:C0:T2:L0:1

We can query the volume to ensure that the volume has grown:

~ # vmkfstools --queryfs -h /vmfs/volumes/NewVOL/
VMFS-3.54 file system spanning 1 partitions.
File system label (if any): NewVOL
Mode: public
Capacity 4.8 GB, 4.2 GB available, file block size 1 MB
UUID: 4ff9c8a0-27ae1bdb-4a70-000c29e8410a
Partitions spanned (on "lvm"):
        mpx.vmhba1:C0:T2:L0:1
Is Native Snapshot Capable: NO

Upgrading VMFS Datastores using VMKFSTOOLS

We can upgrade a VMFS datastore using vmkfstools by running the following command. We’ll be upgrading the datastore detail in the previous example. It is currently VMFS-3.54. To upgrade, run the following:

~ # vmkfstools --upgradevmfs /vmfs/volumes/NewVOL/


VMware ESX Question:
Please ensure that the VMFS-3 volume /vmfs/volumes/4ff9c8a0-27ae1bdb-4a70-000c29e8410a is not in active use by any local or remote ESX 3.x/4.x server.

We recommend the following:
1. Back up data on your volume as a safety measure.
2. Take precautions to ensure no ESX 3.x/4.x servers are accessing this volume.

Continue converting VMFS-3 to VMFS-5?
0) _Yes
1) _No

Select a number from 0-1: 0

Checking if remote hosts are using this device as a valid file system. This may take a few seconds...
Upgrading file system /vmfs/volumes/NewVOL/...
done.

Check that it has been upgrade successfully by using vmkfstools to query the VMFS volume:

~ # vmkfstools --queryfs -h /vmfs/volumes/NewVOL/
VMFS-5.54 file system spanning 1 partitions.
File system label (if any): NewVOL
Mode: public
Capacity 4.8 GB, 4.2 GB available, file block size 1 MB
UUID: 4ff9c8a0-27ae1bdb-4a70-000c29e8410a
Partitions spanned (on "lvm"):
        mpx.vmhba1:C0:T2:L0:1
Is Native Snapshot Capable: NO

We can see that the VMFS version is now VMFS-5.54.

Useful Links and Resources

Calculating a partitions end sector
https://www.virtuallyghetto.com/2011/07/how-to-format-and-create-vmfs-volume.html
https://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1036609

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More