title: How to detach a disk from KVM correctly
body: <p>When I try to detach a drive in KVM, I get the following error:</p>
  <h1>virsh detach-disk vps_99 vde</h1>
  <p>error: operation failed: disk vde cannot be detached - no PCI address for device</p>
  <p>I have tried google, but can't find anyone else with the same problem??</p>
  <p>Here is the XML-dump of my VPS:</p>
  <pre><code>(root@h2)-(/home/cloud)# virsh dumpxml vps_99
  &lt;domain type='kvm' id='218'&gt;
    &lt;name&gt;vps_99&lt;/name&gt;
    &lt;uuid&gt;42db1de2-f0d4-1030-ac57-0050560018a2&lt;/uuid&gt;
    &lt;memory&gt;524288&lt;/memory&gt;
    &lt;currentMemory&gt;524288&lt;/currentMemory&gt;
    &lt;vcpu&gt;1&lt;/vcpu&gt;
    &lt;os&gt;
      &lt;type arch='x86_64' machine='pc-0.12'&gt;hvm&lt;/type&gt;
      &lt;boot dev='hd'/&gt;
    &lt;/os&gt;
    &lt;features&gt;
      &lt;acpi/&gt;
      &lt;apic/&gt;
      &lt;pae/&gt;
    &lt;/features&gt;
    &lt;clock offset='utc'/&gt;
    &lt;on_poweroff&gt;restart&lt;/on_poweroff&gt;
    &lt;on_reboot&gt;restart&lt;/on_reboot&gt;
    &lt;on_crash&gt;restart&lt;/on_crash&gt;
    &lt;devices&gt;
      &lt;emulator&gt;/usr/bin/kvm&lt;/emulator&gt;
      &lt;disk type='block' device='disk'&gt;
        &lt;driver name='qemu' type='raw'/&gt;
        &lt;source dev='/dev/nbd1'/&gt;
        &lt;target dev='vda' bus='virtio'/&gt;
      &lt;/disk&gt;
      &lt;disk type='block' device='disk'&gt;
        &lt;driver name='qemu' type='raw'/&gt;
        &lt;source dev='/dev/nbd2'/&gt;
        &lt;target dev='vdb' bus='virtio'/&gt;
      &lt;/disk&gt;
      &lt;disk type='block' device='disk'&gt;
        &lt;driver name='qemu' type='raw'/&gt;
        &lt;source dev='/dev/nbd3'/&gt;
        &lt;target dev='vde' bus='virtio'/&gt;
      &lt;/disk&gt;
      &lt;interface type='bridge'&gt;
        &lt;mac address='00:50:56:00:1b:24'/&gt;
        &lt;source bridge='br0'/&gt;
        &lt;target dev='vnet3'/&gt;
        &lt;model type='virtio'/&gt;
      &lt;/interface&gt;
      &lt;input type='mouse' bus='ps2'/&gt;
      &lt;graphics type='vnc' port='5903' autoport='yes' keymap='en-us'/&gt;
      &lt;video&gt;
        &lt;model type='cirrus' vram='9216' heads='1'/&gt;
      &lt;/video&gt;
    &lt;/devices&gt;
    &lt;seclabel type='dynamic' model='apparmor'&gt;
      &lt;label&gt;libvirt-42db1de2-f0d4-1030-ac57-0050560018a2&lt;/label&gt;
      &lt;imagelabel&gt;libvirt-42db1de2-f0d4-1030-ac57-0050560018a2&lt;/imagelabel&gt;
    &lt;/seclabel&gt;
  &lt;/domain&gt;
  </code></pre>
  <p>Another crazy thing is that the drive I specify as &quot;vde&quot; gets connected to the virtual server as &quot;vdc&quot; as if it is totally ignoring my &quot;vde&quot; specification.</p>
  <p>If someone can tell me how to make sure the drive is attached as the device I specify, I would be greatful. Amazon Web Services seems to be able to do it, so why should'nt I :)</p>
  <p>UPDATE: After the virtual machine has been started, it seems I can add and remove NEW disks without any problems. Seems it is only problems to detach disks that was defined in the original XML used to create the virtual server. But the question remains, how do I detach disks that was defined when the virtual server was defined?</p>
  <p>UPDATE 2: I have also tried adding a <code>&lt;address&gt;</code> entry for each disk to make sure each disk gets connected at a pre-defined slot, i.e
  <code>&lt;address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/&gt;</code>
  But still does not work to detach the disks and a &quot;virsh dumpxml vps_99&quot; actually shows that my  entries has been entirely removed/ignored.</p>
  <p>UPDATE 3: I also tried putting the disk-definition in a temp XML-file and ran: virsh detach-device vps_99 disk.xml
  Still same error:
  error: Failed to detach device from disk.xml
  error: operation failed: disk vdi cannot be detached - no PCI address for device</p>