Question: I am using libvirt and virt-manager to create VMs on my Linux system. I noticed that the VM images are stored in /var/lib/libvirt/images directory. Is there a way to change the default location of VM image directory to something else?

libvirt and its GUI front-end virt-manager can create and manage VMs using different hypervisors such as KVM and Xen. By default, all the VM images created via libvirt go to /var/lib/libvirt/images directory. However, this may not be desirable in some cases. For example, the disk partition where /var/lib/libvirt/images lives may have limited free space. Or you may want to store all VM images in a specific repository for management purposes.

In fact, you can easily change the default location of the libvirt image directory, or what they call a “storage pool.”

There are two ways to change the default storage pool.

Method One: Virt-Manager GUI

If you are using virt-manager GUI program, changing the default storage pool is very easy.

Go to “Edit” -> “Connection Details” in virt-manager menu GUI.

if “Connection Details” is greyed out… select first entry in list localhost or in this case QEMU/KVM

then it should be possible to select “Connection Details” (not greyed out)

virt-manager change default location where vms are stored

You will see the default storage pool as shown below. On the left bottom of the window, click on the cross icon, which will stop the default storage pool. Once the pool is stopped, click on the trash bin icon on the right, which will delete the pool. Note that this action will NOT remove the VM images inside the pool.

Now click on the plus icon on the far left to add a new storage pool.

virt-manager change default location where vms are stored2

Type in the name of a new storage pool (e.g., default), and choose the type of the pool. In this case, choose a “filesystem directory” type since we are simply changing a storage pool directory.

first step is to “give it a name” (go with the name “default”)

virt-manager change default location where vms are stored3

Type in the path of a new storage pool (e.g., /storage).

or /home/user/vms

virt-manager change default location where vms are stored4

At this point, the new storage pool should be started, and automatically used when you create a new VM.

select “on boot” for the pool to auto start on boot.

virt-manager change default location where vms are stored5

Method One: Virsh Command-Line

Another method to change the default storage pool directory is to use virsh command line utility which comes with libvirt package.

First, run the following command to dump XML definition of the default storage pool.

$ virsh pool-dumpxml default > pool.xml

Open this XML file with a text editor, and change <path> element from /var/lib/libvirt/images to a new location.

[cc lang=”xml” escaped=”true” width=”600″]

default
0ec0e393-28a2-e975-feec-0c7356f38d08
975762788352
530052247552
445710540800

/var/lib/libvirt/images 0711
-1
-1

[/cc]

Remove the current default pool.

$ virsh pool-destroy default
Pool default destroyed

Now create a new storage pool based on the updated XML file.

$ virsh pool-create pool.xml
Pool default created from pool.xml

At this point, a default pool has been changed to a new location, and is ready for use.

Subscribe to Ask Xmodulo

Do you want to receive Linux related questions & answers published at Ask Xmodulo? Enter your email address below, and we will deliver our Linux Q&A straight to your email box, for free. Delivery powered by Google Feedburner.

liked this article?

  • only together we can create a truly free world
  • plz support dwaves to keep it up & running!
  • (yes the info on the internet is (mostly) free but beer is still not free (still have to work on that))
  • really really hate advertisement
  • contribute: whenever a solution was found, blog about it for others to find!
  • talk about, recommend & link to this blog and articles
  • thanks to all who contribute!
admin