As stated in the title of the article, this is an article which is written to discuss on how to resize qcow image via command line. Resizing the qcow image file is done because there is a need to avoid the hassle of installing a new and fresh install operating system to a new created qcow image file.
Supposed, there is a need for a virtual server powered by a certain Linux operating system as soon as possible. It can be done by creating an empty qcow image file. To be able to do that, just read the article titled ‘How to create qemu image via Command Line’ in this link .
So, after the empty qcow image file is already created, just try to duplicate the virtual image which has already been prepared as the main template or the source to that empty qcow image. The virtual image which is chosen as the main template has already been installed and prepared previously so it contains a fully run operating system.
Consider the image of the template’s size is only around 20.0G because it is only a template. But the target of image file has the size of 250.0G, in order to be perfectly fit for duplication, it has to be resized. And the resized part which in the context of this article is in the specific partition which is defined along with the command executed. Below is the command pattern :
virt-resize source-image-file target-image-file --expand=/partition-name
The example of the above command execution can be shown below :
[root@hostname local_vms]# virt-resize myserver-template.qcow2 myserver-app.qcow2 --expand=/dev/sda2 [ 0.0] Examining myserver-template.qcow2 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00 ********** Summary of changes: /dev/sda1: This partition will be left alone. /dev/sda2: This partition will be resized from 19.0G to 249.0G. The LVM PV on /dev/sda2 will be expanded using the 'pvresize' method. ********** [ 14.0] Setting up initial partition table on myserver-app.qcow2 [ 14.2] Copying /dev/sda1 [ 15.9] Copying /dev/sda2 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00 [ 55.5] Expanding /dev/sda2 using the 'pvresize' method Resize operation completed with no errors. Before deleting the old disk, carefully check that the resized disk boots and works correctly. [root@hostname local_vms]#
In the above example, the source image file is myserver-template.qcow2 dan the destination image file is myserver-app.qcow2. For the purpose of resizing the process of certain partition, the parameter passed is ‘–expand’ which has the value of ‘/dev/sda2/’ as the name of the partition selected for further resize.
As shown in the above output generated, the resize process is done in ‘/dev/sda2’ from the ‘/dev/sda2’ partition in myserver-template.qcow2 which has the size of 19.0G into the ‘/dev/sda2’ partition in myserver-app.qcow2 with the size of 249.0G.