In this short tutorial we detail how to create a raw disk image file using qemu-img. Once created, we pass the disk image file to a virtual machine (“VM”) and use it as a virtual disk on which to install the VM’s operating system.
Although this tutorial uses the “raw” disk image format, according to the xl-disk-configuration manpage, qcow, qcow2, vhd, and qed are also accepted formats for VM running on Xen Project hypervisor. Note that these format options are also available when creating a disk image file using qemu-img.
If you’ve installed the Xen Project hypervisor meta-package on a machine running Debian, the qemu-img program should have been installed automatically. Otherwise, qemu-img may be installed via the qemu-utils package.
To install qemu-utils using apt-get, execute the following command:
$ sudo apt-get install qemu-utils
Once qemu-img is installed, we can create an 8GB raw disk image file in the /root/ directory named “vidigest-disk.img” with the following command:
$ sudo qemu-img create -f raw /root/vidigest-disk.img 8G
Once the disk image file has been created, we pass it to the VM by modifying the VM’s .cfg file adding the following “disk” option syntax:
disk = [ '/root/vidigest.img,raw,xvda,rw', ]
Now we’re ready to add a filesystem and/or partition to the disk image file during the installation of the VM’s operating system.