This post explains how to correlate SCSI devices within a Linux virtual machine to the virtual disk configured in the Virtual Machine. This can be accomplished by comparing the SCSI ID listed the Linux Guest OS and the virtual machine configuration in the vSphere client.
In the vSphere Client disks are numbered without any reference to their SCSI ID. Linux operating systems numbers disks based on their SCSI ID and in order of appearance. Usually, the first disk is /dev/sda, the second /dev/sdb and so on. But if you want to remove a disk for example you want to make sure to identify the disk correctly.
Determine Virtual Machine Disk SCSI ID
In the vSphere Client, the SCSI ID is displayed in the Virtual Machine configuration. The SCSI ID has two numbers (Controller:Device) and can be found in the Virtual Device Node section. In this example, the SCSI ID is 0:4 .
Virtual Device Node in the vSphere Webclient. In this example, the SCSI ID is 0:2 .
You can also use PowerCLI to get a list of devices with their SCSI ID:
$vm="vcsa6.virten.lab" $vmview = Get-View -ViewType VirtualMachine -Filter @{"Name" = $vm} foreach ($VirtualSCSIController in ($vmview.Config.Hardware.Device | where {$_.DeviceInfo.Label -match "SCSI Controller"})) { foreach ($VirtualDiskDevice in ($vmview.Config.Hardware.Device | where {$_.ControllerKey -eq $VirtualSCSIController.Key})) { Write-Host SCSI" ("$($VirtualSCSIController.BusNumber):$($VirtualDiskDevice.UnitNumber)")" $VirtualDiskDevice.DeviceInfo.Label } }
Determine SCSI ID from Device Names in Linux (/dev/sdX)
To determine the SCSI ID from device names enter ls -d /sys/block/sd*/device/scsi_device/*
linux:~ # ls -d /sys/block/sd*/device/scsi_device/* /sys/block/sda/device/scsi_device/0:0:0:0 /sys/block/sdb/device/scsi_device/0:0:1:0 /sys/block/sdc/device/scsi_device/0:0:2:0 /sys/block/sdd/device/scsi_device/0:0:3:0 /sys/block/sde/device/scsi_device/0:0:4:0 /sys/block/sdf/device/scsi_device/0:0:5:0 /sys/block/sdg/device/scsi_device/0:0:6:0 /sys/block/sdh/device/scsi_device/0:0:8:0 /sys/block/sdi/device/scsi_device/0:0:10:0 /sys/block/sdj/device/scsi_device/0:0:12:0 /sys/block/sdk/device/scsi_device/0:0:14:0 /sys/block/sdl/device/scsi_device/1:0:0:0 /sys/block/sdm/device/scsi_device/1:0:1:0 /sys/block/sdn/device/scsi_device/1:0:2:0
You can see the the device name, and 4 numbers a:b:c:d
- a = Hostadapter ID
- b = SCSI channel
- c = Device ID
- d = LUN
The Device ID is always c. At the controller, it depends whether you are using the Paravirtual (b) controller, or the LSI Logic (a) controller. From the PowerCLI example and the Linux output you can see that both disks are in the same order. /dev/sde has the SCSI ID 0:0:4:0 which is the equivalent to 0:4 and is Hard Disk 5. As mentioned, when you remove and add disks, the order might change so always doublecheck if you want to remove disks from a Virtual Machine.
Use the following command if you want an output that is better to read:
linux:~ # ls -d /sys/block/sd*/device/scsi_device/* |awk -F '[/]' '{print $4,"- SCSI",$7}' sda - SCSI 0:0:0:0 sdb - SCSI 0:0:1:0 sdc - SCSI 0:0:2:0 sdd - SCSI 0:0:3:0 sde - SCSI 0:0:4:0 sdf - SCSI 0:0:5:0 sdg - SCSI 0:0:6:0 sdh - SCSI 0:0:8:0 sdi - SCSI 0:0:10:0 sdj - SCSI 0:0:12:0 sdk - SCSI 0:0:14:0 sdl - SCSI 1:0:0:0 sdm - SCSI 1:0:1:0 sdn - SCSI 1:0:2:0
If you want to have the output in the Controller:Device format:
For LSI Logic Parallel:
localhost:~ # ls -d /sys/block/sd*/device/scsi_device/* |awk -F '[:/]' '{print $4,"- SCSI",$7":"$9}'
For Paravirtual:
localhost:~ # ls -d /sys/block/sd*/device/scsi_device/* |awk -F '[:/]' '{print $4,"- SCSI",$8":"$9}'
Hello,
you can also add "lsscsi" utility :-)
lsscsi
[1:0:0:0] cd/dvd NECVMWar VMware IDE CDR10 1.00 /dev/sr0
[2:0:0:0] disk VMware Virtual disk 1.0 /dev/sda
[2:0:1:0] disk VMware Virtual disk 1.0 /dev/sdb
[2:0:2:0] disk VMware Virtual disk 1.0 /dev/sdc
[2:0:3:0] disk VMware Virtual disk 1.0 /dev/sdd
[3:0:0:0] disk VMware Virtual disk 1.0 /dev/sde
[3:0:1:0] disk VMware Virtual disk 1.0 /dev/sdf
[3:0:2:0] disk VMware Virtual disk 1.0 /dev/sdg
your matching works only in ideal situation
when you remove disks & trigger udev (or reboot) something like this might happen
server:(/root/home/root)(root)#dmesg | grep scsi | grep mptsas
[ 3.953976] scsi target0:0:0: mptsas: ioc0: add device: fw_channel 0, fw_id 0, phy 0, sas_addr 0x5000c29c646bf443
[ 4.956257] scsi target0:0:1: mptsas: ioc0: add device: fw_channel 0, fw_id 2, phy 2, sas_addr 0x5000c29d5122a4b0
[ 5.958612] scsi target0:0:2: mptsas: ioc0: add device: fw_channel 0, fw_id 3, phy 3, sas_addr 0x5000c2914eee34df
server:(/root/home/root)(root)#lsscsi
[0:0:0:0] disk VMware Virtual disk 1.0 /dev/sda
[0:0:1:0] disk VMware Virtual disk 1.0 /dev/sdb
[0:0:2:0] disk VMware Virtual disk 1.0 /dev/sdc
[2:0:0:0] cd/dvd NECVMWar VMware IDE CDR10 1.00 /dev/sr0
as you can see there is difference between target mapping and mapping on esx
VMWare does not assign ID 0:7 to disks
This is not a problem when this is transferred 1:1 into your OS, which seems to be the case in this example.
My Oracle Linux instead uses it. This gives the result that the id's >= 7 are not idetical in Linux and VMWare.
...
SCSI 0:6 -> VMware 0:6
SCSI 0:7 -> VMware 0:8
...
This does NOT always work. and I recommend you check other things too (like disk size).
On our system VMware had two disks SCSI(2:x) and one SCSI(3:x)
But under linux it had one [2:0:x:0] disks
and two [3:0:x:0]
The disk sizes confirmed the MAJOR number was swapped (23) for some reason.
thank you!! great!!!!