Pages

Tuesday, August 13, 2013

resize kvm disk image

How to resize kvm disk image?

Currently I am working on CentOS 6.0 64 Bit.

I am working on kvm Hypervisor , with x86_64 Architecture and /usr/libexec/qemu-kvm as Emulator.

I got this information from virt-manager tool.

Please refer the screen shot shown below.


My requirement is to resize the Images created under KVM hypervisor like this,

http://blogforopensource.blogspot.com/2013/05/resizing-machine-image-fastly-in.html

Again googling gave me this link,

https://wiki.archlinux.org/index.php/QEMU#Resizing_the_image

1. Check the File type.

file dataNodeUbuntu.img

dataNodeUbuntu.img: x86 boot sector; GRand Unified Bootloader, stage1 version 0x3, stage2 address 0x2000, stage2 segment 0x200; partition 1: ID=0x83, active, starthead 1, startsector 63, 11936232 sectors; partition 2: ID=0x5, starthead 0, startsector 11936295, 642600 sectors; partition 3: ID=0x83, starthead 0, startsector 12578895, 8385930 sectors, code offset 0x48

2. Check the size of the Image.

 ls -alhrt

-rw-------.  1 qemu qemu  6G Aug 13 12:28 dataNodeUbuntu.img

3. Resize the Image

Previously the size of the image was 6 GB.Now I want to increase to 10GB.

Now,

New Required Size - Existing Size will give the difference.

In our case, 10 GB - 6 GB = 4 GB.

So we have to increase the size by 4 GB.

Now run the command.


qemu-img resize dataNodeUbuntu.img  +4G


4.When I checked the size, surprisingly the size got increased to 10 GB (Great !)

But How to make the size to be discovered inside the Virtual Machine ?

Reboot the Virtual Machine and install gparted.

(Since my guest VM is ubuntu).

Newly added disk will be discovered by gparted.
Now create partition with gparted.
Then mount the drive.

You will be able to see the 4 GB disk as another drive.

df -H

Refer the screenshot.








2 comments: