ESXi: Expand datastore from command line

Hi,

sometimes the vSphere Client does not determine when an underlying Volume is expanded. So you cannot expand the datastore by the WebGUI or vSphere Client.

But the command line way is still possible 🙂 These are the steps:


In this example the underlying volume/LUN of datastore_0 was already expand from 6TB to 10TB at the storage system. So I also want to grow up the vmfs on datastore_0 to 10TB.
Login to an ESXi Host by ssh.

Rescan all storage adapter for changes

[root@esxihost:~] esxcli storage core adapter rescan --all

Determine the disk path

[root@esxihost:~] vmkfstools -P /vmfs/volumes/datastore_0
VMFS-5.61 file system spanning 1 partitions.
File system label (if any): datastore_0
Mode: public
Capacity 6596801331200 (6291200 file blocks * 1048576), 217090883584 (207034 blocks) avail, max supported file size 69201586814976
UUID: 5ad58cdb-c8604cf3-e8fc-a0369f990590
Partitions spanned (on "lvm"):
naa.523545670e392ba2e81404da45912d543:1
Is Native Snapshot Capable: YES

Depending on the output of vmkfstools the Diskpath is /vmfs/devices/disks/naa.523545670e392ba2e81404da45912d543, :1 means datastore_0 is the first partition on the disk.

Get the Disk layout

[root@esxihost:~] partedUtil get /vmfs/devices/disks/naa.523545670e392ba2e81404da45912d543
1336746 255 63 21474836480
1 2048 12884901854 0 0

Start Sector of the first partition is 2048, current end sector is 12884901854 .

Determine the last usable end sector. If an error occured like this:

[root@esxihost:~] partedUtil getUsableSectors /vmfs/devices/disks/naa.523545670e392ba2e81404da45912d543
Error: The backup GPT table is not at the end of the disk, as it should be.  This might mean that another operating system believes the disk is smaller.  Fix, by moving the backup to the end (and removing the old backup)? This will also fix the last usable sector as per the new size.

then you have to correct the GPT partition table first:

[root@esxihost:~] partedUtil fixGpt /vmfs/devices/disks/naa.523545670e392ba2e81404da45912d543

FixGpt tries to fix any problems detected in GPT table.
Please ensure that you don't run this on any RDM (Raw Device Mapping) disk.
Are you sure you want to continue (Y/N): y
gpt
1336746 255 63 21474836480
1 2048 12884901854 AA31E02A400F11DB9590000C2911D1B8 vmfs 0

And again. Determine the last usable sector

 
[root@esxihost:~] partedUtil getUsableSectors /vmfs/devices/disks/naa.523545670e392ba2e81404da45912d543
34 21474836446

Last usable sector is 21474836446.

Expand the first partition. 2048 is the start sector and 21474836446 the new end sector.

[root@esxihost:~] partedUtil resize /vmfs/devices/disks/naa.523545670e392ba2e81404da45912d5431 1 2048 21474836446

and also grow the filesystem

[root@esxihost:~] vmkfstools --growfs /vmfs/devices/disks/naa.523545670e392ba2e81404da45912d543:1 /vmfs/devices/disks/naa.523545670e392ba2e81404da45912d543:1

rescan all volumes

[root@esxihost:~] vmkfstools -V

That’s it 🙂

Michael

13 thoughts on “ESXi: Expand datastore from command line”

  1. Thank you so much!

    The VMWare KB didn’t explain what to do if one runs into the GPT issue. Your blog helped me take care of this. Kudos to you, sir!

  2. This was perfect. The Web UI was unable to scan the devices and populate it while I tried to “Increase Capacity” of the datastore. I also ran into the GPT issue. Thanks a lot! I was worried we had wasted a bunch of money in getting a new SSD.

Leave a Reply