PowerCLI

 View Only
  • 1.  How to reliably match guest disks to virtual disks under Linux?

    Posted Jan 06, 2011 11:21 AM

    Greetings,

    I need to match up Linux (RHEL 5) guest disks to the virtual disks at the hardware device level (outside the guest). In Windows, the SCSI port/host number and target ID are easy to get at using WMI and they consistently match up with the virtual hardware SCSI addresses. In Linux, it seems like there are problems either with the virtual SCSI controller drivers or the kernel itself that cause the SCSI port/host number and target ID be off. Has anyone found a way around this?

    To elaborate a bit, if you do an "ls /dev/disk/by-path" you'll see some symlink files like this:

    pci-0000:00:07.1-scsi-1:0:0:0

    And if you do a "ls /sys/bus/scsi/devices/" you'll get more related details, such as this:

    1:0:0:0

    2:0:0:0

    2:0:1:0

    host0

    host1

    host2

    target1:0:0

    target2:0:0

    target2:0:1

    The most readable output comes from "cat /proc/scsi/scsi", which looks like this:

    Attached devices:
    Host: scsi1 Channel: 00 Id: 00 Lun: 00
      Vendor: NECVMWar Model: VMware IDE CDR10 Rev: 1.00
      Type:   CD-ROM                           ANSI  SCSI revision: 05
    Host: scsi2 Channel: 00 Id: 00 Lun: 00
      Vendor: VMware   Model: Virtual disk     Rev: 1.0
      Type:   Direct-Access                    ANSI  SCSI revision: 02
    Host: scsi2 Channel: 00 Id: 01 Lun: 00
      Vendor: VMware   Model: Virtual disk     Rev: 1.0
      Type:   Direct-Access                    ANSI  SCSI revision: 02

    The problem is, none of this info consistently matches up with the two-part SCSI address (eg 1:5) notation vCenter/ESX use to identify virtual disks in the VM hardware device list. To illustrate this, I added a few disks to a 3 different controllers. I figured out the mapping using unique disk sizes (which may not be unique in production).

    VM Device InfoLinux SCSI Info
    lsi sas 0:00:0:0:0
    lsi sas 0:50:0:1:0
    lsi sas 0:80:0:2:0
    paravirtual 1:32:0:3:0
    paravirtual 1:72:0:7:0
    lsi scsi 2:41:0:4:0
    lsi scsi 2:91:0:9:0

    Since the Linux SCSI address is made up of "Host:Channel:TargetId:LUN", I assume the VM device info is made up of "Host:TargetId". As you can see, the only row where the mapping is valid is the very first LSI SAS disk. I gave other LSI SAS disks non-sequential TargetId's, but somehow they got lost in Linux (perhaps due to the driver, or something specific to SAS). The TargetId's for the Paravirtual SCSI and LSI SCSI controllers actually do match up, but the Host (Port) numbers are swapped.

    Any help would be appreciated.

    Oh, and http://communities.vmware.com/thread/293192 is a similar question but the answers are not helpful. Using the SCSI ID is the right approach. It's not unreasonable to expect things to match up inside and outside the OS. MAC addresses, for example, are always consistent.

    Thanks,

    - Chris



  • 2.  RE: How to reliably match guest disks to virtual disks under Linux?

    Posted May 22, 2012 12:34 AM

    I was looking for the same thing, and then found your attempts produced the symlink results.

    If you expand the ls results, you'll find the answer's in the symlink:

    ls -alrt /dev/disk/by-path/

    The SCSI ID is after the last colon.

    Thanks for your posting and hope this helps!

    -Khai



  • 3.  RE: How to reliably match guest disks to virtual disks under Linux?

    Posted Feb 18, 2013 06:47 PM

    This one is gorgeous. Thank you so much. Works like a charm.



  • 4.  RE: How to reliably match guest disks to virtual disks under Linux?

    Posted Aug 05, 2015 07:52 PM

    Did you tried dmesg's sg option to match the hard disk number ? Please go through the below link

    How to Map the VMware virtual Disks for Linux VM ? - UnixArena