Adding a new disk on KVM guest

First check the configuration (this is the default location of the VMs)

1
2
3
4
# virsh domblklist vm01
Target     Source
------------------------------------------------
vda        /var/lib/libvirt/images/vm01.qcow2

Create the disk (replace the path according to your pool)

1
# sudo virsh vol-create-as default --format qcow2 vm01-1.qcow2 1G

or

1
2
# qemu-img create -f qcow2 /var/lib/libvirt/images/vm01-1.qcow2 1G
Formatting '/var/lib/libvirt/images/vm01-1.qcow2', fmt=qcow2 size=1073741824 encryption=off cluster_size=65536 lazy_refcounts=off 

Attach the new disk

1
2
# virsh attach-disk vm01 --source /var/lib/libvirt/images/vm01-1.qcow2 --target vdb --persistent --driver qemu --subdriver qcow2
Disk attached successfully

Check the configuration and verify the XML file

1
2
3
4
5
# virsh domblklist vm01
Target     Source
------------------------------------------------
vda        /var/lib/libvirt/images/vm01.qcow2
vdb        /var/lib/libvirt/images/vm01-1.qcow2
1
# cat /etc/libvirt/qemu/vm01.xml
1
2
3
4
5
6
   <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/vm01-1.qcow2'/>
      <target dev='vdb' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x0a' function='0x0'/>
    </disk>