Sat, March 31, 2018 ยท 1 min read

Libvirt volume management

Libvirt volume management

On libvirt a default storage pool is created called default, which uses location /var/lib/libvirt/images for file based volumes. Each VM created will have a volume, volumes can be created beforehand and the volume destination can be provided for the virt-install command.

List storage pools

$ virsh pool-list
 Name                 State      Autostart
-------------------------------------------
 cipher               active     yes
 default              active     yes
 store                active     yes

Pool information

$ virsh pool-info default
Name:           default
UUID:           5a67026a-5879-4294-9595-297d79ae8d23
State:          running
Persistent:     yes
Autostart:      yes
Capacity:       78.24 GiB
Allocation:     42.74 GiB
Available:      35.51 GiB

$ virsh pool-info store
Name:           store
UUID:           f51da59f-59e5-45d7-9f13-138a067ddc49
State:          running
Persistent:     yes
Autostart:      yes
Capacity:       596.17 GiB
Allocation:     50.00 GiB
Available:      546.17 GiB

List volumes

$ virsh vol-list default
 Name                 Path
------------------------------------------------------------------------------
 centos-VAGRANTSLASH-7_vagrant_box_image_1802.01.img /var/lib/libvirt/images/...
 centosext.qcow2      /var/lib/libvirt/images/centosext.qcow2

Creating volumes

Create from XML:

<volume type='file'>
  <name>alpha.qcow2</name>
  <key>/var/lib/libvirt/images/alpha.qcow2</key>
  <capacity unit='bytes'>107374182400</capacity>
  <allocation unit='bytes'>3099361280</allocation>
  <target>
    <path>/var/lib/libvirt/images/alpha.qcow2</path>
    <format type='qcow2'/>
  </target>
</volume>
$ virsh vol-create default alpha.xml
Vol alpha.qcow2 created from alpha.xml

Or use vol-create-as:

$ virsh vol-create-as default beta.qcow2 2G
Vol beta.qcow2 created

Volume info

$ virsh vol-info /var/lib/libvirt/images/beta.qcow2
Name:           beta.qcow2
Type:           file
Capacity:       2.00 GiB
Allocation:     2.00 GiB

Wipe and delete volumes

$ virsh vol-wipe /var/lib/libvirt/images/alpha.qcow2
Vol /var/lib/libvirt/images/alpha.qcow2 wiped

$ virsh vol-delete /var/lib/libvirt/images/alpha.qcow2
Vol /var/lib/libvirt/images/alpha.qcow2 deleted