Qemu: can I set the serial number on a virtual SCSI device

kvm-virtualizationqemuscsi

I'm using libvirt+KVM+Qemu on Ubuntu 11.04. I have some scsi devices like this:

<disk type='file' device='disk'>
  <driver name='qemu' type='raw'/>
  <source file='/var/lib/libvirt/images/shared-01-02-00.img'/>
  <target dev='sda' bus='scsi'/>
  <address type='drive' controller='0' bus='0' unit='0'/>
</disk>

The show up in the virtual machine as e.g. /dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi0-0-0

For my management purposes, I would like to be able to assigned an arbitrary 'serial number' to the virtual devices, which would show up when scsi_id is run on the block device from inside the virtual machine. How can I do that?

Best Answer

I looked over the libvirt docs and found this:

serial
If present, this specify serial number of virtual hard drive. For example, it may look like WD-WMAP9A966149.

So the XML block you have above would become:

<disk type='file' device='disk'>
  <driver name='qemu' type='raw'/>
  <source file='/var/lib/libvirt/images/shared-01-02-00.img'/>
  <target dev='sda' bus='scsi'/>
  <address type='drive' controller='0' bus='0' unit='0'/>
  <serial>some-arbitrary-serial</serial>
</disk>