This short guide explains what is Saint-size Command line tool and how we can expand or expand KVM virtual machine disk size using Virt-resize tool in Linux.

The other day I noticed that one of my KVM virtual machines is running out of disk space. I could not install any new application or save files due to low disk space. To fix this problem, I simply increased the disk size of the KVM virtual machine virt-size Permission. I personally tested the steps below to increase the disk size of a CentOS 8 KVM virtual machine and it worked as expected.

Virtue-shifting device

Saint-size A virtual machine is a command line tool for resizing disks. Using property-size, we can increase or decrease the size of the disk of a virtual machine. We can also remove partitions inside virtual disks with a virtue-sized command. Please note that live machines can be resized. The guest system must be shut down before their disk images are resized.

To expand the disk size of a virtual machine, we first create a larger disk image from the source image. And then we copy the source image to the destination image and finally resize it.

Is part of the virtue libguestfs-tools Package. To install the libguestfs-tools package on Debian, Ubuntu and its derivatives, run:

$ sudo apt install libguestfs-tools

To install the LibuGest-Tools package on Fedora, RHEL and its clones, run:

$ sudo dnf install libguestfs-tools

34 in fedora, guestfs-tools The package provides virtue-size equipment. So if you are on Fedora 34, then install guestfs-tools Like the package below:

$ sudo dnf install guestfs-tools

Now let’s see how to use virtual machine disk size virt-resize Permission.

Expand or expand KVM virtual machine disk size in Linux

For the purpose of this guide, I will use the CentOS 8 virtual machine disk image centos8.qcow2. I have stored this granule in my current working directory. you can use virsh dumpxml Command to find the disk image you want to resize.


$ virsh dumpxml centos8

In the above command replace CentOS 8 with your VM name.

After locating the disk whose image you want to resize, inspect the partition details inside this disk image. To print the partition details and their sizes of disk details, run:

$ virt-filesystems --long --parts --blkdevs -h -a centos8.qcow2

Sample Production:

 Name       Type       MBR  Size  Parent
 /dev/sda1  partition  83   1.0G  /dev/sda
 /dev/sda2  partition  8e   19G   /dev/sda
 /dev/sda   device     -    20G   -
Display current partitions and their sizes using the property-filesystem command in Linux

As you can see in the output above, my disk image has only two partitions, ie /dev/sda1 1 GB with size and /dev/sda2 With 19 GB. The total size of a disk image is 20 GB.

Now we will,

  • Increase total disk image size by 20 GB 30 GB,
  • Increase the size of the first partition /dev/sda1 From 1.0GB 1.5 GB,
  • Expand another partition /dev/sda2 To fill the remaining space.

Disk images cannot resize at approx-size. Also, virtue-size should not be used on live-virtual machines. Before resizing the disk image, shut down the virtual machine and back up the original disk image.

$ mv centos8.qcow2 centos8.qcow2.backup

The above command will rename the current disk image centos8.qcow2 To centos8.qcow2.backup.

Create a new disk image with the same name and with a size of 30GB using the command:

$ qemu-img create -f qcow2 -o preallocation=metadata centos8.qcow2 30G

Sample Production:

Formatting 'centos8.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off preallocation=metadata compression_type=zlib size=32212254720 lazy_refcounts=off refcount_bits=16

Make sure the newly created disk size is 30GB:

$ virt-filesystems --long --parts --blkdevs -h -a centos8.qcow2

Sample Production:

Name      Type    MBR  Size  Parent
 /dev/sda  device  -    30G   -
Create a new virtual disk image using the qemu-img command

Now expand / expand the KVM virtual machine disk image size using the command:

$ virt-resize --resize /dev/sda1=+500M --expand /dev/sda2 centos8.qcow2.backup centos8.qcow2


  • --resize /dev/sda1=+500M – Increases the size of /dev/sda1 Partition into 500 MB.
  • –Expand / dev / sda2 – resizes /dev/sda2 Partition to fill all remaining space. In my case, it would be sized from 19.0G to 28.5G.
  • centos8.qcow2.backup – This is the original input disk image.
  • centos8.qcow2 – This is a newly created output disk image.

The sample output of the above command is:

[   0.0] Examining centos8.qcow2.backup
 Summary of changes:
 /dev/sda1: This partition will be resized from 1.0G to 1.5G.  The 
 filesystem ext4 on /dev/sda1 will be expanded using the ‘resize2fs’ 
 /dev/sda2: This partition will be resized from 19.0G to 28.5G.  The LVM PV 
 on /dev/sda2 will be expanded using the ‘pvresize’ method.
 [   4.2] Setting up initial partition table on centos8.qcow2
 [   5.6] Copying /dev/sda1
  100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
 [   9.7] Copying /dev/sda2
  100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
 [  45.1] Expanding /dev/sda1 using the ‘resize2fs’ method
 [  45.3] 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.
Expand or expand KVM virtual machine disk size

Check partitions and their sizes virt-filesystems Order:

$ virt-filesystems --long -h --all -a centos8.qcow2

Sample Production:

 Name          Type        VFS   Label  MBR  Size  Parent
 /dev/sda1     filesystem  ext4  -      -    1.4G  -
 /dev/cl/root  filesystem  xfs   -      -    17G   -
 /dev/cl/swap  filesystem  swap  -      -    2.0G  -
 /dev/cl/root  lv          -     -      -    17G   /dev/cl
 /dev/cl/swap  lv          -     -      -    2.0G  /dev/cl
 /dev/cl       vg          -     -      -    29G   /dev/sda2
 /dev/sda2     pv          -     -      -    29G   -
 /dev/sda1     partition   -     -      83   1.5G  /dev/sda
 /dev/sda2     partition   -     -      8e   29G   /dev/sda
 /dev/sda      device      -     -      -    30G   -
Print partitions and their sizes in KVM virtual machine disks using the virtue-filesystem command

As you see in the output above, my CentOS8 KVM disk image size has gone from 20 GB to 30 GB.

Now boot the virtual machine with a new disk image. You can also create a new virtual machine using the Qcow2 image as described in the following link.

If it works without any problem, thoroughly inspect all your data when it is present. If all is well, remove the old backup disk.

If there is a problem with the new disk, shut down the virtual machine and rename the backup disk to its original name. Repeat the above steps again carefully. Do not forget to back up the data and disk image.