Linux-KVM: Converting Raw Disk Images to LVM Logical Volumes Redux

Linux-KVM: Converting Raw Disk Images to LVM Logical Volumes Redux

This really is an update to my previous article “Linux-KVM: Converting Raw Disk Images to LVM Logical Volumes“, but the process is significantly different and thus requires more explaining than a simple inline update would do it justice.  Now the big flaw with my first article was that by using dd on the hypervisor level, we are opening ourselves up to unintentional data loss due to incompetence or even a very competent slip of the finger.

Now to solve this problem, we essentially use virtualization to protect ourselves.  One of the primary tenants of virtualization is isolation, if one virtual machine were able to affect a change on another then virtualization would have never have any place any IT shop.  So if we can perform our imaging from inside the guest then we won’t risk any data loss outside of the guest.  So to do this we host our images, which have been tarred (with the sparse option) and compressed (with gzip), on a simple web server, can be Apache or IIS.

Now simply boot up your VM with a LiveCD, I prefer to use one with built-in VirtIO support (Ubuntu is what I use) since my images have virtio drivers installed already.  And below you will find the command, which will download the image, run it through a pipe, extract it, and then paste it on the local disk.  Now please keep in mind that you need to confirm the device name in the third part of the command, if you attempt to run this on the hypervisor and put it directly onto the Logical Volume that should work, however be very careful to paste over the correct device for the correct VM.

# wget -O - http://imagerepo/images/imagefile.tgz | tar -zxO | dd of=/dev/vda

This is a 3 part command, the first part downloads the image, second extracts and decompresses, and finally we write the image to the block device.  All of this without the need for extra storage space on the server or the client.

One thought on “Linux-KVM: Converting Raw Disk Images to LVM Logical Volumes Redux

  1. Harihara

    What are the sizes of the qcow2 images that you are creating ? I am trying to create a base image (qcow2) using virt-install of a minimal set of RHEL packages. I did use the minus options of kickstart to reduce the number of packages . The size of the generated qcow 2 is around 1GB . I want to see if this can be reduced further

    Any help will be appreciated