How to map vmdk files to Disk Number or the device name inside the guest OS.

Posted by

Step1:

Find out the PCI slot ID of the SCSI controller on the VM and make a note of them. You will need them in Step2
PCI slot ID of the SCSI controller on the VM can be obtained by running a simple command on the vmx for the VM

cat /vmfs/volumes/<data store name>/vmname/vmname.vmx | grep scsi | grep pci

The above command will generate an output similar to.

scsi0.pciSlotNumber = “160”
scsi1.pciSlotNumber = “192”

Step2:

Find disk information within the guest OS. The steps to obtain this information depends upon the guest OS in use.

Linux:

On a Linux machine run following command for the device you want to map.

udevadm info --query=all -n /dev/<device name> | grep DEVPATH

Let’s say we want to map /dev/sda the final command would be look like

udevadm info --query=all -n /dev/ sda | grep DEVPATH

The above command will generate an output similar to

DEVPATH=/devices/pci0000:00/0000:00:15.0/0000:03:00.0/host2/target2:0:1/2:0:1:0/block/sdb

DEVPATH=/devices/pci0000:00/0000:00:15.0/0000:03:00.0/host2/target2:0:1/2:0:1:0/block/sdb

In the above output the first highlighted number is the address of the controller where the /dev/sda is attached and the second  highlighted number is target ID.  Hence, /dev/sda is target 1 on the Scsi controller present at address 0000:03:00.0

Now to find a relation between address of the controller and the PCI slot number run following command on the Linux machine. Run the below command for each PCI slot ID obtained in Step1.

cat /sys/bus/pci/slots/160/address

The output of the above command will be the address of the controller and will look like

0000:03:00

What we know so far:

  • /dev/ sda is target 1 on the Scsi controller present at address 0000:03:00.0
  • Scsi controller present at address 0000:03:00.0 is scsi0

From the above information we can conclude that /dev/sda is target 1 on scsi0 which is nothing but scsi0:1

Windows:

On a Windows machine open “Disk Management” this can done by following

Start > run > diskmgmt.msc

Right click on the disk number and select properties. Let say we do this for Disk 0, it will open a page similar to

diskmgmt

On the above page “Location:” provide you following information
PCI Slot ID: 160 (Location 160)
Target ID: 0 (Target Id 0)
Partition: 0 (LUN 0)

What we know so far:
  • Disk 0 is target 0 on the Scsi controller present at PCI Slot ID 160
  • PCI Slot ID 160 is scsi0

From the above information we can conclude that Disk 0 is target 0 on scsi0 which is nothing but scsi0:0

Note: For windows system in some corner cases location information can be off. Please Verify the disk size as well.

Step3:

Find out the vmdk files and Naa ID of the data store. Once you have found the Scsi ID of the guest OS disk, we can follow the steps below to obtain the vmdk files and Naa ID information
To find vmdk files associated with the VM run following command

cat /vmfs/volumes/<data store name>/vmname/vmname.vmx | grep –i vmdk

The above command will generate an output similar to.

scsi0:0.fileName = "vmname.vmdk"
scsi0:1.fileName = "vmname_1.vmdk"
scsi0:2.fileName = "/vmfs/volumes/4ce381e2-8a5b2a05-b0a7-18a90571b0ec/vmname_2.vmdk"

From the above output we see that the VM has disks located on two data stores scsi0:0.fileName = “vmname.vmdk” and scsi0:1.fileName = “vmname_1.vmdk” exits in VMs home directory. scsi0:2.fileName = “/vmfs/volumes/4ce381e2-8a5b2a05-b0a7-18a90571b0ec/vmname_2.vmdk” exits in a separate datastore.
Use the information obtained in Step1 and Step1 to  map vmdk to an in guest disk number.

In this case disk 0 for windows VMs is vmname.vmdk

To find Naa Id of the data store associated with vmdk run following commands

esxcfg-scsidevs –m | grep <data store name>

For example, To find Naa Id of the data store associated with vmname_2.vmdk run following commands

esxcfg-scsidevs –m | grep 4ce381e2-8a5b2a05-b0a7-18a90571b0ec

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.