lost and found ( for me ? )

KVM : Expand an existing partition(xfs) size

KVM-rhel-grow-fs-qcow2.md

KVM : Expand an existing partition(xfs) size

Here is how to expand an existing partition size of qcow2 images.
1. List partitions of a qcow2 image you would like to expand
[hattori@centos ~]$ sudo yum install -y libguestfs-xfs.x86_64

[root@centos ~]# cd /var/lib/libvirt/images/

[root@centos images]# virsh dumpxml lab05-u | grep qcow2
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/lab05-u.qcow2'/>
[root@centos images]#

[root@centos images]# virt-filesystems --long -h --all -a ./lab05-u.qcow2
Name       Type        VFS   Label  MBR  Size  Parent
/dev/sda1  filesystem  xfs   -      -    1.0G  -
/dev/sda2  filesystem  swap  -      -    4.0G  -
/dev/sda3  filesystem  xfs   -      -    35G   -
/dev/sda1  partition   -     -      83   1.0G  /dev/sda
/dev/sda2  partition   -     -      82   4.0G  /dev/sda
/dev/sda3  partition   -     -      83   35G   /dev/sda
/dev/sda   device      -     -      -    40G   -
[root@centos images]#
2. Extend the size of a file
[root@centos images]# truncate -r ./lab05-u.qcow2 new-lab05-u.qcow2
[root@centos images]# truncate -s +40G new-lab05-u.qcow2
[root@centos images]#
3. Expand a partition (/dev/sda3)
[root@centos images]# virt-resize --expand /dev/sda3 ./lab05-u.qcow2 ./new-lab05-u.qcow2
[   0.0] Examining ./lab05-u.qcow2
**********

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 35.0G to 75.0G.  The
filesystem xfs on /dev/sda3 will be expanded using the ‘xfs_growfs’
method.

**********
[   3.5] Setting up initial partition table on ./new-lab05-u.qcow2
[   3.9] Copying /dev/sda1
 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
[   8.3] Copying /dev/sda2
 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
[  15.6] Copying /dev/sda3
 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
[  99.0] 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.
[root@centos images]#


[root@centos images]# qemu-img info new-lab05-u.qcow2
image: new-lab05-u.qcow2
file format: raw
virtual size: 80G (85906161664 bytes)
disk size: 3.6G
[root@centos images]#
4. Boot a VM with a new qcow2 image
Convert the image format to qcow2 and then launch the VM.
[root@centos images]# qemu-img convert -f raw -O qcow2 ./new-lab05-u.qcow2 ./new-lab05-u.qcow2-new


[root@centos images]# qemu-img convert -f raw -O qcow2 ./new-lab05-u.qcow2 ./new-lab05-u.qcow2-new

[root@centos images]# qemu-img info ./new-lab05-u.qcow2-new
image: ./new-lab05-u.qcow2-new
file format: qcow2
virtual size: 80G (85906161664 bytes)
disk size: 3.8G
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: false
[root@centos images]#
[root@centos images]# mv new-lab05-u.qcow2-new new-lab05-u.qcow2
mv: overwrite ‘new-lab05-u.qcow2’? y
[root@centos images]#


[root@centos images]# virsh start lab05-u
Domain lab05-u started


[user01@lab05-u ~]$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda3        75G  3.4G   72G   5% /
devtmpfs        5.8G     0  5.8G   0% /dev
tmpfs           5.8G  4.0K  5.8G   1% /dev/shm
tmpfs           5.8G  776K  5.8G   1% /run
tmpfs           5.8G     0  5.8G   0% /sys/fs/cgroup
/dev/vda1      1014M  175M  840M  18% /boot
tmpfs           1.2G     0  1.2G   0% /run/user/1000
[user01@lab05-u ~]$
Reference
virt-resize