VMware Cloud Community
Skyislimit
Contributor
Contributor

How to do mapping between disks(OS level) and vmdks?

HI All,

I have thre disks(vmdks) having scsi no as:

scsi3:4

scsi1:0

scsi2:12

In the vmx file they are listed in the above manner.But when I am seeing this in Diskmgmt.msc(Windows OS),I am observing that the disk order is in follwing order:

scsi1:0

scsi2:12

scsi3:4

(in the increasing order of scsi controller number and unit numbers).

Why is it so? Is there any way through which I can detect which disk(on Vm level) macth with which vmdk?

I shall be highly thankful for any help.

Regards,

victor

Reply
0 Kudos
5 Replies
DougBaer
Commander
Commander

This has more to do with how your OS is enumerating the SCSI chain than the order of the disk files within your configuration file.

From within the guest OS, it knows nothing more about how the VMX file is constructed than a physical machine knows about the order in which you have your physical SCSI devices cabled.

However, by leveraging the vSphere PowerCLI, you can map this out (even from the guest if it has PowerShell and the PowerCLI installed) and possibly get what you need. The script below will list the scsi mapping for ALL VMs, but you can pass a VM name after "Get-VM" to narrow it down to one.

$MyVCserver   = 'YOURVC.domain.local'
$MyVCusername = 'user'
$MyVCpassword = 'password'

Connect-VIServer -Server $MyVCserver -User $MyVCusername -Password $MyVCpassword

$VMs = Get-VM | Get-View

ForEach ($VM in $VMs) {
	If($VM) {
		Foreach ($SCSI_Controller in ($VM.Config.Hardware.Device | where {$_.DeviceInfo.Label -like "SCSI*" } )) {
			Write-Host $SCSI_Controller.DeviceInfo.Label
			Foreach ($Disk_Key in $SCSI_Controller.Device) {
				Foreach ($Disk_Device in ($VM.Config.Hardware.Device | where {$_.key -eq $Disk_Key } )) {
					Write-Host "  "  $Disk_Device.UnitNumber : $Disk_Device.DeviceInfo.Label : $Disk_Device.Backing.Filename
				}
			}
		}
	}
}

Disconnect-VIServer -Confirm:$false

The output for a single VM will look something like this:

SCSI Controller 0
   0 : Hard Disk 1 : [LAB_ESX_Celerra] UDA/UDA-000001.vmdk
   1 : Hard Disk 2 : [LAB_ESX_Celerra] UDA/UDA_1-000001.vmdk
   2 : Hard Disk 4 : [LAB_ESX_Celerra] UDA/UDA_3.vmdk
SCSI Controller 1
   6 : Hard Disk 3 : [LAB_ESX_Celerra] UDA/UDA_2.vmdk

For a machine containing 2 SCSI controllers -- the first having SCSI IDs 0:0,0:1, and 0:2, representing hard disks 1,2 and 4 (added in the order of the numbers: 1st, 2nd, 4th).

The second SCSI controller has Hard Disk 3 (the disk added to the VM 3rd) with SCSI ID 1:6.

Based on the understanding that Windows will enumerate in the order of SCSI controller ID followed by SCSI ID per controller, does this help?

Doug Baer, Solution Architect, Advanced Services, Broadcom | VCDX #019, vExpert 2012-23
Reply
0 Kudos
Skyislimit
Contributor
Contributor

Thanks for reply.

This script is enumerating hards disk number at the VM level,but inside OS(I m using windows 2k3) ,the ordering is not same.

Please find the following scenarios:

Scsi no

-


>HardDisk number at VM level -


> Disk number(as reported by windows OS)

scsi0:0 -


hard disk 1----


