How to modify the size of cloud image ?

Recently while working in cloud environment, I encountered a need of expanding an existing cloud image.  I was having rhel 7 qcow2 image with me hence the task was to resize that image to meet some requirements.

Thanks to ample amount of utilities provided by “libguestfs-tools” package which make my task possible.

Step 1 : Checking the size of rhel 7 qcow2 image.

# qemu-img info rhel-guest-image-7.0-20140930.0.x86_64.qcow2
image: rhel-guest-image-7.0-20140930.0.x86_64.qcow2
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 417M
cluster_size: 65536
Format specific information:
compat: 0.10

We can see that virtual disk size is 10GB.

Step 2 : Filesystems inside that image are taking 6GB only.

# virt-filesystems –long -h –all -a rhel-guest-image-7.0-20140930.0.x86_64.qcow2
Name       Type        VFS  Label  MBR  Size  Parent
/dev/sda1  filesystem  xfs  –      –    6.0G  –
/dev/sda1  partition   –    –      83   6.0G  /dev/sda
/dev/sda   device      –    –      –    10G   –

Step 3 : My requirement is to have the filesystem of 15 GB. I created one more image of 15GB.

# qemu-img create -f qcow2 rhel7-guest.qcow2 15G
Formatting ‘rhel7-guest.qcow2’, fmt=qcow2 size=16106127360 encryption=off cluster_size=65536 lazy_refcounts=off

Step 4 : Install the “libguestfs-xfs” package to expand the xfs filesystem.

# yum -y install libguestfs-xfs

Step 5 : Issued the below command to perform the expansion. Make sure that this operation ends with “no error”. Also as suggested at the end of below command try to launch the instance using new image before deleting the old image.

# virt-resize –expand /dev/sda1 rhel-guest-image-7.0-20140930.0.x86_64.qcow2 rhel7-guest.qcow2
Examining rhel-guest-image-7.0-20140930.0.x86_64.qcow2 …
**********

Summary of changes:

/dev/sda1: This partition will be resized from 6.0G to 15.0G.  The
filesystem xfs on /dev/sda1 will be expanded using the ‘xfs_growfs’
method.

**********
Setting up initial partition table on rhel7-guest.qcow2 …
Copying /dev/sda1 …
100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
Expanding /dev/sda1 using the ‘xfs_growfs’ method …

Resize operation completed with no errors.  Before deleting the old disk,
carefully check that the resized disk boots and works correctly.

Step 6 : Let’s check the size information about new image.

# qemu-img info rhel7-guest.qcow2
image: rhel7-guest.qcow2
file format: qcow2
virtual size: 15G (16106127360 bytes)
disk size: 976M
cluster_size: 65536
Format specific information:
compat: 1.1
lazy refcounts: false

Step 7 : I can see the increased size of filesystem in new image to 15 GB from 6GB of previous image.

# virt-filesystems –long -h –all -a rhel7-guest.qcow2
Name       Type        VFS  Label  MBR  Size  Parent
/dev/sda1  filesystem  xfs  –      –    15G   –
/dev/sda1  partition   –    –      83   15G   /dev/sda
/dev/sda   device      –    –      –    15G   –

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s