During a process of moving to a virtualized infrastructure I encountered the following curious problem.
We want to evaluate everything first. This involves creating a virtual images of all required systems, running them all together in an isolated environment and extensive testing of that environment. Then, if everything went good, we are going to repeat everything for real.
The server I am going to virtualize this time is critical. It is very undesirable to take it out of service, even in off-peak hours. It is running Oracle database over Linux (RHEL), it is paired with another identical machine, they are sitting behind the load balancer, but still we don't want to shutdown it. However, a slight load increase for some period of time is OK.
Luckily, everything is deployed over LVM and there is enough space in VGs to make snapshots of volumes and take those snapshots. However, space constraints do not permit to make snapshots of all volumes simultaneously, so I'm going to do this sequentially; each individual volume will be consistent and the "time warps" between creating the snapshots of several volumes doesn't matter much. Each snapshot will be imaged with dd
over SSH to some transient space.
In the end, there will be several snapshots of individual LVM LVs. But for running it as a VM, we need a complete single disk image, which should include all created snapshots as parts.
With qemu it is possible to create an "overlay" qcow2 snapshot for Qemu by specifying a backing image: qemu-img create -f qcow2 -b original-image -F raw new-image.qcow2
, so original image is immutable and all changes will be written to overlay new-image.qcow2
.
Is it possible to do that for several backing images somehow? E.g. if I have a bunch of image files which represent raw LVM volumes "VolGroup00/root", "VolGroup00/var", etc., is there a possibility to create an overlay image which will represent them as LVM volumes (parts of the disk)? The following image illustrates the goal:
I want that LBAs 1GiB+31GiB of the vm-assembled-image.qcow2
to reference LBAs 0÷30GiB of the VolGroup-root.raw
, which is exactly 30GiB (when read; but if anything is written to these LBAs, it should go to qcow2 and subsequent reads should also return data that was previously written to qcow2), LBAs 50GiB÷100GiB of the assembled image to reference LBAs 0÷50GiB of VolGroup00-var.raw
, which is exactly 50GiB (again, anything that is going to be written to that area should be stored to qcow2, and read should be done first from qcow2, and if nothing is stored for that block the read should be performed against raw base image part), and the rest is to be read as zero until written, in which case it is written to qcow2.
Is it possible to do directly? Or is it possible to do it using Device Mapper framework: to define some virtual space, map areas of it into those files, and then I'll use that virtual space as the Qemu base image?