In KVM , VM images are stored in /var/lib/libvirt/images directory by default. There might be the space limitation since /var filesystem lives under root-vg. In KVM virtualization, everyone would prefer to store VM images in central repository to migrate running VM from one hypervisor to another. In that case, you need to change the default path for the libvirt images or you need to mount the volume or NFS share on “/var/lib/libvirt/images” . In this article, we will see that how to modify the default libvirt images path to desired one. In KVM terminology , we will call it as “storage pool”.
Note: This activity has been performed on non-selinux Node. If SELINUX is enabled, then you need to modify the context for new storage path accordingly .
[root@UA-HA ~]# getenforce Disabled [root@UA-HA ~]#
1.Login to the KVM hypervisor host and stop all the running VM’s.
[root@UA-HA kvmpool]# virsh shutdown UAKVM2 [root@UA-HA kvmpool]# [root@UA-HA ~]# virsh list --all Id Name State ---------------------------------------------------- - UAKVM2 shut off [root@UA-HA ~]#
2.List the storage pool.
[root@UA-HA ~]# virsh pool-list Name State Autostart ------------------------------------------- default active yes [root@UA-HA ~]#
3.View the storage pool information.
[root@UA-HA ~]# virsh pool-info default Name: default UUID: 3599dd8a-edef-4c00-9ff5-6d880f1ecb8b State: running Persistent: yes Autostart: yes Capacity: 17.50 GiB Allocation: 7.67 GiB Available: 9.82 GiB [root@UA-HA ~]#
4. Check the existing storage pool path. (Ignore the syntax)
[root@UA-HA ~]# virsh pool-dumpxml default |grep -i path path-/var/lib/libvirt/images-/path [root@UA-HA ~]#
5. Verify that what are the existing VM images are stored on the default path.
[root@UA-HA ~]# virsh vol-list default |grep "/var/lib/libvirt/images" UAKVM2.qcow2 /var/lib/libvirt/images/UAKVM2.qcow2 [root@UA-HA ~]# [root@UA-HA ~]# virsh vol-list default Name Path ------------------------------------------------------------------------------ UAKVM2.qcow2 /var/lib/libvirt/images/UAKVM2.qcow2 [root@UA-HA ~]#
6.Stop the storage pool.
[root@UA-HA ~]# virsh pool-destroy default Pool default destroyed [root@UA-HA ~]#
7.Edit the default pool configuration.
8.Start the storage pool.
[root@UA-HA ~]# virsh pool-start default Pool default started [root@UA-HA ~]#
9.Verify the storage pool path. (Ignore the syntax)
[root@UA-HA ~]# virsh pool-dumpxml default |grep -i path path /kvmpool path [root@UA-HA ~]#
10. Move the VM images from old path to new Path.
[root@UA-HA ~]# mv /var/lib/libvirt/images/UAKVM2.qcow2 /kvmpool/ [root@UA-HA ~]#
11. Edit the VM configuration file to update the new storage pool path. (Ignore syntax)
source file='/kvmpool/UAKVM2.qcow2'
12.Start the KVM guest.
[root@UA-HA kvmpool]# virsh start UAKVM2 Domain UAKVM2 started [root@UA-HA kvmpool]#
If you get error like below,
” error: Failed to start domain XXXXX
error: unsupported configuration: Unable to find security driver for model selinux ”
Edit the VM configuration file and remove “selinux” line from the XML file (In Bottom) & try to start the VM.
# virsh edit UAKVM2 ................... seclabel type='dynamic' model='selinux' relabel='yes';/seclabel ----> Remove this line .
Hope this article informative to you. Share it ! Comment it !! Be Sociable !!!
Marc says
Excellent article and steps to follow. Worked perfectly. Thank you for taking the time to put this together. Always learning..
James says
Great article, I really appreciate you writing it. I Followed it step by step and it worked perfectly, Thank you!!
Ivan says
Thank you very much for your article it was very helpful 😀
Me says
Thanks, I was trying to figure out what caused the “Error starting domain: unsupported configuration: Unable to find security driver for model selinux” problem, and the documentation wasn’t much help. Really appreciate it
David Leeming says
Perfect – This is exactly what I wanted to do, and I couldn’t find it in any other documentation. Many thanks
Tapas Mallick says
Hi,
Is it possible to change the Virtual Machine Configuration directory (/etc/libvirt/qemu/) with such approach mentioned in this article? Intention behind to do this to store VM configuration xml to a Shared NFS/GFS file system by default which will reduce manual steps to copy the configuration file in case we integrate Pacemaker for Migration or HA.
Thanks for the article.