A few years ago I found out about backing images (or “base-images”)[17]. Back then I was doing lots of development on host provisioning tools and needed to be able to quickly revert machines I was working on to a desired initial state. In this use case backing images were especially handy when working on features that frequently destroyed the machine if it didn't work right.
TODO: Link to snapshot section
Snapshots were an option, but how they worked wasn't documented very well at the time. I went with backing images instead, as they worked perfectly for what I needed them to do. I could work iteratively and commit changes in the COW image [16] (copy-on-write) back to the base-image [17] when I was satisfied. I also could use the same base-image for multiple COWs at once. This meant that other people on my team working on the same project could all use the same base-image.
TODO: Maybe create an analogy relating base image workflow with version control
Example 2.20. Creating a Disk with a Backing Image
$ mkdir base-images $ mkdir webserver01 $ cd base-images $ qemu-img create -f qcow2 image-webserver-base.qcow2 10G Formatting 'image-webserver-base.qcow2', fmt=qcow2 size=10737418240 encryption=off cluster_size=0 $ cd ../webserver01 $ qemu-img create -b /srv/images/base-images/image-webserver-base.qcow2 -f qcow2 image-webserver-devel.qcow2 Formatting 'image-webserver-devel.qcow2', fmt=qcow2 size=10737418240 backing_file='/srv/images/base-images/image-webserver-base.qcow2' encryption=off cluster_size=0 $ qemu-img info image-webserver-devel.qcow2 image: image-webserver-devel.qcow2 file format: qcow2 virtual size: 10G (10737418240 bytes) disk size: 136K cluster_size: 65536 backing file: /srv/images/base-images/image-webserver-base.qcow2 (actual path: /srv/images/base-images/image-webserver-base.qcow2)
Procedure 2.1. Steps in Detail
I consider it bad practice to a bunch of bunch of disk images
in a directory so we made two directories here. /srv/images/base-images/
to hold
all the base-images on this system and /srv/images/webserver01
to later
hold the disk assigned to the virtual machine.
Next we go into the base images directory and create a small 10G image, type: QCOW2.
Normally what we used to do at this point is create a virtual machine that uses this disk for it's primary drive. It would get a base OS provisioned on it and any other tweaks we needed there each time it was wiped.
Once the machine was what we wanted in a “Golden Master” it was shutdown and the backing image would be made read-only.
The next step was creating the copy-on-write (COW) image. See
how in the example we give the -b
option with
the full path to the
base-image[18]? Also
note that no size is given after the file name. Size is
implicitly the size of the disks backing image.
With the image preparation complete we would modify the virtual machines configuration and set its primary disk drive to the COW in the webserver01 directory.
[16] In this section when we refer to a COW image it is not apropos the COW (copy-on-write) disk format. Saying COW only serves to help make a distinction between the read-only base-image and the image that changes are copied to on writing.
[17] The terms “base-image” and “backing image” are used interchangeably
[18] Some versions of qemu-img can not handle relative paths)