Resize a RHEL7 QEMU/KVM image

By | April 14, 2016

At some point my RHEL7 development virtual machine run out of space.
Resizing the image is really made easy by RedHat:

STEP 1: Resize the virtual machine disk

STEP 2: Start the VM and check the disks from inside the VM

Check the virtual disk:

We can see here that the virtual disk size was updated to 53.7 GB. This is good it means that the qemu-img was successful.

Check the physical volume:

We see here that we will need to extend this pv /dev/sda2.

Check the volume group

Check the logical volumes

We see here that we want to extend the root logical volume /dev/rhel/root.

STEP 3: Allocate the extra space

First we have to resize the primary partition /dev/sda2. This can be done with parted resize.
The issue here is RHEL7 does not support parted resize see

There two alternatives. One is to delete and remake /dev/sda2, that is not an option here. The other is to simply create a new partition, create anew physical volume, add it to the volume group and extend the logical volume over it.

Create primary partition /dev/sda3, allocate all the space and make it of type LVM

STEP 5: Create a new physical disk on the newly created primary partition

First refresh the partition table. Otherwise pvcreate will complain that /dev/sda3 does not exist.

So call partprobe then try again.

Create the new physical volume

STEP 6: Extend the volume group rhel over the new physical volume.

We see here we have now 30g free in this rhel volume group.

STEP 7: Resize the root logical volume to fill all the available space

STEP 8: Extend the file system to fill the entire logical volume.

Note that by default RHEL7 uses xfs so we have to use xfs_growfs. For other partition types you can use resizefs