2

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?

1 Answer 1

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>
4
  • 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, 2011 at 9:59
  • Awesome. Glad it worked. Good to know about the "-p 0x80" flag too. Oct 10, 2011 at 21:11
  • 1
    Can this be done directly with qemu command line instead of libvirt? Nov 11, 2019 at 2:31
  • @CMCDragonkai: that is possible if you use the -device command line parameter to explicitly specify how the disk image is attached to the virtual machine. There's an example at gist.github.com/ndunks/39bbf227f53fcaac5c1e7bf8fa53d930 : use something like -drive if=none,id=disk00,format=qcow2,file=tmp/disk1.qcow2 -device "ide-hd,drive=disk00,serial=00000000000000000001,model=VMware Virtual IDE Hard Drive". I don't know if that's correct or actually the best way, but it worked for me.
    – oliver
    Sep 15, 2022 at 12:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .