How to create qemu image via Command Line

Posted on

As specified in the title of this article, in order to be precise discussing the subject, it is written to describe how to create qemu image via command line. One of the format file which is known for virtualization technology platform is qcow or currently it is in its 2nd version so it is qcow2. It is adapted by QEMU, one of the famous virtualization technology platform exist. QEMU is an open source technology platform and it is generic purpose for using QEMU is for emulating machine or running server based on virtualization.

So, what is the connection between QEMU and qcow file image format ?. It is because qcow itself is the format which is used as the file format for disk image files used by QEMU. The name of the format, qcow is also stands for “QEMU Copy On Write“.

In order to create a qcow or qcow2 file format, this is the command which is generally need to be executed :

qemu-img create -f format_file location_and_file_name file_size

Description : 
qemu-img : It is the command or the utility which is provided by QEMU virtualization technology platform to perform various operations on disk image file or to be shortened, it is a QEMU disk image utility based on the manual page. 
create : The reserved keyword used in qemu-img command for creating disk image file
-f : It is the first disk image format
format_file : It is the disk image format name
location_and_file_name : It is the location with the name of the image file which is going to be created
file_size : It is the size of image file

To be able to execute the above command pattern, the following package must be checked whether or not it is already been installed or not :

root@hostname:~# apt --installed list | grep qemu-kvm

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

qemu-kvm/now 1:2.5+dfsg-5ubuntu10.2 amd64 [installed,upgradable to: 1:2.5+dfsg-5ubuntu10.14]
root@hostname:~# apt --installed list | grep libvirt-bin

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

libvirt-bin/now 1.3.1-1ubuntu10.1 amd64 [installed,upgradable to: 1.3.1-1ubuntu10.10]
root@hostname:~#

The information concerns those two package or utilities can be shown in the following command execution :

root@hostname:~# apt-cache show qemu-kvm
Package: qemu-kvm
Priority: optional
...
Description-en: QEMU Full virtualization
 QEMU is a fast processor emulator.  This package depends on the
 appropriate qemu-system-$arch to enable KVM to be run.  It also
 includes a script /usr/bin/kvm which runs the appropriate
 qemu-system-$arch in kvm mode.
 .
 Please note that old qemu-kvm configuration files (in /etc/kvm/) are
 no longer used.
Description-md5: d8c3d0e3defbe70c37699d302bf1102e
Multi-Arch: foreign
Homepage: http://www.qemu.org/
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Origin: Ubuntu
Supported: 5y
Task: virt-host

Package: qemu-kvm
Status: install ok installed
...
Description-en: QEMU Full virtualization
 QEMU is a fast processor emulator.  This package depends on the
 appropriate qemu-system-$arch to enable KVM to be run.  It also
 includes a script /usr/bin/kvm which runs the appropriate
 qemu-system-$arch in kvm mode.
...
Package: qemu-kvm
...
Description-en: QEMU Full virtualization
 QEMU is a fast processor emulator.  This package depends on the
 appropriate qemu-system-$arch to enable KVM to be run.  It also
 includes a script /usr/bin/kvm which runs the appropriate
 qemu-system-$arch in kvm mode.
 .
 Please note that old qemu-kvm configuration files (in /etc/kvm/) are
 no longer used.
Description-md5: d8c3d0e3defbe70c37699d302bf1102e
Multi-Arch: foreign
Homepage: http://www.qemu.org/
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Origin: Ubuntu
Supported: 5y
Task: virt-host

user@hostname:~# 

So, based on the description given, qemu-kvm is a QEMU Full Virtualization which is enabling KVM to be run. Another package which is also important for KVM based virtualization technology platform is libvirt-bin. Below is the description of libvirt-bin package as shown below :

root@hostname:~# aptitude show libvirt-bin
Package: libvirt-bin
State: installed
Automatically installed: yes
Version: 1.3.1-1ubuntu10.1
Priority: optional
Section: admin
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Architecture: amd64
Uncompressed Size: 10,9 M
Depends: init-system-helpers (>= 1.18~), lsb-base (>= 4.1+Debian11ubuntu7), libapparmor1 (>= 2.6~devel), libavahi-client3 (>= 0.6.16), libavahi-common3 (>= 0.6.16), libblkid1 (>= 2.17.2), libc6 (>= 2.17), libcap-ng0,
libdbus-1-3 (>= 1.9.14), libdevmapper1.02.1 (>= 2:1.02.97), libgnutls30 (>= 3.4.2), libnetcf1 (>= 1:0.2.2), libnl-3-200 (>= 3.2.7), libnuma1, libparted2 (>= 3.1), libpcap0.8 (>= 1.0.0), libpciaccess0, librados2 (>=
0.72.2), librbd1 (>= 0.72.2), libreadline6 (>= 6.0), libsasl2-2, libsystemd0, libudev1 (>= 183), libvirt0 (= 1.3.1-1ubuntu10.1), libxen-4.6 (>= 4.6.0), libxenstore3.0 (>= 3.2.0), libxml2 (>= 2.7.4), libyajl2 (>=
2.0.4), adduser, bridge-utils, cgmanager | cgroup-lite | cgroup-bin, dnsmasq-base (>= 2.46-1), dbus, ebtables, gettext-base, iptables (>= 1.4.10), logrotate, netcat-openbsd
Recommends: libxml2-utils, gawk, dmidecode, parted, pm-utils
Suggests: policykit-1 (>= 0.105-4~), apparmor (>= 2.8.96~2541-0ubuntu4~), qemu-kvm | qemu (>= 0.9.1), radvd
Conflicts: apparmor (< 2.8.96~2652-0ubuntu1), apparmor:i386 (< 2.8.96~2652-0ubuntu1), libvirt-bin:i386
Breaks: xen-utils-4.1 (>= 4.1.2-2ubuntu2), xen-utils-4.4 (>= 4.4.0-0ubuntu5), xen-utils-4.5 (>= 4.5.0-1ubuntu4)
Enhances: qemu, qemu-kvm, xen
Provides: libvirt-daemon, libvirt-daemon-system
Description: programs for the libvirt library
Libvirt is a C toolkit to interact with the virtualization capabilities of recent versions of Linux (and other OSes). The library aims at providing a long term stable C API for different virtualization mechanisms. It
currently supports QEMU, KVM, XEN, OpenVZ, LXC, and VirtualBox.

This package contains the supporting binaries to use with libvirt
Homepage: http://libvirt.org

 

root@hostname:~#

And the example of the real command execution based on the above command pattern is shown below :

[root@hostname]# qemu-img create -f qcow2 myserver-image.qcow2 250G 
Formatting 'myserver-image.qcow2', fmt=qcow2 size=268435456000 encryption=off cluster_size=65536 lazy_refcounts=off refcount_bits=16
[root@hostname]#

The above command is used to create an image file named myserver-image.qcow2 with the size of 250G and the format is qcow2.

One thought on “How to create qemu image via Command Line

Leave a Reply