Getting SCSI controller information with ESXCLI for VMware disks

VMware provides various tools to manage virtual machines. Some are GUI based such as vSphere client, vSphere web client; some are command line based such as vSphere CLI (ESXCLI), PowerCLI. Most of tasks can be easily done via GUI, but sometimes if you need some information to be kept, comand line could be a better choice to export those information.

Recently I needed to deattach a series of disks from one VM and attach them another new VM as one of steps for a forklift upgrade. The new VM has a newer OS version. Those disks are used as Oracle database storage (data files and backup etc.). To do so, we avoid the need of extra storage to copy database files.

One trick thing here when deattach/reattach disks, you need to make sure the SCSI controller information for disks are kept the same. Otherwise the new OS will not recognize the partion table and filesystem if SCSI controller ID and traget number for a disk is different from the old VM to the new VM.

For example, if a disk has SCSI(1:0) on the old VM, but you assign SCSI(0:4) to it on the new VM, then the new VM won’t recognize the existing disk layout at the OS level. It means your data is somehow lost. Apparently that’s not what you want. The only reason to move a vmdk around is to reuse the contents on it.

Of course you can get disk information (name, SCSI controller etc) from GUI and repeat the same step for all disks. But the easy way is to use a command line to dump the information and save it in a file.

Here is an example to use ESXCLI. First SSH to the ESXi host and find vmid of the old VM:

vim-cmd vmsvc/getallvms

If you know the name of the VM (“Test VM OL6 old pri” is my VM name), you can grep it from the output:

~ # vim-cmd vmsvc/getallvms|grep OL6
 35     Test VM OL6 old pri               [VM_Datastore_1] Test VM OL6 old pri/Test VM OL6 old pri.vmx                           oracleLinux64Guest      vmx-10    OracleLinux R6U10 with VMware tools version 10.3.20    

So the first column of the output is the vmid. In my case it is 35. Next find all device information for this VM:

~ # vim-cmd vmsvc/device.getdevices 35

From the output, you will see something similar to the below:

  (vim.vm.device.ParaVirtualSCSIController) {
     dynamicType = <unset>,
     key = 1000,
     deviceInfo = (vim.Description) {
        dynamicType = <unset>,
        label = "SCSI controller 0",
        summary = "VMware paravirtual SCSI",

That is the controller level information. The information for disks of this controller will follow. And in the section of VirtualDisk, you will see something like below:

  (vim.vm.device.VirtualDisk) {
     dynamicType = <unset>,
     key = 2000,
     deviceInfo = (vim.Description) {
        dynamicType = <unset>,
        label = "Hard disk 1",
        summary = "61,865,984 KB",
        fileName = "[VM_Datastore_1] Test VM OL6 old pri/Test VM OL6 old pri.vmdk",
         controllerKey = 1000,
         unitNumber = 0,
         capacityInKB = 61865984,
         capacityInBytes = 63350767616,

It means this “Hard disk 1” is attached to the SCSI controller 0 — controllerKey = 1000 which matches the key value of the controller. unitNumber = 0 means the target number is 0. So basically this disk is attached to a ParaVirtual SCSI Controller (0:0). Also from the key word “fileName”, you get the full path of the disk.

As you can see, with two simple commands, you get all information you need. Save a lot of clicks!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s