Sandbox99 Chronicles

How to Change the Default KVM/QEMU Image Location

Libvirt Images Location

Written by Jose Mendez

Hi, I’m Jose Mendez, the creator of sandbox99.cc. with a passion for technology and a hands-on approach to learning, I’ve spent more than fifteen years navigating the ever-evolving world of IT.

Published Aug 25, 2025 | Last updated on Aug 25, 2025 at 8:14AM

Reading Time: 3 minutes

Introduction

“Have you ever run out of disk space on your root partition after creating just a few virtual machines? That’s because KVM and libvirt, by default, tuck away all your virtual disk images in /var/lib/libvirt/images. This default setting is fine for a quick test, but it quickly becomes a bottleneck for any serious virtualization project. Fortunately, libvirt provides a clean way to fix this by redefining its storage pools. Follow along as we break down exactly how to move your virtual machine library to a new, more spacious location without breaking anything.”

Step by step guide

To change the default location for KVM/QEMU images, you need to modify the libvirt storage pool. Libvirt manages virtual machine storage using pools, and by default, a pool named “default” is created in /var/lib/libvirt/images. You can either edit the existing “default” pool or delete it and create a new one with the same name.

Here’s a step-by-step guide using the command-line utility virsh:

1. Identify the Current Default Pool

First, list all existing storage pools to confirm the “default” pool is present and to check its current status.

virsh pool-list --all

To see the current path of the default pool, use pool-dumpxml.

virsh pool-dumpxml default | grep -i path

This will show you the current location, which is usually /var/lib/libvirt/images.


2. Move Existing Images and Stop the Pool

Before changing the location, you should move any existing virtual disk images to the new directory.

2.1 Stop all VMs that use the default storage pool. You can use the virsh shutdown [VM_NAME] command.

2.2 Create your new directory. For example, /mnt/data/libvirt/images.

sudo mkdir -p /mnt/data/libvirt/images

2.3 Move the image files from the old location to the new one.

sudo mv /var/lib/libvirt/images/* /mnt/data/libvirt/images/

2.4 Destroy the current default pool. This doesn’t delete the files, but it makes the pool inactive and undefined.

virsh pool-destroy default virsh pool-undefine default

This removes the default pool’s definition, allowing you to create a new one.


3. Define and Start the New Pool

Now, create a new storage pool named “default” that points to your new location.

3.1 Define the new default pool. Replace the /path/to/new/images with your desired directory.

Bashvirsh pool-define-as --name default --type dir --target /mnt/data/libvirt/images

3.2 Start the new pool.

virsh pool-start default

3.3 Set the pool to autostart on boot.

virsh pool-autostart default

4. Verify and Update VM Configuration

Finally, verify that the change was successful and update any existing VM configurations.

4.1 Check the new pool location.

Bashvirsh pool-dumpxml default | grep -i path

The output should now show your new directory.

4.2 Change permissions. Ensure the qemu user has the correct permissions to access the new directory. This is crucial for VMs to function correctly.

sudo chown -R qemu:qemu /mnt/data/libvirt/images 
sudo setfacl -R -m u:qemu:rx /mnt/data/libvirt/images

4.3 Restart the libvirt daemon for the changes to take full effect.

sudo systemctl restart libvirtd

4.4 Update existing VM XML files. For each VM you moved, you must edit its XML configuration to reflect the new disk image path.

virsh edit [VM_NAME]

In the editor, find the <source file='...'> tag and change the path to your new location. For example:XML<disk type='file' device='disk'> ... <source file='/mnt/data/libvirt/images/my-vm-disk.qcow2'/> ... </disk>
After these steps, all new virtual machines will use your new default location, and the moved VMs will be able to start with their new path.

Final Thoughts

Changing the default image location is more than just a quick fix; it’s a lesson in understanding how libvirt manages storage. This concept of storage pools is central to libvirt’s design, and mastering it gives you the power to manage your virtual resources more effectively. While the default setup gets you started, customizing it to fit your needs is the key to building a professional and reliable virtualization lab. Now that you know how to do it, you can apply this same principle to manage different types of storage, from network-attached storage (NAS) to dedicated SSDs

Calendar

September 2025
S M T W T F S
 123456
78910111213
14151617181920
21222324252627
282930  

Related Post