Monday, November 3, 2014

How to re-size qcow2 image using guest-fish?


#######################################################################################################################################################################################################################
resize Image using virt-resize i.e. guestfish
#######################################################################################################################################################################################################################
1.copy the original image twice not to harm the original
# cp tinyCentos.qcow2 tinyCentosTmp.qcow2
# cp tinyCentos.qcow2 tinyCentos30.qcow2

2.view all file systems:
[root@s4-5 templates]# virt-filesystems --long -h --all -a tinyCentos30.qcow2
Name                  Type       VFS  Label MBR Size Parent
/dev/sda1             filesystem ext4 -     -   500M -
/dev/VolGroup/lv_root filesystem ext4 -     -   3.5G -
/dev/VolGroup/lv_swap filesystem swap -     -   1.0G -
/dev/VolGroup/lv_root lv         -    -     -   3.5G /dev/VolGroup
/dev/VolGroup/lv_swap lv         -    -     -   1.0G /dev/VolGroup
/dev/VolGroup         vg         -    -     -   4.5G /dev/sda2
/dev/sda2             pv         -    -     -   4.5G -
/dev/sda1             partition  -    -     83  500M /dev/sda
/dev/sda2             partition  -    -     8e  4.5G /dev/sda
/dev/sda              device     -    -     -   5.0G -


3.enlarge the image by 30Gb:
[root@s4-5 templates]# qemu-img resize tinyCentos30.qcow2 +30G
Image resized.


4.View the filesystems after enlargement:
[root@s4-5 templates]# virt-filesystems --long -h --all -a tinyCentos30.qcow2
Name                  Type       VFS  Label MBR Size Parent
/dev/sda1             filesystem ext4 -     -   500M -
/dev/VolGroup/lv_root filesystem ext4 -     -   3.5G -
/dev/VolGroup/lv_swap filesystem swap -     -   1.0G -
/dev/VolGroup/lv_root lv         -    -     -   3.5G /dev/VolGroup
/dev/VolGroup/lv_swap lv         -    -     -   1.0G /dev/VolGroup
/dev/VolGroup         vg         -    -     -   4.5G /dev/sda2
/dev/sda2             pv         -    -     -   4.5G -
/dev/sda1             partition  -    -     83  500M /dev/sda
/dev/sda2             partition  -    -     8e  4.5G /dev/sda
/dev/sda              device     -    -     -   35G  -


5.resize the lvm partitions:
[root@s4-5 templates]# virt-resize --expand /dev/sda2 --LV-expand /dev/VolGroup/lv_root  tinyCentosTmp.qcow2 tinyCentos30.qcow2
Examining tinyCentosTmp.qcow2 ...
**********

Summary of changes:

/dev/sda1: This partition will be left alone.

/dev/sda2: This partition will be resized from 4.5G to 34.5G.  The LVM
    PV on /dev/sda2 will be expanded using the 'pvresize' method.

/dev/VolGroup/lv_root: This logical volume will be expanded to maximum
    size.  The filesystem ext4 on /dev/VolGroup/lv_root will be
    expanded using the 'resize2fs' method.

**********
Setting up initial partition table on tinyCentos30.qcow2 ...
Copying /dev/sda1 ...
 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
Copying /dev/sda2 ...
 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
Expanding /dev/sda2 using the 'pvresize' method ...
Expanding /dev/VolGroup/lv_root using the 'resize2fs' method ...

Resize operation completed with no errors.  Before deleting the old
disk, carefully check that the resized disk boots and works correctly.
[root@s4-5 templates]#


6.Optional if you want to compress it run:
[root@s4-5 ready_for]# qemu-img convert -c -f qcow2 -O qcow2 tinyCentos30.qcow2 tinyCentos30diet.qcow2
[root@s4-5 ready_for]# ll
-rw-r--r-- 1 root root  307429376 Sep  3 02:08 tinyCentos30diet.qcow2
-rw-r--r-- 1 root root 5854593024 Sep  3 01:15 tinyCentos30.qcow2
-rw-r--r-- 1 root root  943587328 Jun 22 06:02 tinyCentos.qcow2
-rw-r--r-- 1 root root  943587328 Sep  3 01:08 tinyCentosTmp.qcow2
[root@s4-5 ready_for]#

No comments:

Post a Comment