VMware Cloud Community
fsckit
Enthusiast
Enthusiast

cli to create new virtual disks

I can use 'vmkfstools --createvirtualdisk <size>G --diskformat thin <location>' to create a new virtual disk (*.vmdk) file, but how do I get the VM to recognize this new disk in its configuration? 

I need to do this through the cli. I can do it in vSphere Client in Edit Settings, Add, Hard Disk, "Use an existing virtual disk". 

Anyone successfully do this using esxcli or other CLI commands, or in the Perl SDK? 

 Thanks.

5 Replies
npadmani
Virtuoso
Virtuoso

VMware KB: Hot adding a virtual disk to a virtual machine from command line interface

Here's the KB with information that you need.

Narendra Padmani VCIX6-DCV | VCIX7-CMA | VCI | TOGAF 9 Certified
fsckit
Enthusiast
Enthusiast

Thank you. Yes, I saw that KB and I was able to get "vim-cmd vmsvc/device.diskaddexisting" to work. However, if possible I'd rather do this with remote CLI commands. If I can avoid it, I don't want to have to activate ssh on the ESXi host and log in to run vim-cmd commands.

I'm running vmkfstools from a vMA.  Know of any remote CLI command that hot-adds virtual disks?

0 Kudos
npadmani
Virtuoso
Virtuoso

I think you have only PowerCLI left with you to do this.

New-HardDisk - vSphere PowerCLI Cmdlets Reference

Narendra Padmani VCIX6-DCV | VCIX7-CMA | VCI | TOGAF 9 Certified
0 Kudos
fsckit
Enthusiast
Enthusiast

Actually the vSphere SDK for Perl should be able to do this. In fact, one of the included William Lam scripts, vmdkManagement.pl, does exactly this.

vmdkManagement.pl --server <vCenter> --username <me> --operation add --vmdkname <filename.vmdk> --vmname <VM> --datastore <datastore>

Problem is, it always adds the disk to controller 0. When I edit the Perl script to use controller 1 (or any other controller), it fails.

0 Kudos
HDBR
Contributor
Contributor

Okay, I guess the heat has pretty much gone out of this one but I did get the VI web client to successfully "see" a disk created with vmkfstools.  It appears while that utility certainly creates the disk, it doesn't actually assign it to a VM (even though it seems to be embedded in the disk path spec):  until that happens, neither the VI client nor the earmarked VM can see it.  The trick was to use DCLI:

dcli com vmware vcenter vm hardware disk create --vm vm-idx --backing-type VMDK_FILE --backing-vmdk-file "[datastore] path/name.vmdk"

where idx is the "index" assigned to the VM, this can be obtained with another DCLI command:

dcli com vmware vcenter vm list

and the vmdk file path is the one previously created by vmkfstools.  When run successfully, this returns the disks integer ID and you should see it now reported against the VM's hardware with the Hard disk n label and the (I'm assuming Linux) VM will see it through the device file path /dev/sdx.

At least, that's how it's worked for me (vSphere/vCLI 6.5.0).

0 Kudos