Change KVM (libvirt) default storage path…

By default Red Hat will store your images and vm disks in the /var/lib/libvirt/images path. There is storage limit inside directory. Usually for my LABs I don’t have a need for various other storage configurations, I just need to move default path to my home directory since there is a lot of space.

Let’s begin.

Before we begin

Root user

Run all commands as root user

su - root

Make new directory for your VMs

I made /home/vms directory.

mkdir /home/vms

SELinux

First, check your SELinux status. You may have problems with SELinux after deploying this. I didn’t have and I have SELinux in enforcing state on Red Hat 8.2. If you have problems, make sure to change SELinux mode to permissive, or disabled.

getenforce

Virtual machines stop/backup

I’m also usually doing this on a fresh machine, right after KVM installation.

If you already have virtual machines inside /var/lib/libvirt/images make sure that these machines are stopped and that you have a fresh backup! Do not execute these changes without proper backup plan.

To stop active VMs run

virsh shutdown YOURVMname

To copy your VM to new created directory, execute

mv /var/lib/libvirt/images/YOURVMname.qcow2 /home/vms

You should also edit config file of the VM to reflect changes and point to new storage path

 source file='/home/vms/YOURVMname.qcow2'

Change storage path

Ok, let’s start the process.

First we will list our storage pools

virsh pool-list

Next, we will check default pool information

virsh pool-info default

From that command you will see that I have only 50GB of storage space for my VMs inside default pool.

And at last, we will check default storage path

virsh pool-dumpxml default |grep -i path

We will now stop default storage pool

virsh pool-destroy default

We will again check if pool is in inactive state

virsh pool-list --all

After you are sure that default pool is in inactive state, we will edit default pool configuration

virsh pool-edit default

Change path line to reflect your new folder setting. In my case it is /home/vms

<path>/home/vms</path>

Save the file and exit.

We will now start default storage pool

virsh pool-start default

We will once again check to see path for the default pool

virsh pool-dumpxml default |grep -i path

And if I again check details for the default pool, I will see that now I have 400GB at my disposal for the VMs. Much better.

virsh pool-info default

If you already have virtual machines installed, and you edited them and transfered them to the new location like I described earlier, you can run them again

virsh start YOURVMname

As you can see, my VM is running properly.

I was also able to create new VMs without any problem.

In case you have error connected to SELinux that goes something like this.

” error: Failed to start domain XXXXX
error: unsupported configuration: Unable to find security driver for model selinux ”

Edit your VM configuration file

virsh edit YOURVMname

and remove following line

seclabel type='dynamic' model='selinux' relabel='yes';/seclabel

That would be it for this one.

Disclaimer