KVM Linux - Expanding a Guest LVM File System Using Virt-resize
In this post I will cover growing the file system of a guest instance when running KVM linux.
For this you will require the following Packages:
Shutdown the instance
In order to grow the disk we must virsh shutdown the instance, this can be achieved using a simple
virsh shutdown instance_name, try to avoid running a virsh destroy as we want a clean filesystem to avoid issues in the resize.
Get current image information
After the image has shutdown we can now go ahead and get some information on the disk configuration:
1 2 3 4 5 6
As can be seen here there is a single 10GB virtual disk residing on /dev/sda
We must then create a destination disk image, of the required total size
I have opted to use the –expand flag, if this is not specified a new partition is created to ocupy the free space, refer to
man virt-resize for more advanced options such as splitting the freespace to grow existing partitions (i.e. expand the boot partition +100M)
Go make a coffee as this step will take a while to complete.
If you were to start the instance back up now using outfile.qcow2 as the disk image, you would find the OS reports the original disk size, this is due to the LVM configuration which we can not change “online” (unless of course you are changing a partition that can be unmounted, not the case here).
We will use guestfish to complete the process.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
Your lvm configuration may differ change the above according to the output from list-filesystems.
Note: I run e2fsck-f as a precaution, this is not a required step though I highly recomend doing this.
Now finally swap out the images (or update the libvirt xml file, it’s up to you)
1 2 3
If you instance starts successfully and all your data is intact the original.bak can be safely removed.