Chapter 2. The Virtual Disk Cookbook

Table of Contents

2.1. Creating Simple Images
2.2. Resizing Disk Images
2.2.1. Resizing RAW Images
2.2.2. Resizing QCOW2 Images
2.3. Query an Image for Information
2.4. Converting Between RAW and QCOW2
2.4.1. Convert an Image from RAW to QCOW2
2.4.2. Convert an Image from QCOW2 to RAW
2.5. Creating Disks with Backing Images
2.6. Comitting changes to a backing image
2.7. Cloning a Physical Disk

In this section we're just going to cover things you'll find yourself needing to do from time to time. Theory and concepts will be covered later on. It's assumed that you're comfortable with the concepts already and don't need everything explained.

TODO: Make a link to theory/concepts

2.1. Creating Simple Images

The simplest operation you can do (next to deleting an image) is creating a new virtual disk image. Depending on what format you choose there are several options available when creating an image:

  • Encryption

  • Compression

  • Backing images [5]

  • Snapshots

In this example we will start simple and only show how to create basic images in different formats. Each image we create will appear to a virtual machine as a drive with 10GB of capacity.

Example 2.1.  Using qemu-img to Create RAW Images

$ qemu-img create webserver.raw 10G
Formatting 'webserver.raw', fmt=raw, size=10485760 kB

TODO: make terms like 'RAW' and etc... link to a relevant section where they are defined

From the fmt attribute in the output above we can see that the format of the virtual disk we created is of type RAW[6], this is the default when using qemu-img. Where it says size=... we see that the disk was created with a capacity of 10485760 kB, or 10gB.