Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

KVM virsh attach-disk does not honour device letter

I use the following command to attach a disk to a running KVM virtual server:

virsh attach-disk vps_89 /dev/nbd31 --target vdc --driver tap

The disk is attached correctly. However, the disk is not attached as vdc inside the virtual server. I know the documentation says that the --target parameter is only giving a "hint" to the virtual server, but I can't really believe there is NO way to force the disk to be attached as a certain device (at least on Linux).

I am controlling my virtual servers through scripts and I must trust that the disk is attached to the exact device as I tell it to.

When I detach the disk using this:

virsh detach-disk vps_89 --target vdc

Then re-attaching the same disk again, the device-ID seems to be increamented each time, i.e vdc, vdd, vde, vdf etc... (totally ignoring my --target param)

Does anyone know a good (and reliable) way of attaching disks to KVM in a predictable way?

like image 766
Daniele Testa Avatar asked Oct 21 '25 13:10

Daniele Testa


1 Answers

According to RedHat [1] and libvirt [2] this is not a bug, it's a feature:

The actual device name specified is not guaranteed to map to the device name in the guest OS. Treat it as a device ordering hint.

The only available solution is to use UUID (/dev/disk/by-uuid/) for handling disk inside virtual machine.

  1. https://bugzilla.redhat.com/show_bug.cgi?id=693372
  2. http://libvirt.org/formatdomain.html
like image 64
nab Avatar answered Oct 24 '25 11:10

nab