shadowman.jpg

Resizing RHEV virtual disks

Recently I encountered the need to resize a VM virtual disk within RedHat Enterprise Virtualization (RHEV). According to RedHat this functionality is on the roadmap, but does not exist with RHEV 3.2. Others are claiming success via more complex procedures utilizing the qemu-img commands, but my approach to the problem was obvious and very simplistic at best.

WARNING: With any modification to any partition or filesystem, there is the realistic possibility for data loss. Perform the following procedure at your own risk. I assume no responsibility if you recklessly and/or unknowingly destroy your data. Your block device assignments, volume groups and logical volumes will most likely be different than those I’ve demonstrated below. Administrator discretion is advised.

Since Linux supports logical volumes and Windows supports dynamic disks, I’ve decided to go the route of changing the size of the backing disk image. This requires the VM to boot from boot media which allows for a “dd” operation. I already have Clonezilla in my ISO storage domain which proved successful for my needs.

1) Shutdown the VM

2) Create a virtual disk of greater size than the disk you wish to expand. Assign the new disk to the VM and activate it.

3) Start the VM with the Run Once option and select your chosen boot media.

4) Open a terminal session on the VM and verify the source and target volumes. I used fdisk to confirm the content of the partition table and pvs when multiple VM disks are of similar size.

5) Use DD to copy the disk contents from the source to the target. eg. dd if=/dev/vda of=/dev/vdb bs=512k Use block size (bs) at your discretion. Some have found a larger bs value provided better throughput while others report I/O bottlenecks. Your mileage may vary.

6) Once the dd completes, edit the source virtual disk within the RHEV-M console and unset the bootable flag (if necessary), and set the bootable flag on the target virtual disk (if necessary). Deactivate the old disk.

7) Boot the VM from it’s virtual disk and verify the disk content.

8) Windows: extend the existing partition to the new space from within the Disk Management tool.

9) Linux: Since I’m not a fan of resizing underlying disk partitions, I chose the LVM route and created an additional partition on the newly expanded space and labeled it as LVM (8E) from within fdisk. The kernel must see the new partition to continue. In some cases performing a partprobe will perform this, in some cases a reboot was required.

10) Linux: Create a physical volume (pv) from the new partition. eg. pvcreate /dev/vda2

11) Linux: Extend the volume group (vg) with the new physical volume. eg. vgextend VolGroup /dev/vda2

12) Linux: Extend the logical volume (lv) to use the newly expanded space. I personally prefer using extents since it’s more consise. Grab the extent count from the vgdisplay command. Extended the LV. eg. lvresize -l +xxxxx /dev/VolGroup/XXXXX Replace the xxxxx with the extent value and replace XXXXX with logical volume name.

13) Linux: Extend the filesystem eg. resize2fs /dev/VolGroup/XXXXX Replace XXXXX with logical volume name. These resizes can be done on a live filesystem.

14) Once you have confirmed the validity of your data, you may now remove the original deactivated virtual disk from RHEV.