Create vmfs datastores using the ESXi CLI

After configuring iscsi and mounting the LUNs into the ESXi hosts as described here it's time to partition and create the file system on the newly added SAN disk.


ESXi comes with two utilities needed to achieve this task.
- partedUtil
- vmkfstools

The process involves 2 steps, first partition the disk and then create a vmfs5 datastore:

My LUN is a 50GB LUN presented form a solaris box:

~ # ls -s /dev/disks/
.
.
.
.
52428800 naa.600144f04f16450000005463a0ac0001

1. Partition the disk with partedUtil:

To get partition types supported:

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

Get partition information for the LUN:

~ # partedUtil "getptbl" /vmfs/devices/disks/naa.600144f04f16450000005463a0ac0001
gpt
6527 255 63 104857600
~ # 

Create a new partition:


~ # partedUtil "setptbl" "/vmfs/devices/disks/naa.600144f04f16450000005463a0ac0001" "gpt" "1 2048 104857566 AA31E02A400F11DB9590000C2911D1B8 0"
gpt
0 0 0 0
1 2048 104857566 AA31E02A400F11DB9590000C2911D1B8 0
~ # 

in order:
- partition number
- starting sector
- last sector
- GUID/type
- attr

Note: the partition attribute is a number which describes the partition type. Common used are 128 (0x80) for bootable partitions, otherwise 0 for most partitions.

Check the new partition has been created:

~ # partedUtil getptbl "/vmfs/devices/disks/naa.600144f04f16450000005463a0ac0001"
gpt
6527 255 63 104857600
1 2048 104857566 AA31E02A400F11DB9590000C2911D1B8 vmfs 0
~ # 

2. Create the vmfs5 datastore using vmkfstools:

~ # vmkfstools -C vmfs5 -b 1m -S iscsi_datastore /vmfs/devices/disks/naa.600144f04f16450000005463a0ac0001:1
create fs deviceName:'/vmfs/devices/disks/naa.600144f04f16450000005463a0ac0001:1', fsShortName:'vmfs5', fsName:'iscsi_datastore'
deviceFullPath:/dev/disks/naa.600144f04f16450000005463a0ac0001:1 deviceFile:naa.600144f04f16450000005463a0ac0001: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 "naa.600144f04f16450000005463a0ac0001:1" with blockSize 1048576 and volume label "iscsi_datastore".
Successfully created new volume: 545f4a8d-ae6ff624-4e80-000c29e46a30
~ # 

The new datastore is ready to be used:

~ # df -h
Filesystem   Size   Used Available Use% Mounted on
VMFS-5      32.5G   1.1G     31.4G   3% /vmfs/volumes/datastore1
VMFS-5      49.8G 972.0M     48.8G   2% /vmfs/volumes/iscsi_datastore
vfat         4.0G   8.2M      4.0G   0% /vmfs/volumes/53cbd008-a135e53c-af91-000c298ee185
vfat       249.7M 157.8M     91.9M  63% /vmfs/volumes/3bbec171-e89b7d26-32f9-0706f6883562
vfat       249.7M   8.0K    249.7M   0% /vmfs/volumes/ba6ee87f-8cb18390-8ec4-220b0346c7a6
vfat       285.8M 192.6M     93.2M  67% /vmfs/volumes/53cbd001-e781921c-3fbf-000c298ee185
~ #