Convert qcow2 to LVM

For some reason, I had setup a new virtual machine using qcow2, and it was slow, so slow. I had LVMs for all the others. I went out to see if it was possible to convert the qcow2 image to an LVM partition, and it turns out it was easy, but I did have to mix and match a few tips I found here and there.

Convert the qcow2 image to raw

Before doing any of this, it's probably better to shut down the virtual machine. Then, find your disk image, mine was in /var/lib/libvirt/images, so :

cd /var/lib/libvirt/images/

Then, convert the image to raw:

qemu-img convert vmachine.qcow2 -O raw vmachine.raw

Create an LVM partition

But first, find the size we'll need:

ls -l vmachine.raw

This shows:

-rw------- 1 root root 11811160064 Nov 2 12:01 vmachine.raw

That, 11811160064, should be the right size for our LVM partition, so let's create it (in this example, we're using the volume group vg0:

lvcreate -L 11811160064b -nvmachine vg0


Now all we need to do is use `dd` to copy everything to the LVM partition:

dd if=vmachine.raw of=/dev/vg0/vmachine bs=4M

And that's about it. Well, you'll just need to replace the qcow2 disk with the newly created LVM block in your virtual machine settings.