In this example, I will take you through the steps to resize qcow2 image with virt-resize using 6 Easy Steps. If you are running multiple virtual machines using qcow2 image and let's suppose one day you might feel you need some extra storage in your virtual machine then you need to go for resizing. This situation is very frequently encountered and hence it is important to understand the steps required to resize qcow2 image. Here we are basically going to use two kvm tools, virt-resize and qemu-img to resize qcow2 image.
Resize qcow2 Image with virt-resize
Also Read: How to Install KVM Server tools(virsh) on Linux(RHEL/CentOS 7/8) in 6 Easy Steps
Step 1: Prerequisites
a)You need to have KVM tools(
qemu-img) installed in your System.
b)You should have sudo access to run privilege commands. To know more about providing
sudo access you can check Step by Step: How to Add User to Sudoers.
Step 2: Shutdown Your VM
First you need to shutdown your VM using
virsh destroy test1 command as shown below. You cannot resize qcow2 image while VM is active and running.
[root@localhost ~]# virsh destroy test1
Step 3: Take the Backup of qcow2 image
Before resizing the qcow2 image you need to take a backup of this image. virt-resize cannot resizes disk in-place so we need to use the backup qcow2 image(
test1.qcow2.old) as input image and original qcow2 image (
test1.qcow2) as output image. Here we will go to directory
/u01/data and take the backup of existing
test1.qcow2 image to
[root@localhost ~]# cd /u01/data/ [root@localhost ~]# mv test1.qcow2 test1.qcow2.old
Step 4: Create a Raw Image using qemu-img command
Now we need to create a raw qcow2 image with the same size as we need in our virtual machine filesystem. Since we are increasing the size of our VM from
1 GB to
2 GB so we will specify the size as
[root@localhost ~]# qemu-img create -f raw /u01/data/test1.qcow2 2G Formatting '/u01/data/test1.qcow2', fmt=raw size=21990232
-f : First image format. More info on qemu-img Man Page.
Step 5: Resize Original qcow2 using virt-resize command
Now you can perform the resize operation using virt-resize command as shown below. Here we are expanding
/dev/sda3 partition from old qcow2 image to fill new spaces using
virt-resize --expand /dev/sda3 test1.qcow2.old test1.qcow2 command.
[root@localhost ~]# virt-resize --expand /dev/sda3 test1.qcow2.old test1.qcow2 [ 0.0] Examining test1.qcow2.old ◓ 25% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒═══════════════════════════════════════════════════════════════════════════════════════════════════════════⟧ --:-- 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ --:-- ********** Summary of changes: /dev/sda1: This partition will be left alone. /dev/sda2: This partition will be left alone. /dev/sda3: This partition will be resized from 1011.2M to 2022.4M. The filesystem xfs on /dev/sda3 will be expanded using the 'xfs_growfs' method. ********** [ 33.3] Setting up initial partition table on test1.qcow2 [ 43.1] Copying /dev/sda1 [ 43.1] Copying /dev/sda2 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00 [ 50.2] Copying /dev/sda3 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00 [4590.4] Expanding /dev/sda3 using the 'xfs_growfs' method Resize operation completed with no errors. Before deleting the old disk, carefully check that the resized disk boots and works correctly.
--expand: Expand the named partition so it uses up all extra space (space left over after any other resize changes that you request have been done). More info on virt-resize Man Page.
Step 6: Start Virtual Machine using virsh command
After successfully resizing of disk partition you can start the virtual machine using
virsh start test1 command and check the disk space by logging into the VM. You will find that the disk space is now increased to 2 GB.
[root@localhost ~]#virsh start test1 Domain test1 started
15 virt-install examples | KVM Virtualization commands cheatsheet
18 Useful virsh commands examples for KVM Hypervisor Management (virt-df,virt-log)
How to Enable or Disable SELinux Temporarily or Permanently on RedHat/CentOS 7/8
10 Popular Examples of sudo command in Linux(RedHat/CentOS 7/8)
How to Install and Use telnet command in Linux (RedHat/Linux 7/8) using 5 Easy Steps
12 Most Popular rm command in Linux with Examples
Create a Self Signed Certificate using OpenSSL
How to Check timezone in Linux (timedatectl and date commands) Using 4 Easy Methods
How to Resize qcow2 image and filesystem using virt-resize
1 thought on “How to Resize qcow2 Image Using virt-resize and qemu-img(KVM tools) in 6 Easy Steps”
How to resize qcow2 Image using qemu-img(KVM tools) in 2 easy steps:
1. qemu-img resize /path/to/image.qcow2 [+|-]size eg
qemu-img resize /home/user/.local/share/libvirt/images/Windows10-UEFI.qcow2 +24G
2. boot your guest and resize the partition.