A default virtual machine has straightforward hardware. A single SCSI disk on a single SCSI card, for example. Having multiple SCSI disks or cards in a VM creates the need for in-guest identification. Linux complicates matters slightly by using alphabetical disk naming: /dev/sda, /dev/sdb, ... /dev/sdz, /dev/sdaa, /dev/sdab, ... This post looks at how you can identify individual disks in a VMware virtual machine.
Executive summary: VMware notation "X:Y" typically maps onto Linux scsi(X+2), Id:Y, which are then named in ascending order with /dev/sd* identifiers.
First step is to identify the SCSI cards:
The first two "scsi host" entries you'll see are the virtual IDE controllers, which Linux drives using its SCSI layer too. VMware uses these for one CD-ROM device (max four). The third "scsi host" called "host2" is the first virtual SCSI card. In the VM definition (the VMX file) you'd see this:
[root@testhost ~]# cd /sys/class/scsi_host
[root@testhost scsi_host]# ls -l
total 0
lrwxrwxrwx. 1 root root 0 May 22 2013 host0 -> ../../devices/pci0000:00/0000:00:07.1/host0/scsi_host/host0
lrwxrwxrwx. 1 root root 0 May 22 2013 host1 -> ../../devices/pci0000:00/0000:00:07.1/host1/scsi_host/host1
lrwxrwxrwx. 1 root root 0 May 22 2013 host2 -> ../../devices/pci0000:00/0000:00:10.0/host2/scsi_host/host2
Every device in /proc/scsi/scsi will be identified with the host that it's connected to. That, and the "Id" number,
[root@testhost scsi_host]# cat /proc/scsi/scsi
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
What VMware calls "0:0" is the disk on the first SCSI card (scsi2 in Linux), and "Id: 00". The default second disk would be virtually shown on "0:1", being scsi2 "Id: 01".
So in general, "SCSI disk X:Y" in VMware means scsi(X+2) ID: Y in Linux.
Linux names its disk devices at discovery time, during the boot cycle. So first the disks on scsi2 would be scanned, then scsi3, scsi4 and scsi5. On each scsi_host the disks will be added in ascending order, Id:00 first, up to 06, then 08 up to 15.
The only situation this could be different, is if you hot-add virtual disks or virtual SCSI cards without rebooting Linux. Both of these actions are supported in VMware, and by the Linux kernel. Those new cards and disks would be added to the list after the pre-existing ones, and no live device renaming/reordering happens for obvious reasons.
In a multiple SCSI card configuration you might notice that, while scsi2 (first virtual SCSI card) shows up on PCI bus 10, scsi3-5 show up behind a PCI bridge on PCI bus 11, together with the virtual network device(s).
On vSphere 5.5 and higher, both CD-ROM and disk devices can be shown on virtual SATA controllers, driven in Linux by the ahci driver. Each VMware virtual SATA controller (PCI ID 15ad:07e0 behind a PCI bridge on bus 11) will show up as 30 (!) scsi_host entries, and each can connect to one disk. The virtual disk number VMware shows, will be translated in the corresponding scsi_host number as reported by Linux. Device enumeration will still happen in ascending order over the scsi_hosts as before.
Executive summary: VMware notation "X:Y" typically maps onto Linux scsi(X+2), Id:Y, which are then named in ascending order with /dev/sd* identifiers.
First step is to identify the SCSI cards:
The first two "scsi host" entries you'll see are the virtual IDE controllers, which Linux drives using its SCSI layer too. VMware uses these for one CD-ROM device (max four). The third "scsi host" called "host2" is the first virtual SCSI card. In the VM definition (the VMX file) you'd see this:
[root@testhost ~]# cd /sys/class/scsi_host
[root@testhost scsi_host]# ls -l
total 0
lrwxrwxrwx. 1 root root 0 May 22 2013 host0 -> ../../devices/pci0000:00/0000:00:07.1/host0/scsi_host/host0
lrwxrwxrwx. 1 root root 0 May 22 2013 host1 -> ../../devices/pci0000:00/0000:00:07.1/host1/scsi_host/host1
lrwxrwxrwx. 1 root root 0 May 22 2013 host2 -> ../../devices/pci0000:00/0000:00:10.0/host2/scsi_host/host2
Every device in /proc/scsi/scsi will be identified with the host that it's connected to. That, and the "Id" number,
[root@testhost scsi_host]# cat /proc/scsi/scsi
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
What VMware calls "0:0" is the disk on the first SCSI card (scsi2 in Linux), and "Id: 00". The default second disk would be virtually shown on "0:1", being scsi2 "Id: 01".
So in general, "SCSI disk X:Y" in VMware means scsi(X+2) ID: Y in Linux.
Linux names its disk devices at discovery time, during the boot cycle. So first the disks on scsi2 would be scanned, then scsi3, scsi4 and scsi5. On each scsi_host the disks will be added in ascending order, Id:00 first, up to 06, then 08 up to 15.
The only situation this could be different, is if you hot-add virtual disks or virtual SCSI cards without rebooting Linux. Both of these actions are supported in VMware, and by the Linux kernel. Those new cards and disks would be added to the list after the pre-existing ones, and no live device renaming/reordering happens for obvious reasons.
In a multiple SCSI card configuration you might notice that, while scsi2 (first virtual SCSI card) shows up on PCI bus 10, scsi3-5 show up behind a PCI bridge on PCI bus 11, together with the virtual network device(s).
On vSphere 5.5 and higher, both CD-ROM and disk devices can be shown on virtual SATA controllers, driven in Linux by the ahci driver. Each VMware virtual SATA controller (PCI ID 15ad:07e0 behind a PCI bridge on bus 11) will show up as 30 (!) scsi_host entries, and each can connect to one disk. The virtual disk number VMware shows, will be translated in the corresponding scsi_host number as reported by Linux. Device enumeration will still happen in ascending order over the scsi_hosts as before.
Comments
The more reliable way to actually map this through is to pull the VM extended configuration data using powershell
$vm=vm-get "guest"
$vm.ExtensionData.Config.ExtraConfig | where {$_.Key -like "*pciSlotNumber")
Then follow the process described in this kb article
Howto Map PCI devices to guests
Once you have the bridge slot number convert it to hex and it's trivially mapped to the pci bridge in the /sys/pci path or lsscsi --verbose output.
for DISK in $(ls /dev/sd*|grep -v [0-9]); do echo -n "$DISK "; udevadm info -n $DISK -a|grep label|cut -nc 20-24|tr "\n" ":"; udevadm info -n $DISK -a|grep 'KERNELS=="target'|cut -c 25; done
which works because the SCSI adapter is communicated to the guest in an attribute that's available to udev.