Moving a storage pool in Virt Manager/Qemu

Today, I had to move my storage pool in Qemu to some other partition due to low disk space on my root partition. I decided to move it to a directory in my /home partition (I'm used to allocating most of my disk space to the /home partition).

First of all, we need to stop libvirtd.

/sbin/service libvirtd stop

Next, we should move the storage pool to the new location. By default the storage pool is located at /var/lib/libvirt/images. I choose to move it to the directory /home/ausmarton/vm.

mv /var/lib/libvirt/images /home/ausmarton/vm

Any storage pool that is configured, has an xml file created for itself in /etc/libvirt/storage. So, in our case, we just need to edit the file /etc/libvirt/storage/default.xml. Here, we need to edit the path element which comes under the target element.

<path>/var/lib/libvirt/images</path>

Now that line should look something like this:

<path>/home/ausmarton/vm</path>

I would like to point out that /etc/libvirt/storage/ also contains a directory called autostart which again contains symlinks to each of the xml files inside /etc/libvirt/storage/. In case if you don't find any files in /etc/libvirt/storage/ try having a look at /etc/libvirt/storage/autostart/.

After this, we also need to make appropriate changes to each of the VM configurations. For this, we need to edit files located in /etc/libvirt/qemu. Each VM would have an xml file with the name that you have configured for the VM. I have a VM named Fedora, and so there's a config file with the name Fedora.xml. In this, we need to change the source element under the disk element which comes under the devices element. Currently in Fedora.xml, the <source> element is:

<source file='/var/lib/libvirt/images/Server.img'/>

We need to change it to:

<source file='/home/ausmarton/vm/Server.img'/>

Finally, we need to start libvirtd,

/sbin/service libvirtd start

and that's that!

Comments

  1. When I attempt to start the moved VM I now get a permission error
    "Error starting domain: Cannot access storage file /home/foo/VMs/myvm.qcow2 (as uid:107 gid:107 permission denied.

    ReplyDelete
    Replies
    1. I got around this but editing /etc/libvirt/qemu.conf - options "user" and "group"

      Delete

Post a Comment

Popular posts from this blog

Errors while trying to monitor Asterisk through Nagios

Configuring remote access for couchdb

Proxy Error 502 “Reason: Error reading from remote server” with Apache 2.2.3