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

= Hostadapter ID b = SCSI channel

= SCSI channel c = Device ID

= 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}'