Adding a new disk on KVM guest

Feb 10, 2020

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

# virsh domblklist vm01
Target     Source
------------------------------------------------
vda        /var/lib/libvirt/images/vm01.qcow2

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

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

or

# 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

# 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

# virsh domblklist vm01
Target     Source
------------------------------------------------
vda        /var/lib/libvirt/images/vm01.qcow2
vdb        /var/lib/libvirt/images/vm01-1.qcow2
# cat /etc/libvirt/qemu/vm01.xml
   <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>
virtualizationlinuxkvm

Determine disk usage for a filesystem

How to use virt-manager on Windows and Mac

comments powered by Disqus