Converting and Resizing KVM Hard Drives

Hello everyone! I have been rebuilding my network and servers due to a major outage that I had with my ISP, which we are still meddling with. However, during the outage, I had to rebuild my servers. So I lost a lot of my build machines. Luckily, I still had copies running on my Mac running VMware Fusion. However, I don’t run on there so my machines just sit powered down, but if I need to bring them up for anything, I can.

Well, I have a build machine that was running out there before I brought it into my KVM environment, but it was out of hard drive space and under utilized. This blog post is going to show how I moved the hard drive to my kvm server and then how I resized it and got it up and running.

First thing I did was scp the vmdk file from my Mac to my KVM server:

scp ~/Documents/Virtual\ Machines.localized/Precise-build.vmwarevm/Virtual\ Disk.vmdk kvm2:/data/VMS/precise-build.vmdk

After 40 minutes, the vmdk was copied. I then converted it to qcow2:

qemu-img convert -O qcow2 precise-build.vmdk precise-build.qcow2

After that finished, I was able to get info on it:

qemu-img info precise-build.qcow2
image: precise-build.qcow2
file format: qcow2
virtual size: 80G (85899345920 bytes)
disk size: 73G
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: false
    refcount bits: 16
    corrupt: false

I wanted to grow it to 200GB in size:

qemu-img resize precise-build.qcow2 +120G

I then got info on it to verify that it grew:

qemu-image info precise-build.qcow2
image: precise-build.qcow2
file format: qcow2
virtual size: 200G (214748364800 bytes)
disk size: 75G
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: false
    refcount bits: 16
    corrupt: false

I was now ready to build the VM, which I used Virtual-Manager to build. I told it to use an existing disk, and then set it up to use more memory and processors then previously so I could get better performance out of it. I then told it to boot from a CD image of Parted-Magic so I could grow the file system. Luckily, this server only had two partitions, the root partition at the swap partition. However, the swap was on an extended partition and at the end of the disk. So I had to delete it and the extended partition so I could used parted to extend the file system. I extended it to the end minus 6GB, and then created at extended partition at the end and added a swap partition back and then saved it and rebooted. The machine rebooted, ran fsck and started up normally.

I was then able to delete the vmdk file from my server to reclaim the 73GB of space it was using:

rm /data/VMS/precise-build.vmdk

Thats it. I hope this guide helps you migrating VM’s and growing their file systems from VMware or even Virtual Box to KVM.

Let me know in the comments.

Thanks!


Comments

3 responses to “Converting and Resizing KVM Hard Drives”

  1. Awesome, this is what I was searching for in yahoo

  2. Good Morning, google lead me here, keep up great work.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.