1

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?

5

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>
| improve this answer | |
  • Nice: bit of experimentation required, but with this set, I get the ID passed through in the output of scsi_id when I use the "-p 0x80" flag. Thanks, I feel silly for missing this in the docs :-) – kdt Oct 10 '11 at 9:59
  • Awesome. Glad it worked. Good to know about the "-p 0x80" flag too. – up_the_irons Oct 10 '11 at 21:11
  • Can this be done directly with qemu command line instead of libvirt? – CMCDragonkai Nov 11 '19 at 2:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.