Do virtio disks support persistent names and Serial numbers?
Environment
- Red Hat Enterprise Linux 6
- Red Hat Enterprise Linux 7
- Red Hat Enterprise Linux 8
- Red Hat Enterprise Linux 9
virtiodevices
Issue
- How can persistent names be set up for
virtiodisks in a RHEL guest? - Are persistent names supported for
virtiodisks? - How can I define a serial number or WWN to a
virtiodisk?
Resolution
In order to be able to create udev rules for persistent and consistent naming of virtio disks, you will need a piece of unique characteristic of the disk. Usually, WWN or serial numbers are used as the binding point.
Please check the 'Root Cause' section for more information on WWN and Serial numbers support in virtio devices.
It is possible to define to manually define a ID_SERIAL for a virtio-block and both ID_SERIAL and ID_WWN for a virtio-serial device.
In order to do so:
- Edit your VM attributes with
virsh edit <VM name> - Scroll down to the
<disk>clause, which you want to set a serial and/or WWN (if it is avirtio-scsi). - Add the desired clause for your disk device. For Serial number, you will use a
<serial>clause. For a WWN, use the<WWN>clause. See a example:
<!-- virtio-block device -->
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2' cache='unsafe'/>
<source file='/run/media/rfreire/Satellite/images/a72-2.interna.rf01.co-disk1'/>
<target dev='vda' bus='virtio'/>
<serial>vaicorinthians</serial>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</disk>
<!-- virtio-SCSI device -->
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/run/media/rfreire/Satellite/images/a72-2.interna.rf01.co-disk2'/>
<target dev='sda' bus='scsi'/>
<serial>Campeao2017</serial>
<wwn>0x500a0751f0156c38</wwn>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
Note: WWNs follows a numbering schema. For more information, please refer to the Content from standards.ieee.org is not included.IEEE Guidelines for Organizationally Unique Identifier PDF document.
Root Cause
By default, virtio-scsi devices does present a ID_SERIAL attribute, stating the disk position in the SCSI pseudo-bus of the VM (these devices are presented normally as /dev/sd*. virtio-block devices does not present a ID_SERIAL or ID_WWN attribute.
For more information, refer to the below table.
| Device Type | Default Serial | Default WWN | Supports WWN | Supports Serial |
|---|---|---|---|---|
| Virtio-Block (/dev/vd*) | N | N | N | Y |
| Virtio-SCSI (/dev/sd*) | Y | N | Y | Y |
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.