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
1. Check which device to resize (this image has LVM created PV on /dev/sda2):
1 2 3 |
guestfish -a image-name.qcow run pvs-full -- SHOWS WHICH DEVICE TO RESIZE |
2. Resize image (from 250 to 750GB) – resizing is NOT performed in place:
1 2 |
cp image-name-250G.qcow2 image-name-750G.qcow2 qemu-img resize image-name-750G.qcow2 +500GB |
3. Resize disk and specific device (in this case it is /dev/sda2) and LVM PV:
1 |
virt-resize --expand /dev/sda2 image-name-250G.qcow2 image-name-750G.qcow2 |
4. 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):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
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 |
5. Upload image to glance.