Written by michal
on
on
Increase LV size of a qcow2 image
When you get a qcow2 image with a given size – it can’t be simply changed on-the-fly while running a VM or by giving just more space to a VM flavor in OpenStack. Situation gets even more complex when image has LVs inside but fortunately by using guestfish and virt-resize image can be suited to one’s needs. Below are the steps that I used to perform such modifications:
Default image: image-name-250G.qcow2
Resized: image-name-750G.qcow2
- Check which device to resize (this image has LVM created PV on /dev/sda2):
guestfish -a image-name.qcow
run
pvs-full -- SHOWS WHICH DEVICE TO RESIZE
- Resize image (from 250 to 750GB) – resizing is NOT performed in place:
cp image-name-250G.qcow2 image-name-750G.qcow2
qemu-img resize image-name-750G.qcow2 +500GB
- Resize disk and specific device (in this case it is /dev/sda2) and LVM PV:
virt-resize --expand /dev/sda2 image-name-250G.qcow2 image-name-750G.qcow2
- Go to guestfish and use free space on VGS to create additional LV, create additional filesystem and mount point (DISABLE 64bit flag on EXT4, required by this image as it uses outdated e2fsck that doesn’t support 64bit option):
guestfish -a image-name-750G.qcow
run
vgs-full
lvcreate lv_additional_lv VolGroup00 512000 (500GB)
lvs-full
mkfs-opts ext4 /dev/VolGroup00/lv_additional_lv features:^64bit
list-filesystems
mount mkfs-opts ext4 /dev/VolGroup00/lv_root /
mkdir /additional_directory -- directory for new LV
vi /etc/fstab -- add entry
/dev/mapper/VolGroup00-lv_additional_lv /dbdata ext4 defaults,nodev 1 2
umount /
Exit
- Upload image to glance.