Mapping block devices to CCW devices

Red Hat Enterprise Linux 9.2 KVM guest

Each virtual block device corresponds to an online CCW device.

Other than the standard device nodes, udev-created device nodes can be based on the bus ID of the CCW device and so provide a persistent mapping of node to CCW device. Preferably, use such persistent device nodes when working with virtual block devices.

Use the information that follows if you need to find out the current mapping between standard device nodes and CCW devices. For example, you might need this mapping for diagnostic explorations.

To list the device nodes for your block devices, issue:
# ls /sys/block
The command output is a list of symbolic links that match the device names of the block devices.
Example:
# ls /sys/block
vda     vdb     vdc

These links contain several attributes, including another symbolic link, device. To find the bus ID for a particular block device, issue a command according to the following example:

Example:
# ls -1 /sys/block/vdb/device/../.. | head -1
0.0.1111
Tip: For an overview of the mapping, issue this command:
# ls -d /sys/devices/css0/*/*/virtio*/block/*
Example:
# ls -d /sys/devices/css0/*/*/virtio*/block/*
/sys/devices/css0/0.0.0000/0.0.10b1/virtio3/block/vda
/sys/devices/css0/0.0.0001/0.0.1111/virtio4/block/vdb
/sys/devices/css0/0.0.0002/0.0.11ab/virtio5/block/vdc
You can pipe the output to awk to obtain a more compact view:
# ls -d /sys/devices/css0/*/*/virtio*/block/* | awk -F "/" '{print $9 "\t" $6}'
vda     0.0.10b1
vdb     0.0.1111
vdc     0.0.11ab