VMware {code} Community
sike
Contributor
Contributor

How to get the mapping from VMDK file to the physical disk

Hi,

I'm new in this area. Maybe someone already posted the similar question. We want to get a mapping between the VMDK files and the physical disk.

I can open the vmx file and get the content. But it only gives me the logical location, such as /vmfs/volumes/storage1/TestVM1/TestVM1.vmdk. But how do I know which physical hard disk this vmdk file is located? For example, /dev/sda or /dev/sdb.

Thanks.

sike

Reply
0 Kudos
9 Replies
lamw
Community Manager
Community Manager

You can utilize this script to do a simple mapping:

Here is a more detail PowerCLI script that was recently released for mapping Window VMs: http://www.van-lieshout.com/2009/12/match-vm-and-windows-harddisks-using-powercli/

If you need to map to the exact disk, what you can look into is the driver order + disk information from within the guest if it has VMware Tools installed and you can do some correlation to figure out the mappings.

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

Twitter: @lamw

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Comuunity

If you find this information useful, please award points for "correct" or "helpful".

sike
Contributor
Contributor

Thanks, William.

Using WMI in the VM, I can get the mapping of VM hard disk drive and the vmdk file logical location. But I could not get the mapping of the vmdk file logical location and the physical disk (i.e. /dev/sda). Is there any method I can get this mapping?

Regards

Si Ke

Reply
0 Kudos
lamw
Community Manager
Community Manager

Once you have the VMDK mapped to the datastore, just head over to your vSphere Client and look under the host Configuration and under the "Storage" section you'll have the physical device mapping which is backing that specific datastore.

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

Twitter: @lamw

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Comuunity

If you find this information useful, please award points for "correct" or "helpful".

Reply
0 Kudos
sike
Contributor
Contributor

Thank you, William.

I can get this mapping using VMWare tools. But is there any API to get this mapping?

Regards

Si Ke

Reply
0 Kudos
lamw
Community Manager
Community Manager

Take a look at this script:

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

Twitter: @lamw

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Comuunity

If you find this information useful, please award points for "correct" or "helpful".

sike
Contributor
Contributor

Thank you, William.

I'd like to know if there is any simple api to get this mapping because our product will run on the pure esx server without any additional plugins.

Regards

Si Ke

Reply
0 Kudos
lamw
Community Manager
Community Manager

Not sure how much simpler you want to go? I wouldn't recommend running things in the Service Console if that's what you meant by running on 'pure' ESX host. I hope you know that the future direction of hypervisor will be going towards ESXi and hence all management capabilities will be via the API's.

The script I written above does all that you've asked and it's pretty darn simple to implement and use, especially if you just down the vMA appliance.

If you want to get this same mapping using the Service Console, yes you can of course figure that out but there's no API. It'll be simple shell or python script to go through all VMs, find the VMDKs and map it back the datastore and physical device and you would need to run this script on each host via SSH login.

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

Twitter: @lamw

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Comuunity

If you find this information useful, please award points for "correct" or "helpful".

Reply
0 Kudos
CMJ88
Contributor
Contributor

William,

I ran your script on one of my 2008 R2 64bit servers.  Unfortunetly the script is failing to match the Windows disks.

The Line below is where you are matching the Windows drive to the VMDK.  You are subtracting 1 from the .SCSIPort.  Why are you subtracting 1?  On my server the .SCSIPort is 2 higher than the .BusNumber.  Should this be constant?

$DiskMatch = $WinDisks | ?{($_.SCSIPort 1) -eq $VirtualSCSIController.BusNumber -and $_.SCSITargetID -eq $VirtualDiskDevice.UnitNumber}

Thanks,

Casey

Reply
0 Kudos
Fresned
Contributor
Contributor


CMJ88,

  I found this information from here:  Generic SCSI on a Windows Host Operating System

Note: The SCSI bus is assigned a number by the host operating system after all IDE buses have been assigned numbers. For example, if you have 2 IDE buses, they are numbered 0 and 1. The first SCSI bus is assigned bus number 2. In the example above, you use 2 for X

Windows assigns SCSI bus numbers after the IDE numbers. He most likely subtracted one from the SCSI port because he had one IDE controller on his system.  In your case you probably have two IDE controllers so that is why your SCSI port is consistently higher by two than your bus number.

You could use this to enumerate your IDE controllers:

$IDE = $VMView.Config.Hardware.Device | where {$_.DeviceInfo.Label -match "IDE "}

Then change this line to the following to subtract them from the SCSI port you retrieved from Windows so that it correctly matches the SCSI bus number from VMWare:

$DiskMatch = $WinDisks | ?{($_.SCSIPort - $IDE.Count) -eq $VirtualSCSIController.BusNumber  -and $_.SCSITargetID -eq $VirtualDiskDevice.UnitNumber} 
Reply
0 Kudos