• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

UnixArena

  • Home
  • kubernetes
  • DevOps
    • Terraform
    • Jenkins
    • Docker
    • Openshift
      • OKD
    • Ansible engine
    • Ansible Tower
      • AWX
    • Puppet
  • Cloud
    • Azure
    • AWS
    • Openstack
    • Docker
  • VMware
    • vCloud Director
    • VMware-Guests
    • Vcenter Appliance 5.5
    • vC OPS
    • VMware SDDC
    • VMware vSphere 5.x
      • vSphere Network
      • vSphere DS
      • vShield Suite
    • VMware vSphere 6.0
    • VSAN
    • VMware Free Tools
  • Backup
    • Vembu BDR
    • Veeam
    • Nakivo
    • Azure Backup
    • Altaro VMBackup
    • Spinbackup
  • Tutorials
    • Openstack Tutorial
    • Openstack Beginner’s Guide
    • VXVM-Training
    • ZFS-Tutorials
    • NetApp cDot
    • LVM
    • Cisco UCS
    • LDOM
    • Oracle VM for x86
  • Linux
    • How to Articles
    • Q&A
    • Networking
    • RHEL7
  • DevOps Instructor-led Training
  • Contact

Linux KVM – Change libvirt VM image store path – Part 10

December 23, 2015 By Cloud_Devops 6 Comments

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.

KVM storage pool - Linux
KVM storage pool – Linux

 

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 !!!

Filed Under: Linux KVM, Redhat Enterprise Virtualization, Redhat-LINUX, RHEL7 Tagged With: KVM, Linux KVM, Redhat Enterprise Virtualization, Redhat Linux, RHEL7

Reader Interactions

Comments

  1. Marc says

    January 30, 2021 at 4:03 pm

    Excellent article and steps to follow. Worked perfectly. Thank you for taking the time to put this together. Always learning..

    Reply
  2. James says

    June 29, 2020 at 3:53 am

    Great article, I really appreciate you writing it. I Followed it step by step and it worked perfectly, Thank you!!

    Reply
  3. Ivan says

    February 24, 2020 at 1:03 am

    Thank you very much for your article it was very helpful 😀

    Reply
  4. Me says

    February 7, 2017 at 9:01 am

    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

    Reply
  5. David Leeming says

    October 9, 2016 at 11:23 pm

    Perfect – This is exactly what I wanted to do, and I couldn’t find it in any other documentation. Many thanks

    Reply
  6. Tapas Mallick says

    September 17, 2016 at 2:20 pm

    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.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Follow UnixArena

  • Facebook
  • LinkedIn
  • Twitter

Copyright © 2025 · UnixArena ·

Go to mobile version