How to map vmdk files to Disk number or device name inside guest OS

Firstly, I would like to Thank my colleague Akshay Kalia (https://in.linkedin.com/in/kaliaakshay) for sharing this information with us .

In most cases you can obtain this mapping by following a few simple steps

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 V

#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 with generate an out similar to

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 put the highlighted number is the address of the controller where the /dev/sda is attached. Further the highlighted number 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 target1 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 target1 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

disk

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 target0 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 target0 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 following 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/UUID/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/UUID/vmname_2.vmdk” exits in a separate data store

Use the information obtained in step one and two map vmdk to an in gues disk number. In this case disk 0 for windows VMs is vmname.vmdk

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

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

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

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

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s