Growing a qemu disk with xfs - plembo/onemoretech GitHub Wiki
#Growing a qemu disk with XFS
Awhile ago I started using XFS rather than ext4 as the standard filesystem on all my Red Hat boxes at home, including my personal workstation and laptop. LVM is still used to manage the underlying physical media for maximum flexibility.
The problem is that, even after a number of years as Red Hat's standard filesystem, the Internets are still pretty confused about XFS.
##The problem
Typically, not enough space was allocated for the maximum size of a fixed virtual disk. Before LVM and XFS this often required resizing the physical disk using gparted or another tool, adding a new partition in the space created, and then extending the volume over the old and new partitions.
Not any more.
##Resizing the disk image
I use qcow2 format for all the images I run under KVM/libvirt. To expand the physical size of a disk I take it off line and then issue the command:
qemu-img resize myimage.img +30G
This increases disk capacity by an additional 30G.
##Expanding the physical volume
LVM has two kinds of volumes: physical and logical. Just increasing the disk capacity above doesn't make that additional size immediately visible or usable by the system.
To get there the physical volume needs to be extended in size.
Doing that while the disk is online would carry a high risk of data loss, even if the system let you do it. As a result the safest course is to temporarily boot the guest using a bootable utility image. I use the .iso image for Gparted Live because its relatively stable and simple to operate.
With Gparted Live I can expand the physical volume to use all the space available on the disk. In Gparted Live this involves selecting the physical volume to be expanded and dragging the indicator bar all the way to the right where the physical disk ends.
Once I've done that I commit the change and then reboot the guest, this time choosing the hard disk for boot.
To verify the change in physical size, I run the "pvdisplay" LVM command. The PV Size should now reflect the added space.
##Extending the logical volume
Extending the logical volume required the use of the lvextend command. To extend the volume to use all available space on the physical volume you only need the LV Path for the target volume from the lvdisplay command and the PV Name from the pvdisplay command. These two values are then plugged into the lvextend command:
lvextend /dev/centos/root /dev/vda2
In the above example the LV Path is /dev/centos/root, and the PV Name is /dev/vda2.
##Growing the XFS filesystem
Finally, you need to grow the XFS filesystem so that the additional space becomes usable. This is done by running the xfs_growfs command with the partition name:
xfs_growfs /
In this case I'm growing the filesystem for the root partition.
Copyright 2004-2019 Phil Lembo