> disk 0 (this is fine as windows enumertes disk from number 0

scsi 1:0----


hardisk 2 -


disk 2 (matching wrong at Os level)

scsi0:1 -


hard disk 3----


disk 1 ( matching wrong)

I want to find (from with in OS) the corresponding mapping of disks (os level) and vmdks. Please tell is there any way to achieve this. Please point me to correct forum if I am posting in wrong forum

Reply
0 Kudos
DougBaer
Commander
Commander

I am not certain there is a way to do what you are asking because Windows is performing its disk enumeration based on its internal rules and the 'hardware' addressing of the scsi disks. In cases like this, many people use the size of the disks to determine which is which.

In the event that there are several disks of the same size presented to a given guest, I normally use the SCSI ID to determine which VMDK corresponds to which OS disk. The only scenarios in which I see VMs with large numbers of same-sized disks are database or mail servers, so the percentage of guests this affects is relatively small in my experiences.

You can use WMI to list the disks from the OS perspective and map them up with the results of the previous script. Is that kind of what you're looking for? It shouldn't be too much of a problem to combine the two chunks of code. If I understand correctly, you want to run this from within the VM so that it can understand which VMDK is backing its various drives. Correct?

[vSphere PowerCLI] C:\> gwmi Win32_DiskDrive | select DeviceID,SCSIBus,SCSITargetID,SCSIPort,SCSILogicalUnit | format-table -autosize

DeviceID           SCSIBus SCSITargetID SCSIPort SCSILogicalUnit
--------           ------- ------------ -------- ---------------
\\.\PHYSICALDRIVE0       0            0        1               0
\\.\PHYSICALDRIVE1       0            5        1               0
\\.\PHYSICALDRIVE2       0            6        1               0
\\.\PHYSICALDRIVE3       0            3        2               0

Doug Baer, Solution Architect, Advanced Services, Broadcom | VCDX #019, vExpert 2012-23
Reply
0 Kudos
Skyislimit
Contributor
Contributor

Thanks, for your kind help.

I am able to get mapping through the script.

Once again,

Thank you very much.

Victor

Reply
0 Kudos
DougBaer
Commander
Commander

I played with this a little more. It sounds like you may have already finished this, but here is what I came up with:

$MyVCserver   = 'lab-vc01.lab.local'
$MyVCusername = 'Doug'
$MyVCpassword = 'password'
$MyWinAdminName = 'Administrator'
$MyWinPassword = 'password'
$MyVMname = 'SCSI-TEST'

######
$c = Get-Credential $MyWinAdminName
######

$VC = Connect-VIServer -Server $MyVCserver -User $MyVCusername -Password $MyVCpassword
$VMs = Get-VM $MyVMname | Get-View

$myData = @()
ForEach ($VM in $VMs) {
  If($VM) {  
  
    Foreach ($SCSI_Controller in ($VM.Config.Hardware.Device | where {$_.DeviceInfo.Label -like "SCSI*" } )) {
      Foreach ($Disk_Key in $SCSI_Controller.Device) {
        Foreach ($Disk_Device in ($VM.Config.Hardware.Device | where {$_.key -eq $Disk_Key } )) {
          $myObj = "" | Select-Object Controller, CtrlBusNum, Unit, Label, BackingFile
          $myObj.Controller = $SCSI_Controller.DeviceInfo.Label
          $myObj.CtrlBusNum = $SCSI_Controller.BusNumber
          $myObj.Unit = $Disk_Device.UnitNumber
          $myObj.Label = $Disk_Device.DeviceInfo.Label
          $myObj.BackingFile = $Disk_Device.Backing.Filename
        }
        $myData += $myObj
      }
    }
    $myGuestData = @()
    # Use WMI to get disk information
    $myGuestData = gwmi Win32_DiskDrive -computername $MyVMname -Credential $c | `
      Select DeviceID,SCSIBus,SCSITargetID,SCSIPort,SCSILogicalUnit
    $myGuestdata | Format-table -autosize

  }
}
Disconnect-VIServer $VC -Confirm:$false

foreach ($VMDK in $myData) {
  foreach ($GuestDisk in $myGuestData) {
    if ((($GuestDisk.scsiport-1) -eq $VMDK.CtrlBusNum) -and ($VMDK.unit -eq $GuestDisk.SCSITargetID)) {
      Write-Host $GuestDisk.DeviceID, $VMDK.Label, $VMDK.BackingFile
    }
  }  
}

Doug Baer, Solution Architect, Advanced Services, Broadcom | VCDX #019, vExpert 2012-23
Reply
0 Kudos