Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to hot-add a file-based disk to a running KVM virtual server. I've created a new disk from scratch using the command

dd of=/home/cloud/vps_59/test.img bs=1 seek=5G count=0

and I was hoping to get it hot-added to the guest by doing this in the virsh shell:

virsh # attach-disk vps_59 /home/cloud/vps_59/test.img \
        vdd --driver=file --subdriver=raw

The XML definition of the domain then becomes:

<disk type='file' device='disk'>
  <driver name='qemu' type='raw'/>
  <source file='/home/cloud/vps_59/root.img'/>
  <target dev='vda' bus='virtio'/>
<disk type='file' device='disk'>
  <driver name='file' type='raw'/>
  <source file='/home/cloud/vps_59/test.img'/>
  <target dev='vdd' bus='virtio'/>

As you can see, the driver name becomes wrong, it should be driver name='qemu' as the existing vda disk. I have tried with --drive=qemu but it states it is unsupported.

Secondly, I only "see" the newly added drive once I reboot the virtual machine running Ubuntu 10.04.4 LTS. How can I make the drive "hotplug"? I want the virtual machine to "see" the new drive immediately without a reboot.

share|improve this question
Unrelated suggestion, use qemu-img instead of dd - its arguments come more natural and does the same thing: qemu-img create test.img 5G –  chutz Dec 12 '12 at 0:05

1 Answer 1

First of all, you should avoid using virsh attach-disk with its limited amount of options. Instead, I suggest to specify the exact disk format you prefer in a separate, temporary XML file, like this:

<disk type='file' device='disk'>
  <driver name='qemu' type='qcow2' cache='writeback'/>
  <source file='/home/gert/kvm/testdomain-vdb.img'/>
  <target dev='vdb' bus='virtio'/>

Before adding it, make sure the hotplug kernel modules are loaded in the guest:

modprobe acpiphp
modprobe pci_hotplug

Some distributions, including recent CentOS/RHEL/Fedora have this built-in in the kernel. In this case, check for CONFIG_HOTPLUG_PCI_ACPI. If it's y, then you're all set.

Finally, add it to the running VM using

virsh # attach-device [domain] /path/to/disk.xml

(optionally, add the --persistent option to let Libvirt update the domain XML definition 'persistent'.)

In the guest, the kernel should now be triggered, as can be checked with dmesg:

[  321.946440] virtio-pci 0000:00:06.0: using default PCI settings
[  321.952782]  vdb: vdb1 vdb2

This also works perfectly using the GUI-enabled virt-manager application.

See also:

share|improve this answer
Shouldn't you also add --persistent to make sure this configuration does not get lost when you power off the virtual machine? –  chutz Dec 12 '12 at 0:06
@chutz yes, thanks. updated my answer. –  gertvdijk Dec 12 '12 at 0:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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